Class: Suitcase::Hotel
- Inherits:
-
Object
- Object
- Suitcase::Hotel
- Extended by:
- Helpers
- Defined in:
- lib/suitcase/hotel/hotel.rb,
lib/suitcase/hotel/location.rb
Overview
A Class representing a Hotel that stores information about the hotel. It provides methods for checking room availability, fetching images and just general information providing.
Defined Under Namespace
Classes: Location
Constant Summary
- AMENITIES =
{ pool: 1, fitness_center: 2, restaurant: 3, children_activities: 4, breakfast: 5, meeting_facilities: 6, pets: 7, wheelchair_accessible: 8, kitchen: 9 }
Instance Attribute Summary (collapse)
-
- (Object) address
Returns the value of attribute address.
-
- (Object) airport_code
Returns the value of attribute airport_code.
-
- (Object) amenities
Returns the value of attribute amenities.
-
- (Object) amenity_mask
Returns the value of attribute amenity_mask.
-
- (Object) city
Returns the value of attribute city.
-
- (Object) confidence_rating
Returns the value of attribute confidence_rating.
-
- (Object) country_code
Returns the value of attribute country_code.
-
- (Object) deep_link
Returns the value of attribute deep_link.
-
- (Object) high_rate
Returns the value of attribute high_rate.
-
- (Object) hotel_in_destination
Returns the value of attribute hotel_in_destination.
-
- (Object) id
Returns the value of attribute id.
-
- (Object) images
Returns the value of attribute images.
-
- (Object) latitude
Returns the value of attribute latitude.
-
- (Object) location_description
Returns the value of attribute location_description.
-
- (Object) longitude
Returns the value of attribute longitude.
-
- (Object) low_rate
Returns the value of attribute low_rate.
-
- (Object) name
Returns the value of attribute name.
-
- (Object) nightly_rate_total
Returns the value of attribute nightly_rate_total.
-
- (Object) number_of_floors
Returns the value of attribute number_of_floors.
-
- (Object) number_of_rooms
Returns the value of attribute number_of_rooms.
-
- (Object) postal_code
Returns the value of attribute postal_code.
-
- (Object) property_category
Returns the value of attribute property_category.
-
- (Object) property_description
Returns the value of attribute property_description.
-
- (Object) province
Returns the value of attribute province.
-
- (Object) proximity_distance
Returns the value of attribute proximity_distance.
-
- (Object) rating
Returns the value of attribute rating.
-
- (Object) short_description
Returns the value of attribute short_description.
-
- (Object) supplier_type
Returns the value of attribute supplier_type.
-
- (Object) tripadvisor_rating
Returns the value of attribute tripadvisor_rating.
Class Method Summary (collapse)
-
+ (Object) find(info)
Public: Find a Hotel based on known information.
-
+ (Object) find_by_id(id, session)
Public: Find a Hotel by it's id.
- + (Object) find_by_ids(ids, session)
-
+ (Object) find_by_info(info)
Public: Find a hotel by info other than it's id.
-
+ (Object) handle_errors(info)
Handle the errors from the response.
-
+ (Object) images(parsed)
Public: Get images from a parsed object.
-
+ (Object) parse_information(parsed)
Public: Parse the information returned by a search request.
- + (Object) split(parsed)
Instance Method Summary (collapse)
-
- (Hotel) initialize(info)
constructor
Public: Initialize a new hotel.
-
- (Object) rooms(info)
Public: Fetch possible rooms from a Hotel.
- - (Object) thumbnail_url
Methods included from Helpers
base_url, main_url, parse_response, update_session, url
Constructor Details
- (Hotel) initialize(info)
Public: Initialize a new hotel
info - a Hash of the options listed in attr_accesor.
Returns a new Hotel object with the passed-in attributes.
41 42 43 44 45 |
# File 'lib/suitcase/hotel/hotel.rb', line 41 def initialize(info) info.each do |k, v| send (k.to_s + "=").to_sym, v end end |
Instance Attribute Details
- (Object) address
Returns the value of attribute address
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def address @address end |
- (Object) airport_code
Returns the value of attribute airport_code
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def airport_code @airport_code end |
- (Object) amenities
Returns the value of attribute amenities
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def amenities @amenities end |
- (Object) amenity_mask
Returns the value of attribute amenity_mask
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def amenity_mask @amenity_mask end |
- (Object) city
Returns the value of attribute city
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def city @city end |
- (Object) confidence_rating
Returns the value of attribute confidence_rating
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def @confidence_rating end |
- (Object) country_code
Returns the value of attribute country_code
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def country_code @country_code end |
- (Object) deep_link
Returns the value of attribute deep_link
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def deep_link @deep_link end |
- (Object) high_rate
Returns the value of attribute high_rate
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def high_rate @high_rate end |
- (Object) hotel_in_destination
Returns the value of attribute hotel_in_destination
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def hotel_in_destination @hotel_in_destination end |
- (Object) id
Returns the value of attribute id
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def id @id end |
- (Object) images
Returns the value of attribute images
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def images @images end |
- (Object) latitude
Returns the value of attribute latitude
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def latitude @latitude end |
- (Object) location_description
Returns the value of attribute location_description
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def location_description @location_description end |
- (Object) longitude
Returns the value of attribute longitude
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def longitude @longitude end |
- (Object) low_rate
Returns the value of attribute low_rate
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def low_rate @low_rate end |
- (Object) name
Returns the value of attribute name
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def name @name end |
- (Object) nightly_rate_total
Returns the value of attribute nightly_rate_total
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def nightly_rate_total @nightly_rate_total end |
- (Object) number_of_floors
Returns the value of attribute number_of_floors
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def number_of_floors @number_of_floors end |
- (Object) number_of_rooms
Returns the value of attribute number_of_rooms
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def number_of_rooms @number_of_rooms end |
- (Object) postal_code
Returns the value of attribute postal_code
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def postal_code @postal_code end |
- (Object) property_category
Returns the value of attribute property_category
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def property_category @property_category end |
- (Object) property_description
Returns the value of attribute property_description
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def property_description @property_description end |
- (Object) province
Returns the value of attribute province
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def province @province end |
- (Object) proximity_distance
Returns the value of attribute proximity_distance
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def proximity_distance @proximity_distance end |
- (Object) rating
Returns the value of attribute rating
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def @rating end |
- (Object) short_description
Returns the value of attribute short_description
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def short_description @short_description end |
- (Object) supplier_type
Returns the value of attribute supplier_type
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def supplier_type @supplier_type end |
- (Object) tripadvisor_rating
Returns the value of attribute tripadvisor_rating
34 35 36 |
# File 'lib/suitcase/hotel/hotel.rb', line 34 def @tripadvisor_rating end |
Class Method Details
+ (Object) find(info)
Public: Find a Hotel based on known information
info - a Hash of known information
Returns a single Hotel if an id is passed in, otherwise an Array of Hotels.
53 54 55 56 57 58 59 60 61 |
# File 'lib/suitcase/hotel/hotel.rb', line 53 def self.find(info) if info[:ids] find_by_ids(info[:ids], info[:session]) elsif info[:id] find_by_id(info[:id], info[:session]) else find_by_info(info) end end |
+ (Object) find_by_id(id, session)
Public: Find a Hotel by it's id.
id - an Integer or String representation of the Hotel's
id.
Returns a single Hotel object.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/suitcase/hotel/hotel.rb', line 69 def self.find_by_id(id, session) params = { hotelId: id } if Configuration.cache? and Configuration.cache.cached?(:info, params) raw = Configuration.cache.get_query(:info, params) else url = url(:method => "info", :params => params, :session => session) raw = parse_response(url) handle_errors(raw) Configuration.cache.save_query(:info, params, raw) if Configuration.cache? end hotel_data = parse_information(raw) update_session(raw, session) Hotel.new(hotel_data) end |
+ (Object) find_by_ids(ids, session)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/suitcase/hotel/hotel.rb', line 84 def self.find_by_ids(ids, session) params = { hotelIdList: ids.join(",") } if Configuration.cache? and Configuration.cache.cached?(:list, params) raw = Configuration.cache.get_query(:list, params) else url = url(:method => "list", :params => params, :session => session) raw = parse_response(url) handle_errors(raw) Configuration.cache.save_query(:list, params, raw) if Configuration.cache? end hotels = [] [split(raw)].flatten.each do |hotel_data| hotels.push Hotel.new(parse_information(hotel_data)) end update_session(raw, session) hotels end |
+ (Object) find_by_info(info)
Public: Find a hotel by info other than it's id.
info - a Hash of options described in the Hotel
accessors, excluding the id.
Returns an Array of Hotels.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/suitcase/hotel/hotel.rb', line 108 def self.find_by_info(info) params = info.dup params["numberOfResults"] = params[:results] ? params[:results] : 10 params.delete(:results) params["destinationString"] = params[:location] params.delete(:location) amenities = params[:amenities] ? params[:amenities].map { |amenity| AMENITIES[amenity] }.join(",") : nil params["minRate"] = params[:min_rate] if params[:min_rate] params["maxRate"] = params[:max_rate] if params[:max_rate] params[:amenities] = amenities if amenities hotels = [] if Configuration.cache? and Configuration.cache.cached?(:list, params) parsed = Configuration.cache.get_query(:list, params) else parsed = parse_response(url(:method => "list", :params => params, :session => info[:session])) handle_errors(parsed) Configuration.cache.save_query(:list, params, parsed) if Configuration.cache? end [split(parsed)].flatten.each do |hotel_data| hotels.push Hotel.new(parse_information(hotel_data)) end update_session(parsed, info[:session]) info[:results] ? hotels[0..(info[:results]-1)] : hotels end |
+ (Object) handle_errors(info)
Handle the errors from the response.
163 164 165 166 167 168 169 |
# File 'lib/suitcase/hotel/hotel.rb', line 163 def self.handle_errors(info) key = info.keys.first if info[key] && info[key]["EanWsError"] = info[key]["EanWsError"]["presentationMessage"] end raise EANException.new() if end |
+ (Object) images(parsed)
Public: Get images from a parsed object
parsed - a Hash representing the parsed JSON
Returns an Array of Suitcase::Images.
156 157 158 159 160 |
# File 'lib/suitcase/hotel/hotel.rb', line 156 def self.images(parsed) images = parsed["HotelInformationResponse"]["HotelImages"]["HotelImage"].map { |image_data| Suitcase::Image.new(image_data) } if parsed["HotelInformationResponse"] && parsed["HotelInformationResponse"]["HotelImages"] && parsed["HotelInformationResponse"]["HotelImages"]["HotelImage"] images = [Suitcase::Image.new("thumbnailURL" => "http://images.travelnow.com" + parsed["thumbNailUrl"])] unless parsed["thumbNailUrl"].nil? or parsed["thumbNailUrl"].empty? return images ? images : [] end |
+ (Object) parse_information(parsed)
Public: Parse the information returned by a search request
parsed - a Hash representing the parsed JSON
Returns a reformatted Hash with the specified accessors.
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/suitcase/hotel/hotel.rb', line 138 def self.parse_information(parsed) handle_errors(parsed) summary = parsed["hotelId"] ? parsed : parsed["HotelInformationResponse"]["HotelSummary"] parsed_info = { id: summary["hotelId"], name: summary["name"], address: summary["address1"], city: summary["city"], postal_code: summary["postalCode"], country_code: summary["countryCode"], rating: summary["hotelRating"], high_rate: summary["highRate"], low_rate: summary["lowRate"], latitude: summary["latitude"].to_f, longitude: summary["longitude"].to_f, province: summary["stateProvinceCode"], airport_code: summary["airportCode"], property_category: summary["propertyCategory"].to_i, proximity_distance: summary["proximityDistance"].to_s + summary["proximityUnit"].to_s, tripadvisor_rating: summary["tripAdvisorRating"], deep_link: summary["deepLink"] } parsed_info[:amenities] = parsed["HotelInformationResponse"]["PropertyAmenities"]["PropertyAmenity"].map { |x| Amenity.new(id: x["amenityId"], description: x["amenity"]) } if parsed["HotelInformationResponse"] parsed_info[:images] = images(parsed) if images(parsed) parsed_info[:property_description] = parsed["HotelInformationResponse"]["HotelDetails"]["propertyDescription"] if parsed["HotelInformationResponse"] parsed_info[:location_description] = summary["locationDescription"] parsed_info[:number_of_rooms] = parsed["HotelInformationResponse"]["HotelDetails"]["numberOfRooms"] if parsed["HotelInformationResponse"] parsed_info[:number_of_floors] = parsed["HotelInformationResponse"]["HotelDetails"]["numberOfFloors"] if parsed["HotelInformationResponse"] parsed_info end |
+ (Object) split(parsed)
171 172 173 174 |
# File 'lib/suitcase/hotel/hotel.rb', line 171 def self.split(parsed) hotels = parsed["HotelListResponse"]["HotelList"] hotels["HotelSummary"] end |
Instance Method Details
- (Object) rooms(info)
Public: Fetch possible rooms from a Hotel.
info - a Hash of options described as the accessors in
the Suitcase::Room class
Returns an Array of Suitcase::Rooms.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/suitcase/hotel/hotel.rb', line 187 def rooms(info) params = { rooms: [{adults: 1, children_ages: []}] }.merge(info) params[:rooms].each_with_index do |room, n| params["room#{n+1}"] = room[:adults].to_s + "," + (room[:children_ages].join(",") if room[:children_ages]) end params["arrivalDate"] = info[:arrival] params["departureDate"] = info[:departure] params["includeDetails"] = true params.delete(:arrival) params.delete(:departure) params["hotelId"] = @id if Configuration.cache? and Configuration.cache.cached?(:avail, params) parsed = Configuration.cache.get_query(:avail, params) else parsed = Hotel.parse_response(Hotel.url(:method => "avail", :params => params, :session => info[:session])) Hotel.handle_errors(parsed) Configuration.cache.save_query(:avail, params, parsed) if Configuration.cache? end hotel_id = parsed["HotelRoomAvailabilityResponse"]["hotelId"] rate_key = parsed["HotelRoomAvailabilityResponse"]["rateKey"] supplier_type = parsed["HotelRoomAvailabilityResponse"]["HotelRoomResponse"][0]["supplierType"] Hotel.update_session(parsed, info[:session]) rooms = parsed["HotelRoomAvailabilityResponse"]["HotelRoomResponse"].map do |raw_data| room_data = {} room_data[:rate_code] = raw_data["rateCode"] room_data[:room_type_code] = raw_data["roomTypeCode"] room_data[:room_type_description] = raw_data["roomTypeDescription"] room_data[:promo] = raw_data["RateInfo"]["@promo"].to_b room_data[:price_breakdown] = raw_data["RateInfo"]["ChargeableRateInfo"]["NightlyRatesPerRoom"]["NightlyRate"].map { |raw| NightlyRate.new(raw) } if raw_data["RateInfo"]["ChargeableRateInfo"] && raw_data["RateInfo"]["ChargeableRateInfo"]["NightlyRatesPerRoom"] && raw_data["RateInfo"]["ChargeableRateInfo"]["NightlyRatesPerRoom"]["NightlyRate"].is_a?(Array) room_data[:total_price] = raw_data["RateInfo"]["ChargeableRateInfo"]["@total"] room_data[:nightly_rate_total] = raw_data["RateInfo"]["ChargeableRateInfo"]["@nightlyRateTotal"] room_data[:average_nightly_rate] = raw_data["RateInfo"]["ChargeableRateInfo"]["@averageRate"] room_data[:arrival] = info[:arrival] room_data[:departure] = info[:departure] room_data[:rate_key] = rate_key room_data[:hotel_id] = hotel_id room_data[:supplier_type] = supplier_type room_data[:rooms] = params[:rooms] room_data[:bed_types] = [raw_data["BedTypes"]["BedType"]].flatten.map { |x| BedType.new(id: x["@id"], description: x["description"]) } if raw_data["BedTypes"] && raw_data["BedTypes"]["BedType"] Room.new(room_data) end end |
- (Object) thumbnail_url
176 177 178 179 |
# File 'lib/suitcase/hotel/hotel.rb', line 176 def thumbnail_url first_image = images.find { |img| img.thumbnail_url != nil } first_image.thumbnail_url if first_image end |