Skip to content

Commit

Permalink
Merge pull request #43 from florianv/swap
Browse files Browse the repository at this point in the history
Use latest Swap
  • Loading branch information
florianv committed Feb 19, 2018
2 parents d8acb56 + c916898 commit 68194ac
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -99,6 +99,8 @@ Here is the list of the currently implemented services.
| [Russian Central Bank](http://http://www.cbr.ru) | * | RUB | Yes |
| [currencylayer](https://currencylayer.com) | USD (free), * (paid) | * | Yes |
| [Cryptonator](https://www.cryptonator.com) | * Crypto (Limited standard currencies) | * Crypto (Limited standard currencies) | No |
| [1Forge](https://1forge.com) | * (free but limited or paid) | * (free but limited or paid) | No |
| [CurrencyDataFeed](https://currencydatafeed.com) | * (free but limited or paid) | * (free but limited or paid) | No |
| Array | * | * | Yes |

## Credits
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -32,7 +32,7 @@
},
"require": {
"php": "^5.5|^7.0",
"florianv/swap": "^3.0",
"florianv/swap": "^3.3",
"psr/cache": "^1.0",
"cache/adapter-common": "^0.3"
},
Expand Down
11 changes: 9 additions & 2 deletions config/swap.php
Expand Up @@ -33,7 +33,7 @@
| Here is the config spec for each service:
|
| * "central_bank_of_czech_republic", "central_bank_of_republic_turkey", "european_central_bank", "fixer"
| "google", "national_bank_of_romania", "webservicex", "yahoo", "russian_central_bank" can be enabled with "true" as value.
| "google", "national_bank_of_romania", "webservicex", "russian_central_bank", "cryptonator" can be enabled with "true" as value.
|
| * 'currency_layer' => [
| 'access_key' => 'secret', // Your app id
Expand All @@ -49,8 +49,15 @@
| 'token' => 'secret', // The API token
| ]
|
| * 'currency_data_feed' => [
| 'api_key' => 'secret', // The API token
| ]
|
| * 'forge' => [
| 'api_key' => 'secret', // The API token
| ]
|
*/

'services' => [
'fixer' => true,
],
Expand Down
4 changes: 3 additions & 1 deletion doc/readme.md
Expand Up @@ -250,6 +250,8 @@ Here is the complete list of supported services and their possible configuration
'webservicex' => true,
'xignite' => ['token' => 'token'],
'russian_central_bank' => true,
'cryptonator' => true
'cryptonator' => true,
'currency_data_feed' => ['api_key' => 'secret'],
'forge' => ['api_key' => 'secret'],
]
```
11 changes: 8 additions & 3 deletions src/SwapServiceProvider.php
Expand Up @@ -94,10 +94,10 @@ private function registerServices(Container $app)
$app->singleton($serviceName, function () use ($config) {
return new PhpArray($config);
});

$app->tag($serviceName, 'swap.service');
return;

continue;
}

// Process the regular services
Expand Down Expand Up @@ -200,6 +200,11 @@ public function provides()
*/
private function getServiceClass($name)
{
// WebserviceX is a special case
if ('webservicex' === $name) {
$name = 'webservice_x';
}

$camelized = ucfirst(implode('', array_map('ucfirst', explode('_', $name))));

return 'Exchanger\\Service\\'.$camelized;
Expand Down
38 changes: 38 additions & 0 deletions tests/SwapServiceProviderTest.php
Expand Up @@ -15,7 +15,22 @@
use Exchanger\ExchangeRate;
use Exchanger\ExchangeRateQuery;
use Exchanger\HistoricalExchangeRateQuery;
use Exchanger\Service\CentralBankOfCzechRepublic;
use Exchanger\Service\CentralBankOfRepublicTurkey;
use Exchanger\Service\Cryptonator;
use Exchanger\Service\CurrencyDataFeed;
use Exchanger\Service\CurrencyLayer;
use Exchanger\Service\EuropeanCentralBank;
use Exchanger\Service\Fixer;
use Exchanger\Service\Forge;
use Exchanger\Service\Google;
use Exchanger\Service\NationalBankOfRomania;
use Exchanger\Service\OpenExchangeRates;
use Exchanger\Service\PhpArray;
use Exchanger\Service\RussianCentralBank;
use Exchanger\Service\WebserviceX;
use Exchanger\Service\Xignite;
use Exchanger\Service\Yahoo;
use GrahamCampbell\TestBench\Traits\ServiceProviderTestCaseTrait;
use Exchanger\Service\Chain;
use Http\Discovery\HttpClientDiscovery;
Expand Down Expand Up @@ -75,10 +90,33 @@ public function testAllServices()
'xignite' => ['token' => 'token'],
'yahoo' => true,
'russian_central_bank' => true,
'currency_data_feed' => ['api_key' => 'secret'],
'forge' => ['api_key' => 'secret'],
'cryptonator' => true,
]);

$this->assertInstanceOf(Chain::class, $this->app['swap.chain']);

$services = $this->app->tagged('swap.service');

$this->assertCount(16, $services);

$this->assertInstanceOf(CentralBankOfCzechRepublic::class, $services[0]);
$this->assertInstanceOf(CentralBankOfRepublicTurkey::class, $services[1]);
$this->assertInstanceOf(CurrencyLayer::class, $services[2]);
$this->assertInstanceOf(EuropeanCentralBank::class, $services[3]);
$this->assertInstanceOf(Fixer::class, $services[4]);
$this->assertInstanceOf(Google::class, $services[5]);
$this->assertInstanceOf(NationalBankOfRomania::class, $services[6]);
$this->assertInstanceOf(OpenExchangeRates::class, $services[7]);
$this->assertInstanceOf(PhpArray::class, $services[8]);
$this->assertInstanceOf(WebserviceX::class, $services[9]);
$this->assertInstanceOf(Xignite::class, $services[10]);
$this->assertInstanceOf(Yahoo::class, $services[11]);
$this->assertInstanceOf(RussianCentralBank::class, $services[12]);
$this->assertInstanceOf(CurrencyDataFeed::class, $services[13]);
$this->assertInstanceOf(Forge::class, $services[14]);
$this->assertInstanceOf(Cryptonator::class, $services[15]);
}

public function testSwapIsInjectable()
Expand Down

0 comments on commit 68194ac

Please sign in to comment.