Class: ExpediaApi::ResponseLists::Hotels

Inherits:
BaseResponseList show all
Defined in:
lib/expedia_api/response_lists/hotels.rb

Instance Attribute Summary

Attributes inherited from BaseResponseList

#exception, #response

Instance Method Summary collapse

Methods inherited from BaseResponseList

#each, #entries, #error?, #first, #initialize, #last, #map, #success?

Constructor Details

This class inherits a constructor from ExpediaApi::ResponseLists::BaseResponseList

Instance Method Details

#entries=(entries) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/expedia_api/response_lists/hotels.rb', line 5

def entries=(entries)
  if entries
    @entries = entries.map {|e| ExpediaApi::Entities::SearchEntity.new(e.with_indifferent_access) }
  else
    @entries = []
  end
end

#extract_entries_from_response(response) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/expedia_api/response_lists/hotels.rb', line 13

def extract_entries_from_response(response)
  body = extract_data_from_response(response)
  return [] if body.empty?
  hotel_count = body["HotelCount"].to_i
  if hotel_count == 1
    [body["HotelInfoList"]["HotelInfo"]]
  elsif hotel_count > 1
    body["HotelInfoList"]["HotelInfo"]
  else
    []
  end
end