Skip to content

Commit

Permalink
use curl for fetching VAT rates from jsonvat.com, #4
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Jan 21, 2017
1 parent fe1b13b commit 16e1174
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Rates/Clients/JsonVat.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ class JsonVat implements Client{
public function fetch() {
$url = self::URL;

// fetch data
$response = file_get_contents($url);
if( empty( $response ) ) {
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
$response_body = curl_exec($curl_handle);
curl_close($curl_handle);

if( empty( $response_body ) ) {
throw new ClientException( "Error fetching rates from {$url}.");
}
$data = json_decode($response);
$data = json_decode($response_body);

// build map with country codes => rates
$map = array();
Expand Down

0 comments on commit 16e1174

Please sign in to comment.