Skip to content

Commit

Permalink
Merge pull request #17 from florianv/swap3
Browse files Browse the repository at this point in the history
Swap 3.0
  • Loading branch information
florianv committed Oct 8, 2016
2 parents 5276499 + 0e3d1ea commit fa2b288
Show file tree
Hide file tree
Showing 16 changed files with 743 additions and 254 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
@@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
11 changes: 11 additions & 0 deletions .gitattributes
@@ -0,0 +1,11 @@
* text=auto

/doc export-ignore
/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
.styleci.yml export-ignore
.travis.yml export-ignore
phpunit.xml export-ignore
18 changes: 18 additions & 0 deletions .scrutinizer.yml
@@ -0,0 +1,18 @@
filter:
excluded_paths: [tests/*]

checks:
php:
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true
6 changes: 6 additions & 0 deletions .styleci.yml
@@ -0,0 +1,6 @@
preset: symfony

finder:
path:
- "src"
- "tests"
14 changes: 9 additions & 5 deletions .travis.yml
Expand Up @@ -2,15 +2,19 @@ language: php

php:
- 5.5
- 5.5.9
- 5.6
- 7.0
- nightly
- hhvm

sudo: false

cache:
directories:
- $HOME/.composer/cache

before_script:
- composer selfupdate
- composer --prefer-source --dev install
- travis_retry composer self-update
- travis_retry composer update --no-interaction --prefer-dist

script:
- bin/phpunit
- composer test
89 changes: 50 additions & 39 deletions README.md
@@ -1,74 +1,85 @@
# Laravel Swap
<img src="https://github.com/florianv/swap/blob/master/doc/logo.png" width="200px" align="left"/>
> Currency exchange rates library for Laravel
[![Build status][travis-image]][travis-url]
[![Version][version-image]][version-url]
[![Downloads][downloads-image]][downloads-url]
[![Build status](http://img.shields.io/travis/florianv/laravel-swap.svg?style=flat-square)](https://travis-ci.org/florianv/laravel-swap)
[![Total Downloads](https://img.shields.io/packagist/dt/florianv/laravel-swap.svg?style=flat-square)](https://packagist.org/packages/florianv/laravel-swap)
[![Scrutinizer](https://img.shields.io/scrutinizer/g/florianv/laravel-swap.svg?style=flat-square)](https://scrutinizer-ci.com/g/florianv/laravel-swap)
[![Version](http://img.shields.io/packagist/v/florianv/laravel-swap.svg?style=flat-square)](https://packagist.org/packages/florianv/laravel-swap)

> Integrates [Swap](https://github.com/florianv/swap) with Laravel
**Swap** allows you to retrieve currency exchange rates from various services such as [Fixer](http://fixer.io) or [Yahoo](https://finance.yahoo.com/) and optionally cache the results.

## Installation
<br /><br />

Install the package via [Composer](https://getcomposer.org):
## QuickStart

1) Install via Composer:

```bash
$ composer require florianv/laravel-swap
$ composer require florianv/laravel-swap php-http/message php-http/guzzle6-adapter
```

## Configuration

Register the service provider and the facade in your configuration:
2) Configure the Service Provider and alias:

```php
// config/app.php
'providers' => [
Florianv\LaravelSwap\SwapServiceProvider::class
Swap\Laravel\SwapServiceProvider::class
],

'aliases' => [
'Swap' => Florianv\LaravelSwap\Facades\Swap::class
'Swap' => Swap\Laravel\Facades\Swap::class
]
```

Publish Swap's configuration:
3) Publish the Package configuration

```bash
$ php artisan vendor:publish
$ php artisan vendor:publish --provider="Swap\Laravel\SwapServiceProvider"
```

By default, `Swap` is configured to use the `FileGetContentsHttpAdapter`, the `YahooFinanceProvider` provider and don't use a cache.
4) Start using it!

For more informations about all possibilities including Laravel Cache integration, read the comments in the
[configuration file](https://github.com/florianv/laravel-swap/blob/master/config/swap.php).
```php
// Get the latest EUR/USD rate
$rate = Swap::latest('EUR/USD');

## Usage
// 1.129
$rate->getValue();

### Via the Facade
// 2016-08-26
$rate->getDate()->format('Y-m-d');

```php
Route::get('/', function () {
$rate = Swap::quote('EUR/USD');
});
// Get the EUR/USD rate yesterday
$rate = Swap::historical('EUR/USD', Carbon::yesterday());
```

### Via Injection
## Documentation

```php
use Swap\SwapInterface;
The complete documentation can be found [here](https://github.com/florianv/laravel-swap/blob/master/doc/readme.md).

Route::get('/', function (SwapInterface $swap) {
$rate = $swap->quote('EUR/USD');
});
```
## Services

## License
Here is the list of the currently implemented services.

[MIT](https://github.com/florianv/laravel-swap/blob/master/LICENSE)
| Service | Base Currency | Quote Currency | Historical |
|---------------------------------------------------------------------------|----------------------|----------------|----------------|
| [Fixer](http://fixer.io) | * | * | Yes |
| [European Central Bank](http://www.ecb.europa.eu/home/html/index.en.html) | EUR | * | Yes |
| [Google](http://www.google.com/finance) | * | * | No |
| [Open Exchange Rates](https://openexchangerates.org) | USD (free), * (paid) | * | Yes |
| [Xignite](https://www.xignite.com) | * | * | Yes |
| [Yahoo](https://finance.yahoo.com) | * | * | No |
| [WebserviceX](http://www.webservicex.net/ws/default.aspx) | * | * | No |
| [National Bank of Romania](http://www.bnr.ro) | RON | * | No |
| [Central Bank of the Republic of Turkey](http://www.tcmb.gov.tr) | * | TRY | No |
| [Central Bank of the Czech Republic](http://www.cnb.cz) | * | CZK | No |
| [currencylayer](https://currencylayer.com) | USD (free), * (paid) | * | Yes |

[travis-url]: https://travis-ci.org/florianv/laravel-swap
[travis-image]: http://img.shields.io/travis/florianv/laravel-swap.svg
## Credits

[version-url]: https://packagist.org/packages/florianv/laravel-swap
[version-image]: http://img.shields.io/packagist/v/florianv/laravel-swap.svg
- [Florian Voutzinos](https://github.com/florianv)
- [All Contributors](https://github.com/florianv/laravel-swap/contributors)

## License

[downloads-url]: https://packagist.org/packages/florianv/laravel-swap
[downloads-image]: https://img.shields.io/packagist/dt/florianv/laravel-swap.svg
The MIT License (MIT). Please see [LICENSE](https://github.com/florianv/laravel-swap/blob/master/LICENSE) for more information.
24 changes: 13 additions & 11 deletions composer.json
@@ -1,7 +1,7 @@
{
"name": "florianv/laravel-swap",
"type": "library",
"description": "Integrates Swap with Laravel 5",
"description": "Currency exchange rates library for Laravel",
"keywords": [
"laravel",
"currency",
Expand All @@ -21,26 +21,28 @@
],
"autoload": {
"psr-4": {
"Florianv\\LaravelSwap\\": "src/"
"Swap\\Laravel\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Florianv\\LaravelSwap\\Tests\\": "tests/"
"Swap\\Laravel\\Tests\\": "tests/"
}
},
"require": {
"php": ">=5.5.9",
"illuminate/contracts": "~5.0",
"illuminate/support": "~5.0",
"illuminate/view": "~5.0",
"florianv/swap": "~2.5"
"php": "^5.5|^7.0",
"florianv/swap": "^3.0",
"psr/cache": "^1.0",
"cache/adapter-common": "^0.3"
},
"require-dev": {
"graham-campbell/testbench": "~2.1"
"graham-campbell/testbench": "~2.1",
"php-http/guzzle6-adapter": "^1.0",
"php-http/message": "^1.0",
"cache/integration-tests": "^0.11"
},
"config": {
"bin-dir": "bin"
"scripts": {
"test": "phpunit"
},
"extra": {
"branch-alias": {
Expand Down
65 changes: 45 additions & 20 deletions config/swap.php
Expand Up @@ -13,28 +13,32 @@

/*
|--------------------------------------------------------------------------
| Http Adapter
| Options.
|--------------------------------------------------------------------------
|
| This option specifies a service id to use as http adapter
| (defaults to FileGetContentsHttpAdapter).
| The options to pass to Swap amongst:
|
| * cache_ttl: The cache ttl in seconds.
*/
'http_adapter' => null,
'options' => [],

/*
|--------------------------------------------------------------------------
| Providers
| Services
|--------------------------------------------------------------------------
|
| This option specifies the providers to use with their name as key and
| their config as value. The providers will be wrapped in a ChainProvider
| in the order they appear in this array.
| This option specifies the services to use with their name as key and
| their config as value.
|
| Here is the config spec for each provider:
| Here is the config spec for each service:
|
| * "yahoo_finance", "google_finance", "european_central_bank", "webservicex"
| "national_bank_of_romania" can be enabled with "true" as value.
| * "central_bank_of_czech_republic", "central_bank_of_republic_turkey", "european_central_bank", "fixer"
| "google", "national_bank_of_romania", "webservicex", "yahoo" can be enabled with "true" as value.
|
| * 'currency_layer' => [
| 'access_key' => 'secret', // Your app id
| 'enterprise' => true, // True if your AppId is an enterprise one
| ]
|
| * 'open_exchange_rates' => [
| 'app_id' => 'secret', // Your app id
Expand All @@ -47,24 +51,45 @@
|
*/

'providers' => [
'yahoo_finance' => true,
'services' => [
'fixer' => true,
],

/*
|--------------------------------------------------------------------------
| Cache
|--------------------------------------------------------------------------
|
| This option specifies which cache to use to store rate values and its ttl.
| Currently only Illuminate cache is supported:
| This option specifies the Laravel cache store to use.
|
| 'cache' => [
| 'type' => 'illuminate',
| 'store' => 'apc', // Name of the cache store
| 'ttl' => 60 // Ttl in minutes (defaults to 0)
| ],
| 'cache' => 'file'
*/
'cache' => null,

/*
|--------------------------------------------------------------------------
| Http Client.
|--------------------------------------------------------------------------
|
| The HTTP client service name to use.
*/
'http_client' => null,

/*
|--------------------------------------------------------------------------
| Request Factory.
|--------------------------------------------------------------------------
|
| The Request Factory service name to use.
*/
'request_factory' => null,

/*
|--------------------------------------------------------------------------
| Cache Item Pool.
|--------------------------------------------------------------------------
|
| The Cache Item Pool service name to use.
*/
'cache_item_pool' => null,
];

0 comments on commit fa2b288

Please sign in to comment.