Skip to content

Commit

Permalink
Change price fetching to use curl instead of file_get_content
Browse files Browse the repository at this point in the history
  • Loading branch information
jusasiiv committed Aug 17, 2018
1 parent d14ebe0 commit e3c89a4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions system/library/blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,23 @@ public function __get($name) {

public function getBTCPrice() {
//Getting price
$options = array( 'http' => array( 'method' => 'GET') );
$context = stream_context_create($options);
$currency_code = $this->config->get('config_currency');
$contents = file_get_contents($this->blockonomics_price_url.$currency_code);
$priceObj = json_decode($contents);
return $priceObj->price;
$url = $this->blockonomics_price_url.$currency_code;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);

$data = curl_exec($ch);
curl_close($ch);

$responseObj = json_decode($data);
if (!isset($responseObj)) {
return '';
}

return $responseObj->price;
}

/**
Expand Down

0 comments on commit e3c89a4

Please sign in to comment.