Class: Parsec::Request::Availability
- Defined in:
- lib/parsec/request/availability.rb
Constant Summary
Constants inherited from Base
Base::DATE_FORMAT, Base::NAMESPACE, Base::RESOURCES
Instance Method Summary collapse
-
#availability_request(from_date, to_date, rooms, search_criteria) ⇒ Object
rubocop:enable Metrics/AbcSize.
-
#by_hotel(from_date, to_date, rooms, hotel_search_criteria) ⇒ Object
rooms - array of room hashes, e.g.
- #search(from_date, to_date, rooms, search_criteria) ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Parsec::Request::Base
Instance Method Details
#availability_request(from_date, to_date, rooms, search_criteria) ⇒ Object
rubocop:enable Metrics/AbcSize
27 28 29 30 31 32 33 34 35 |
# File 'lib/parsec/request/availability.rb', line 27 def availability_request(from_date, to_date, rooms, search_criteria) attributes = { 'RateDetails' => '1', 'DetailLevel' => '1', 'CancelPenalties' => '1', 'Language' => 'EN' } = (from_date, to_date, rooms_description(rooms), search_criteria) response = client(:availability).call('OTA_HotelAvailRQ', attributes: attributes, message: ) response.body rescue Savon::Error => e Xlog.and_raise_error(e) end |
#by_hotel(from_date, to_date, rooms, hotel_search_criteria) ⇒ Object
rooms - array of room hashes, e.g. { rph1: { adults: 2, children: [5, 8]}, rph2: { adults: 3 }} rubocop:disable Metrics/AbcSize
8 9 10 11 12 13 14 15 |
# File 'lib/parsec/request/availability.rb', line 8 def by_hotel(from_date, to_date, rooms, hotel_search_criteria) hotels = availability_request(from_date, to_date, rooms, hotel_search_criteria) return error(hotels[:ota_hotel_avail_rs]) if hotels[:ota_hotel_avail_rs][:errors].present? Array.wrap(hotels[:ota_hotel_avail_rs][:hotels][:hotel]).map do |h| Array.wrap(h[:rooms][:room]).map { |r| Parsec::Availability.build(r, h[:info], (to_date - from_date).to_i) } end.flatten.group_by(&:hotel_code) end |
#search(from_date, to_date, rooms, search_criteria) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/parsec/request/availability.rb', line 17 def search(from_date, to_date, rooms, search_criteria) hotels = availability_request(from_date, to_date, rooms, search_criteria) return error(hotels[:ota_hotel_avail_rs]) if hotels[:ota_hotel_avail_rs][:errors].present? Array.wrap(hotels[:ota_hotel_avail_rs][:hotels][:hotel]).map do |h| Array.wrap(h[:rooms][:room]).map { |r| Parsec::Availability.search(r, h[:info][:@hotel_code]) } end.flatten.group_by(&:hotel_code) end |