/** * Turn the currencyCode exchange rate collection into a JSON structure. * * Format: * * { * "rates": { * "EUR": { * "rate": "0.706700000000", * "price_currency_code": "EUR" * } * }, * "valid_until": "2015-02-27T12:00:00Z" * } * * @return string the JSON structure. * @throws NostoException of the rate collection is empty. */ protected function getCollectionAsJson() { $data = array('rates' => array(), 'valid_until' => null); /** @var NostoExchangeRate $item */ foreach ($this->collection as $item) { $data['rates'][$item->getName()] = array('rate' => $item->getExchangeRate(), 'price_currency_code' => $item->getCurrencyCode()); } if (empty($data['rates'])) { Nosto::throwException(sprintf('Failed to update currencyCode exchange rates for account %s. No rates found in collection.', $this->account->getName())); } return json_encode($data); }