Class: Elong::API::Static::Hotel
- Inherits:
-
Object
- Object
- Elong::API::Static::Hotel
- Defined in:
- lib/elong/api/static.rb,
lib/elong/api/static/hotel.rb
Class Method Summary collapse
-
.brands ⇒ Hash
Get the brands of hotel.
-
.detail(hotel_id) ⇒ Hash
Get the detail info of one hotel.
-
.geo ⇒ Hash
List All Geo Data.
-
.list(status = nil) ⇒ Array
List all hotel 8-bit ids.
Class Method Details
.brands ⇒ Hash
Get the brands of hotel
57 58 59 60 |
# File 'lib/elong/api/static.rb', line 57 def brands xml = open "http://api.elong.com/xml/v2.0/hotel/brand_cn.xml" Hash.from_xml(xml)['ArrayOfHotelBrand']['HotelBrand'] end |
.detail(hotel_id) ⇒ Hash
Get the detail info of one hotel
44 45 46 47 48 49 50 51 52 |
# File 'lib/elong/api/static.rb', line 44 def detail(hotel_id) raise "hotel_id should be String" unless hotel_id.class == String begin xml = open "http://api.elong.com/xml/v2.0/hotel/cn/#{hotel_id[-2,2]}/#{hotel_id}.xml" rescue OpenURI::HTTPError return false end Hash.from_xml(xml)['Hotel']['Detail'] end |
.geo ⇒ Hash
List All Geo Data
36 37 38 39 |
# File 'lib/elong/api/static.rb', line 36 def geo xml = open "http://api.elong.com/xml/v2.0/hotel/geo_cn.xml" Hash.from_xml(xml)['HotelGeos']['HotelGeoList']['HotelGeo'] end |
.list(status = nil) ⇒ Array
List all hotel 8-bit ids
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/elong/api/static.rb', line 22 def list(status = nil) raise "status must be 0 or 1 or nil" unless [0,1,nil].include?status noko = Nokogiri::XML(open('http://api.elong.com/xml/v2.0/hotel/hotellist.xml')) results = noko.xpath("/HotelIndex/Hotels/Hotel") if status results.map{|node|node["HotelId"] if node['Status'] == status.to_s}.delete_if{|node|node.nil?} else results.map{|node|node["HotelId"]} end end |