Class: Suitcase::Hotel

Inherits:
Object
  • Object
show all
Defined in:
lib/suitcase/hotel/hotel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#airport_codeObject

Returns the value of attribute airport_code.



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

def airport_code
  @airport_code
end

#cityObject

Returns the value of attribute city.



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

def city
  @city
end

#confidence_ratingObject

Returns the value of attribute confidence_rating.



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

def confidence_rating
  @confidence_rating
end

#countryObject

Returns the value of attribute country.



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

def country
  @country
end

#currency_codeObject

Returns the value of attribute currency_code.



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

def currency_code
  @currency_code
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#high_rateObject

Returns the value of attribute high_rate.



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

def high_rate
  @high_rate
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#latitudeObject

Returns the value of attribute latitude.



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

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



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

def longitude
  @longitude
end

#low_rateObject

Returns the value of attribute low_rate.



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

def low_rate
  @low_rate
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#postal_codeObject

Returns the value of attribute postal_code.



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

def postal_code
  @postal_code
end

#ratingObject

Returns the value of attribute rating.



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

def rating
  @rating
end

#tripadvisor_ratingObject

Returns the value of attribute tripadvisor_rating.



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

def tripadvisor_rating
  @tripadvisor_rating
end

Class Method Details

.find(hash) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/suitcase/hotel/hotel.rb', line 10

def self.find(hash)
  hotels = []
  json = JSON.parse Net::HTTP.get_response(URI.parse(URI.escape("http://api.ean.com/ean-services/rs/hotel/v3/list?apiKey=#{Suitcase::Hotel::API_KEY}&city=#{hash[:near]}&numberOfResults=#{hash[:results]}"))).body
  if json["HotelListResponse"]["HotelList"]
    json["HotelListResponse"]["HotelList"]["HotelSummary"].each do |hotel_data|
      h = Hotel.new
      h.id = hotel_data["hotelId"]
      h.name = hotel_data["name"]
      h.address = hotel_data["address1"]
      h.city = hotel_data["city"]
      h.postal_code = hotel_data["postalCode"]
      h.country = COUNTRY_CODES[hotel_data["countryCode"]]
      h.airport_code = hotel_data["airportCode"]
      h.rating = hotel_data["hotelRating"]
      h.confidence_rating = hotel_data["confidenceRating"]
      h.tripadvisor_rating = hotel_data["tripAdvisorRating"]
      h.currency_code = hotel_data["rateCurrencyCode"]
      h.latitude = hotel_data["latitude"]
      h.longitude = hotel_data["longitude"]
      h.high_rate = hotel_data["highRate"]
      h.low_rate = hotel_data["lowRate"]
      hotels.push(h)
    end
    hotels[0..hash[:results]-1]
  else
    if json["HotelListResponse"]["EanWsError"]
      raise "An error occured. Check data."
    end
  end
end

Instance Method Details

#complete_addressObject



45
46
47
# File 'lib/suitcase/hotel/hotel.rb', line 45

def complete_address
  address + " " + city + ", " + country + " " + postal_code
end

#geolocationObject



41
42
43
# File 'lib/suitcase/hotel/hotel.rb', line 41

def geolocation
  latitude + ", " + longitude
end