Class: Suitcase::Hotel::Location

Inherits:
Object
  • Object
show all
Extended by:
Helpers
Defined in:
lib/suitcase/hotel/location.rb

Constant Summary

Constants included from Helpers

Helpers::URL_DEFAULTS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

base_url, build_session_params, generate_signature, handle_errors, main_url, parameterize, parameterize_rooms, 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

#activeObject

Returns the value of attribute active.



4
5
6
# File 'lib/suitcase/hotel/location.rb', line 4

def active
  @active
end

#cityObject

Returns the value of attribute city.



4
5
6
# File 'lib/suitcase/hotel/location.rb', line 4

def city
  @city
end

#countryObject

Returns the value of attribute country.



4
5
6
# File 'lib/suitcase/hotel/location.rb', line 4

def country
  @country
end

#country_codeObject

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_idObject

Returns the value of attribute destination_id.



4
5
6
# File 'lib/suitcase/hotel/location.rb', line 4

def destination_id
  @destination_id
end

#provinceObject

Returns the value of attribute province.



4
5
6
# File 'lib/suitcase/hotel/location.rb', line 4

def province
  @province
end

#typeObject

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

Raises:



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"]
    message = info[key]["EanWsError"]["presentationMessage"]
  end
  
  raise EANException.new(message) if message
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