/** * Retrieve all the currencies available. * Return false if something went wrong. * * @return array|bool */ public function getCurrencies() { $response = $this->jsonRatesClient->get('currencies.json'); $reponseStatus = (int) $response->getStatusCode(); $responseBody = $response->getBody()->getContents(); if (Response::HTTP_OK === $reponseStatus) { $listCurrencies = json_decode($responseBody, true); return $listCurrencies; } return false; }
/** * Retrieve the rate for the given currencies. * Return false if something went wrong. * * @param Currency $from * @param Currency $to * * @return float|bool */ public function getRateFor(Currency $from, Currency $to) { $uri = '/get/?access_key=' . $this->apiKey . '&from=' . $from->getCode() . '&to=' . $to->getCode(); $response = $this->jsonRatesClient->get($uri); $reponseStatus = (int) $response->getStatusCode(); $responseBody = $response->getBody()->getContents(); if (Response::HTTP_OK === $reponseStatus) { $rate = (double) json_decode($responseBody, true); return $rate; } return false; }