Skip to content

Commit

Permalink
Add access key for fixer.io.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielme85 committed Aug 28, 2018
1 parent 99fad13 commit 5a923da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/Providers/Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public function download(string $currency, string $date = null) {
$url = 'http';
}
if (!empty($date)) {
$url .= "://data.fixer.io/api/$date?base=$currency";
$url .= "://data.fixer.io/api/$date?access_key=".$this->settings['fixer-access-key']."&base=$currency";
} else {
$url .= "://data.fixer.io/api/latest?base=$currency";
$url .= "://data.fixer.io/api/latest?access_key=".$this->settings['fixer-access-key']."&base=$currency";
}
$this->url = $url;
$response = $this->connect($url);
Expand Down Expand Up @@ -100,16 +100,15 @@ private function convert($input) : Rates
if (!empty($data['rates'])) {
$rates->extra['fixer_date'] = $data['date'] ?? null;
foreach ($data['rates'] as $key => $row) {
$newrates[$key] = $row;
$rates->rates[$key] = $row;
}
//add 1:1 conversion rate from base for testing
$newrates[$data['base']] = 1;
$rates->rates[$data['base']] = 1;
}
}
else {
$rates->error = "No data in response from Fixer.io";
}
$rates->rates = $newrates;

return $rates;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/CurrencyConvertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function testFixer()
$this->assertEquals(1, $currency->convert('NOK', 'NOK', 1));

//Live test
$currency = new Currency('currencylayer', false);
$currency = new Currency('fixer', false);
$this->assertNotEmpty($currency->getRateResults());
$this->assertNotEmpty($currency->getRateResults('USD', '2018-01-01'));
$this->assertEquals(1, $currency->convert('USD', 'USD', 1));
Expand Down

0 comments on commit 5a923da

Please sign in to comment.