Пример #1
0
 /**
  * First we check if we've attempted to make a request w/in the time limit for Bitcoincharts.
  * If so, return stale data.
  *
  * If we haven't made a request, or $_btcCurrencyStr is null (only on first run), we attempt
  * to make a GET Requst to the bitcoincharts API. If we don't get a respone we return an error
  * message.
  *
  * If we get a response, we format a currency string for the channel and update the
  * _lastCurrencyRequest.
  *
  * @return string   A currency string or an error message on failure.
  */
 private function getCurrencyData()
 {
     // Enforce that we can't hit the Bitcoins server more than once every 15 minutes.
     if (time() > $this->_lastCurrencyRequest + self::bChartsWaitSec || null == self::$_btcCurrencyStr) {
         $currencyJSON = file_get_contents(self::btcchartsURL);
         if (FALSE == $currencyJSON) {
             return 'Error retreiving currency, try again soon.';
         }
         $cSet = json_decode($currencyJSON);
         self::$_btcCurrencyStr = sprintf("USD 24h:%s 7d:%s 30d:%s", $cSet->USD->{'24h'}, $cSet->USD->{'7d'}, $cSet->USD->{'30d'});
         $this->_lastCurrencyRequest = time();
         return self::$_btcCurrencyStr;
     }
     return sprintf("[%ss stale] %s", time() - $this->_lastCurrencyRequest, self::$_btcCurrencyStr);
 }