/** * @param Response $response * * @return static */ public static function fromResponse(Response $response) { $responseData = $response->getContentAsArray(); $hotelDeals = new static(); $hotelDeals->pollingFinished = $response->getHttpCode() === 200; $hotelDeals->deals = array_map(function (array $deal) { return Deal::fromArray($deal); }, $responseData['hotel_rates']); $hotelDeals->searchParams = $responseData['search_params']; return $hotelDeals; }
/** * @param Response $response * * @return HotelCollection */ public static function fromResponse(Response $response) { $responseData = $response->getContentAsArray(); $hotelCollection = new static(); $hotelCollection->pollingFinished = $response->getHttpCode() === 200; $hotelCollection->searchParams = $responseData['search_params']; $hotelCollection->resultInfo = ResultInfo::fromArray($responseData['result_info']); if (isset($responseData['_links']['next'])) { $hotelCollection->hasNextPage = true; $hotelCollection->nextPageOffset = static::extractOffsetFromUrl($responseData['_links']['next']['href']); } if (isset($responseData['_links']['prev'])) { $hotelCollection->hasPrevPage = true; $hotelCollection->prevPageOffset = static::extractOffsetFromUrl($responseData['_links']['prev']['href']); } foreach ($responseData['hotels'] as $data) { $hotelDetails = $data['_embedded']['hotel_details']; $hotelRates = $data['_embedded']['hotel_rates']; $hotelCollection->hotel[] = new Hotel($hotelDetails['id'], $hotelDetails['name'], $hotelDetails['category'], $hotelDetails['superior'], $hotelDetails['city'], $hotelDetails['rating_value'], $hotelDetails['rating_count'], Image::fromArray($hotelDetails['main_image']), array_map(function (array $deal) { return Deal::fromArray($deal); }, $hotelRates)); } return $hotelCollection; }