elong 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5af2fbccbef85118ae749fc2648e699d5deeb5f3
4
- data.tar.gz: 51aec4fb8d9373ce93c26e13d4167e570b4ce37a
3
+ metadata.gz: b4e5ee92e88658bfc0ce4d142f39ca9dd06124ae
4
+ data.tar.gz: 8e7fbc013cd32a72e7325cf0f3b302aecee87672
5
5
  SHA512:
6
- metadata.gz: 4d8345090f842c032d13085f489232d154fb66b6b0d49381c554c9849e51b8ac6c6e7b466b30de6a2caff3861becf78ae41d6bb8b64d66bb352bb82c1b7923d4
7
- data.tar.gz: 0f279d8fa2aeaba614f949f52391c90eab7bab9d0250c0e25fa0897cd534154516558f005b5a1b403dda6527c14a27a59e5b2b0e63779da9e69f5be6d5ded762
6
+ metadata.gz: e441a605e07cd90a232f1bd3054941867fabf53c6d5077da6c4f932816f48b5a595619df4b5abddf22ea3ab1825eb616a82df517bd77cc08263cf95c75c6c999
7
+ data.tar.gz: 34714491e8f801c24ff09185699f9c15bc9359806dc5534637958aa7a740d1cdd1b04176d732e9f62b6219472eb7a03ccd5fd93d3dbe16692b593b360b6dbf5d
data/.gitignore CHANGED
@@ -16,3 +16,5 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+
20
+ .DS_Store
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Elong
2
2
 
3
- 艺龙(elong.com) OpenAPI for Ruby
3
+ [艺龙](http://www.elong.com) [OpenAPI](http://open.elong.com/) for Ruby
4
4
 
5
5
  ## 安装
6
6
 
@@ -26,7 +26,7 @@
26
26
 
27
27
  client = Elong::Client.new(user, appKey, secretKey)
28
28
 
29
- ### API 调用
29
+ ### 动态数据 API 调用
30
30
 
31
31
  #### 查看国内酒店指定时间段北京(Id:0101)地区的房源信息
32
32
 
@@ -43,6 +43,28 @@
43
43
 
44
44
  > 无需在意文档中某些接口必须调用 `https` 协议的接口,代码已经帮你处理好了,调用就行了!
45
45
 
46
+ ### 静态数据 API 调用
47
+
48
+ #### 列出所有国内酒店hotel_id
49
+
50
+ ```ruby
51
+ hotel_ids = Elong::API::Static::Hotel.list #所有酒店
52
+ hotel_ids = Elong::API::Static::Hotel.list(0) #所有有效酒店
53
+ hotel_ids = Elong::API::Static::Hotel.list(1) #所有无效酒店
54
+ ```
55
+
56
+ #### 读取某一条酒店详细信息
57
+
58
+ ```ruby
59
+ detail = Elong::API::Static::Hotel.detail(hotel_id)
60
+ ```
61
+
62
+ #### 列出所有地理位置信息
63
+
64
+ ```ruby
65
+ geo_data = Elong::API::Static::Hotel.geo
66
+ ```
67
+
46
68
 
47
69
  ### API 返回
48
70
 
@@ -54,6 +76,13 @@
54
76
 
55
77
  puts response.code
56
78
 
79
+ > 调用正常返回 '0',错误情况看下面
80
+
81
+ #### 查看错误信息
82
+
83
+ puts response.code
84
+ puts response.error
85
+
57
86
  #### 查看返回的数据内容
58
87
 
59
88
  puts response
@@ -78,7 +107,7 @@
78
107
  ## 测试用例
79
108
 
80
109
  使用中对代码有疑惑,请浏览源码中 spec 中的代码,里面包含了大量的代码用例。
81
- 填写 `spec/spec_hepler.rb` 中必要的 API 设定可以爬通完整的测试用例。
110
+ 填写 `spec/spec_hepler.rb` 中必要的 API 设定可以跑通完整的测试用例。
82
111
 
83
112
 
84
113
  ## 贡献代码
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "rest-client"
25
25
  spec.add_dependency 'multi_json'
26
26
  spec.add_dependency 'multi_xml'
27
+ spec.add_dependency 'activesupport'
28
+ spec.add_dependency 'nokogiri'
27
29
  end
@@ -7,3 +7,5 @@ require "elong/api/base"
7
7
  require "elong/api/hotel"
8
8
  require "elong/api/ghotel"
9
9
  require "elong/api/common"
10
+
11
+ require "elong/api/static"
@@ -0,0 +1,65 @@
1
+ # require "elong/api/static/hotel"
2
+ require 'open-uri'
3
+ require 'active_support/core_ext/hash'
4
+ require 'nokogiri'
5
+ module Elong
6
+ module API
7
+ module Static
8
+ end
9
+ end
10
+ end
11
+
12
+ module Elong
13
+ module API
14
+ module Static
15
+ class Hotel
16
+ # Elong Hotel Static API Class
17
+ class << self
18
+
19
+ # List all hotel 8-bit ids
20
+ #
21
+ # @return [Array]
22
+ def list(status = nil)
23
+ raise "status must be 0 or 1 or nil" unless [0,1,nil].include?status
24
+ noko = Nokogiri::XML(open('http://api.elong.com/xml/v2.0/hotel/hotellist.xml'))
25
+ results = noko.xpath("/HotelIndex/Hotels/Hotel")
26
+ if status
27
+ results.map{|node|node["HotelId"] if node['Status'] == status.to_s}.delete_if{|node|node.nil?}
28
+ else
29
+ results.map{|node|node["HotelId"]}
30
+ end
31
+ end
32
+
33
+ # List All Geo Data
34
+ #
35
+ # @return [Hash]
36
+ def geo
37
+ xml = open "http://api.elong.com/xml/v2.0/hotel/geo_cn.xml"
38
+ Hash.from_xml(xml)['HotelGeos']['HotelGeoList']['HotelGeo']
39
+ end
40
+
41
+ # Get the detail info of one hotel
42
+ #
43
+ # @return [Hash]
44
+ def detail(hotel_id)
45
+ raise "hotel_id should be String" unless hotel_id.class == String
46
+ begin
47
+ xml = open "http://api.elong.com/xml/v2.0/hotel/cn/#{hotel_id[-2,2]}/#{hotel_id}.xml"
48
+ rescue OpenURI::HTTPError
49
+ return false
50
+ end
51
+ Hash.from_xml(xml)['Hotel']['Detail']
52
+ end
53
+
54
+ # Get the brands of hotel
55
+ #
56
+ # @return [Hash]
57
+ def brands
58
+ xml = open "http://api.elong.com/xml/v2.0/hotel/brand_cn.xml"
59
+ Hash.from_xml(xml)['ArrayOfHotelBrand']['HotelBrand']
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,55 @@
1
+
2
+ module Elong
3
+ module API
4
+ module Static
5
+ class Hotel
6
+ # Elong Hotel Static API Class
7
+ class << self
8
+
9
+ # List all hotel 8-bit ids
10
+ #
11
+ # @return [Array]
12
+ def list(status = nil)
13
+ raise "status must be 0 or 1 or nil" unless [0,1,nil].include?status
14
+ noko = Nokogiri::XML(open('http://api.elong.com/xml/v2.0/hotel/hotellist.xml'))
15
+ results = noko.xpath("/HotelIndex/Hotels/Hotel")
16
+ if status
17
+ results.map{|node|node["HotelId"] if node['Status'] == status.to_s}.delete_if{|node|node.nil?}
18
+ else
19
+ results.map{|node|node["HotelId"]}
20
+ end
21
+ end
22
+
23
+ # List All Geo Data
24
+ #
25
+ # @return [Hash]
26
+ def geo
27
+ xml = open "http://api.elong.com/xml/v2.0/hotel/geo_cn.xml"
28
+ Hash.from_xml(xml)['HotelGeos']['HotelGeoList']['HotelGeo']
29
+ end
30
+
31
+ # Get the detail info of one hotel
32
+ #
33
+ # @return [Hash]
34
+ def detail(hotel_id)
35
+ raise "hotel_id should be String" unless hotel_id.class == String
36
+ begin
37
+ xml = open "http://api.elong.com/xml/v2.0/hotel/cn/#{hotel_id[-2,2]}/#{hotel_id}.xml"
38
+ rescue OpenURI::HTTPError
39
+ return false
40
+ end
41
+ Hash.from_xml(xml)['Hotel']['Detail']
42
+ end
43
+
44
+ # Get the brands of hotel
45
+ #
46
+ # @return [Hash]
47
+ def brands
48
+ xml = open "http://api.elong.com/xml/v2.0/hotel/brand_cn.xml"
49
+ Hash.from_xml(xml)['ArrayOfHotelBrand']['HotelBrand']
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module Elong
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Elong::API::Static::Hotel,"#list" do
4
+ let(:list) {Elong::API::Static::Hotel.list()}
5
+ let(:list0) {Elong::API::Static::Hotel.list(0)}
6
+ let(:list1) {Elong::API::Static::Hotel.list(1)}
7
+ it "should return array of all hotel ids which size is bigger than 70000 " do
8
+ list_class = list.class
9
+ list_class.should == Array
10
+ list_size = list.size
11
+ list_size.should > 70000
12
+ list_first = list.first
13
+ list_first.should =~ /[0-9]{8}/
14
+ end
15
+ it "should return array of all hotel ids which size is between 45000 and 70000" do
16
+ list0_class = list0.class
17
+ list0_class.should == Array
18
+ list0_size = list0.size
19
+ (45000..70000).should cover list0_size
20
+ list0_first = list0.first
21
+ list0_first.should =~ /[0-9]{8}/
22
+ end
23
+ it "should return array of all hotel ids which size is between 20000 and 45000" do
24
+ list1_class = list1.class
25
+ list1_class.should == Array
26
+ list1_size = list1.size
27
+ (20000..45000).should cover list1_size
28
+ list1_first = list1.first
29
+ list1_first.should =~ /[0-9]{8}/
30
+ end
31
+ end
32
+ __END__
33
+ describe Elong::API::Static::Hotel,"#brands" do
34
+ let(:brands) {Elong::API::Static::Hotel.brands}
35
+ it "should return array of brands which size is bigger than 50" do
36
+ brands.class.should == Array
37
+ brands.first.should have_key 'BrandId'
38
+ end
39
+ end
40
+
41
+
42
+
43
+ describe Elong::API::Static::Hotel,"#detail" do
44
+ let(:detail){Elong::API::Static::Hotel.detail('01667007')}
45
+ it "should get at least hotel name from hotel id 01667007" do
46
+ detail.class.should == Hash
47
+ detail.should have_key 'Name'
48
+ detail['Name'].class.should == String
49
+ detail['Name'].size.should > 0
50
+ end
51
+ end
52
+
53
+ describe Elong::API::Static::Hotel,"#geo" do
54
+ let(:geo){Elong::API::Static::Hotel.geo}
55
+ it "should get an Array " do
56
+ geo.class.should == Array
57
+ end
58
+ it "should get at least CityName from the first geo data" do
59
+ geo.first.should have_key 'CityName'
60
+ end
61
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elong
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - icyleaf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-08 00:00:00.000000000 Z
11
+ date: 2013-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: Elong OpenAPI wrapper
84
112
  email:
85
113
  - icyleaf.cn@gmail.com
@@ -108,11 +136,14 @@ files:
108
136
  - lib/elong/api/hotel/data.rb
109
137
  - lib/elong/api/hotel/incr.rb
110
138
  - lib/elong/api/hotel/order.rb
139
+ - lib/elong/api/static.rb
140
+ - lib/elong/api/static/hotel.rb
111
141
  - lib/elong/client.rb
112
142
  - lib/elong/request.rb
113
143
  - lib/elong/response.rb
114
144
  - lib/elong/version.rb
115
145
  - spec/elong/api/elong_api_hotel_spec.rb
146
+ - spec/elong/api/static/hotel_spec.rb
116
147
  - spec/elong/elong_client_spec.rb
117
148
  - spec/elong/elong_request_spec.rb
118
149
  - spec/elong/elong_response_spec.rb
@@ -137,12 +168,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
168
  version: '0'
138
169
  requirements: []
139
170
  rubyforge_project:
140
- rubygems_version: 2.0.6
171
+ rubygems_version: 2.0.3
141
172
  signing_key:
142
173
  specification_version: 4
143
174
  summary: Elong OpenAPI wrapper
144
175
  test_files:
145
176
  - spec/elong/api/elong_api_hotel_spec.rb
177
+ - spec/elong/api/static/hotel_spec.rb
146
178
  - spec/elong/elong_client_spec.rb
147
179
  - spec/elong/elong_request_spec.rb
148
180
  - spec/elong/elong_response_spec.rb