Class: TAPI::V3::Hotels::Search
- Inherits:
-
GenericSearch
- Object
- GenericSearch
- TAPI::V3::Hotels::Search
- Defined in:
- lib/tapi/v3/hotels/search.rb
Instance Attribute Summary collapse
-
#arrival_date ⇒ Object
Returns the value of attribute arrival_date.
-
#city_id ⇒ Object
Returns the value of attribute city_id.
-
#departure_date ⇒ Object
Returns the value of attribute departure_date.
-
#double_rooms_count ⇒ Object
Returns the value of attribute double_rooms_count.
-
#expired ⇒ Object
Returns the value of attribute expired.
-
#hotel_id ⇒ Object
Returns the value of attribute hotel_id.
-
#region_id ⇒ Object
Returns the value of attribute region_id.
-
#room_configuration ⇒ Object
Returns the value of attribute room_configuration.
-
#single_rooms_count ⇒ Object
Returns the value of attribute single_rooms_count.
Attributes inherited from GenericSearch
#client, #client_urls, #errors, #start_time, #started_at
Class Method Summary collapse
Instance Method Summary collapse
- #city ⇒ Object
- #hotel ⇒ Object
-
#hotel_search(result_or_hotel_id) ⇒ Object
create a hotel search with the same parameters for a given hotel.
-
#initialize(options = {}) ⇒ Search
constructor
class.
- #item_path ⇒ Object
- #location ⇒ Object
- #location_id ⇒ Object
- #location_type ⇒ Object
- #parameters ⇒ Object
- #region ⇒ Object
- #state ⇒ Object
- #to_param ⇒ Object
- #update_room_configuration! ⇒ Object
Methods inherited from GenericSearch
#add_error, #api_key, #api_url, #get, #has_errors?, #id, #id=, #load_client, #method_missing, #post_url, #reload, #restart!, #start!, #valid?
Methods included from TAPI::Validations
#add_error, #has_errors?, #inherited_validations, #validate, #validates_date_format_of, #validates_numericality_of, #validates_presence_of, #validations
Methods included from Utils
append_query, coerce_date, parse_date, symbolize_keys
Methods included from Configurable
Constructor Details
#initialize(options = {}) ⇒ Search
class
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tapi/v3/hotels/search.rb', line 67 def initialize( = {}) @errors = {} @single_rooms_count = 0 @double_rooms_count = 0 self.arrival_date = [:arrival_date] self.departure_date = [:departure_date] self.city_id = [:city_id] self.region_id = [:region_id] self.hotel_id = [:hotel_id] if [:room_configuration].blank? self.single_rooms_count = [:single_rooms_count] || 1 self.double_rooms_count = [:double_rooms_count] || 0 else self.room_configuration = [:room_configuration] end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class TAPI::V3::GenericSearch
Instance Attribute Details
#arrival_date ⇒ Object
Returns the value of attribute arrival_date.
8 9 10 |
# File 'lib/tapi/v3/hotels/search.rb', line 8 def arrival_date @arrival_date end |
#city_id ⇒ Object
Returns the value of attribute city_id.
8 9 10 |
# File 'lib/tapi/v3/hotels/search.rb', line 8 def city_id @city_id end |
#departure_date ⇒ Object
Returns the value of attribute departure_date.
8 9 10 |
# File 'lib/tapi/v3/hotels/search.rb', line 8 def departure_date @departure_date end |
#double_rooms_count ⇒ Object
Returns the value of attribute double_rooms_count.
9 10 11 |
# File 'lib/tapi/v3/hotels/search.rb', line 9 def double_rooms_count @double_rooms_count end |
#expired ⇒ Object
Returns the value of attribute expired.
6 7 8 |
# File 'lib/tapi/v3/hotels/search.rb', line 6 def expired @expired end |
#hotel_id ⇒ Object
Returns the value of attribute hotel_id.
8 9 10 |
# File 'lib/tapi/v3/hotels/search.rb', line 8 def hotel_id @hotel_id end |
#region_id ⇒ Object
Returns the value of attribute region_id.
8 9 10 |
# File 'lib/tapi/v3/hotels/search.rb', line 8 def region_id @region_id end |
#room_configuration ⇒ Object
Returns the value of attribute room_configuration.
9 10 11 |
# File 'lib/tapi/v3/hotels/search.rb', line 9 def room_configuration @room_configuration end |
#single_rooms_count ⇒ Object
Returns the value of attribute single_rooms_count.
9 10 11 |
# File 'lib/tapi/v3/hotels/search.rb', line 9 def single_rooms_count @single_rooms_count end |
Class Method Details
.parse_room_configuration(str) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tapi/v3/hotels/search.rb', line 42 def parse_room_configuration(str) rooms_strings = str.split('][').map {|r| r.gsub(/\]|\[/, '').split('|')} raise ArgumentError, "#{str} is not a valid room configuration hash !" if rooms_strings.length > 3 || rooms_strings.empty? room_collection = {} rooms = rooms_strings.each_with_index do |guests, i| room_collection[i + 1] ||= {} guests.each do |g| case g when 'A' room_collection[i + 1]['adults'] ||= 0 room_collection[i + 1]['adults'] += 1 when /\d/ room_collection[i + 1]['child'] ||= {} last_key = room_collection[i + 1]['child'].keys.min || 0 room_collection[i + 1]['child'][last_key + 1] = g.to_i else raise ArgumentError, "#{str} is not a valid room configuration hash !" end end end room_collection end |
Instance Method Details
#city ⇒ Object
141 142 143 |
# File 'lib/tapi/v3/hotels/search.rb', line 141 def city @city ||= get("/locations/cities/#{city_id}").city unless city_id.to_s.empty? end |
#hotel ⇒ Object
149 150 151 |
# File 'lib/tapi/v3/hotels/search.rb', line 149 def hotel @hotel ||= get("/locations/hotels/#{hotel_id}").hotel unless hotel_id.to_s.empty? end |
#hotel_search(result_or_hotel_id) ⇒ Object
create a hotel search with the same parameters for a given hotel
201 202 203 204 205 206 207 208 |
# File 'lib/tapi/v3/hotels/search.rb', line 201 def hotel_search(result_or_hotel_id) hotel_id = result_or_hotel_id.is_a?(Fixnum) ? result_or_hotel_id : result_or_hotel_id.hotel_id params = parameters params.delete(:city_id) params.delete(:region_id) params[:hotel_id] = hotel_id TAPI::V3::Hotels::Search.new(params) end |
#item_path ⇒ Object
87 88 89 |
# File 'lib/tapi/v3/hotels/search.rb', line 87 def item_path 'hotels' end |
#location ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/tapi/v3/hotels/search.rb', line 95 def location case when city_id then city when region_id then region when hotel_id then hotel end end |
#location_id ⇒ Object
111 112 113 |
# File 'lib/tapi/v3/hotels/search.rb', line 111 def location_id city_id || region_id || hotel_id end |
#location_type ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/tapi/v3/hotels/search.rb', line 103 def location_type case when city_id then :city when region_id then :region when hotel_id then :hotel end end |
#parameters ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/tapi/v3/hotels/search.rb', line 186 def parameters { :key => config[:key], :format => 'json', :city_id => city_id, :region_id => region_id, :hotel_id => hotel_id, :arrival_date => arrival_date.to_s, :departure_date => departure_date.to_s, :room_configuration => room_configuration } end |
#region ⇒ Object
145 146 147 |
# File 'lib/tapi/v3/hotels/search.rb', line 145 def region @region ||= get("/locations/regions/#{region_id}").region unless region_id.to_s.empty? end |
#state ⇒ Object
91 92 93 |
# File 'lib/tapi/v3/hotels/search.rb', line 91 def state @client.status_detailed.state if @client end |
#to_param ⇒ Object
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/tapi/v3/hotels/search.rb', line 175 def to_param { :location_type => location_type, :location_id => location_id, :arrival_date => arrival_date.to_s, :departure_date => departure_date.to_s, :single_rooms_count => single_rooms_count, :double_rooms_count => double_rooms_count } end |
#update_room_configuration! ⇒ Object
171 172 173 |
# File 'lib/tapi/v3/hotels/search.rb', line 171 def update_room_configuration! @room_configuration = ('[A]' * single_rooms_count) + ('[A|A]' * double_rooms_count) end |