Class: Suitcase::Hotel::Location

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

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Suitcase::Helpers

base_url, main_url, parse_response, update_session, url

Constructor Details

- (Location) initialize(info)

Returns a new instance of Location



8
9
10
11
12
# File 'lib/suitcase/hotel/location.rb', line 8

def initialize(info)
  info.each do |k, v|
    instance_variable_set("@" + k.to_s, v)
  end
end

Instance Attribute Details

- (Object) active

Returns the value of attribute active



6
7
8
# File 'lib/suitcase/hotel/location.rb', line 6

def active
  @active
end

- (Object) city

Returns the value of attribute city



6
7
8
# File 'lib/suitcase/hotel/location.rb', line 6

def city
  @city
end

- (Object) country

Returns the value of attribute country



6
7
8
# File 'lib/suitcase/hotel/location.rb', line 6

def country
  @country
end

- (Object) country_code

Returns the value of attribute country_code



6
7
8
# File 'lib/suitcase/hotel/location.rb', line 6

def country_code
  @country_code
end

- (Object) destination_id

Returns the value of attribute destination_id



6
7
8
# File 'lib/suitcase/hotel/location.rb', line 6

def destination_id
  @destination_id
end

- (Object) province

Returns the value of attribute province



6
7
8
# File 'lib/suitcase/hotel/location.rb', line 6

def province
  @province
end

- (Object) type

Returns the value of attribute type



6
7
8
# File 'lib/suitcase/hotel/location.rb', line 6

def type
  @type
end

Class Method Details

+ (Object) find(info)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/suitcase/hotel/location.rb', line 15

def find(info)
  params = {}
  [:city, :address].each do |dup|
    params[dup] = info[dup] if info[dup]
  end
  params[:destinationString] = info[:destination_string]
  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

+ (Object) handle_errors(info)

Raises:



37
38
39
40
41
42
43
# File 'lib/suitcase/hotel/location.rb', line 37

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

+ (Object) parse(raw)



31
32
33
34
35
# File 'lib/suitcase/hotel/location.rb', line 31

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