Class: Suitcase::Hotel::Location
- Inherits:
-
Object
- Object
- Suitcase::Hotel::Location
- Extended by:
- Helpers
- Defined in:
- lib/suitcase/hotel/location.rb
Constant Summary
Constants included from Helpers
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#city ⇒ Object
Returns the value of attribute city.
-
#country ⇒ Object
Returns the value of attribute country.
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#destination_id ⇒ Object
Returns the value of attribute destination_id.
-
#province ⇒ Object
Returns the value of attribute province.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.find(info) ⇒ Object
Public: Find a Location.
- .handle_errors(info) ⇒ Object
- .parse(raw) ⇒ Object
Instance Method Summary collapse
-
#initialize(info) ⇒ Location
constructor
A new instance of Location.
Methods included from Helpers
base_url, build_session_params, generate_signature, handle_errors, main_url, parameterize, parse_response, update_session, url
Constructor Details
#initialize(info) ⇒ Location
Returns a new instance of Location.
7 8 9 10 11 |
# File 'lib/suitcase/hotel/location.rb', line 7 def initialize(info) info.each do |k, v| instance_variable_set("@" + k.to_s, v) end end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
4 5 6 |
# File 'lib/suitcase/hotel/location.rb', line 4 def active @active end |
#city ⇒ Object
Returns the value of attribute city.
4 5 6 |
# File 'lib/suitcase/hotel/location.rb', line 4 def city @city end |
#country ⇒ Object
Returns the value of attribute country.
4 5 6 |
# File 'lib/suitcase/hotel/location.rb', line 4 def country @country end |
#country_code ⇒ Object
Returns the value of attribute country_code.
4 5 6 |
# File 'lib/suitcase/hotel/location.rb', line 4 def country_code @country_code end |
#destination_id ⇒ Object
Returns the value of attribute destination_id.
4 5 6 |
# File 'lib/suitcase/hotel/location.rb', line 4 def destination_id @destination_id end |
#province ⇒ Object
Returns the value of attribute province.
4 5 6 |
# File 'lib/suitcase/hotel/location.rb', line 4 def province @province end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/suitcase/hotel/location.rb', line 4 def type @type end |
Class Method Details
.find(info) ⇒ Object
Public: Find a Location.
info - A Hash of information to search by, including city & address.
Returns an Array of Location’s.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/suitcase/hotel/location.rb', line 21 def find(info) params = {} [:city, :address].each do |dup| params[dup] = info[dup] if info[dup] end if info[:destination_string] params[:destinationString] = info[:destination_string] end if Configuration.cache? and Configuration.cache.cached?(:geoSearch, params) raw = Configuration.cache.get_query(:geoSearch, params) else url = url(:method => 'geoSearch', :params => params, :session => info[:session]) raw = parse_response(url) handle_errors(raw) end parse(raw) end |
.handle_errors(info) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/suitcase/hotel/location.rb', line 56 def handle_errors(info) key = info.keys.first if info[key] && info[key]["EanWsError"] = info[key]["EanWsError"]["presentationMessage"] end raise EANException.new() if end |
.parse(raw) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/suitcase/hotel/location.rb', line 41 def parse(raw) [raw["LocationInfoResponse"]["LocationInfos"]["LocationInfo"]].flatten.map do |raw| Location.new( province: raw["stateProvinceCode"], destination_id: raw["destinationId"], type: raw["type"], city: raw["city"], active: raw["active"], code: raw["code"], country: raw["country"], country_code: raw["countryCode"] ) end end |