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 +4 -4
- data/.gitignore +2 -0
- data/README.md +32 -3
- data/elong.gemspec +2 -0
- data/lib/elong.rb +2 -0
- data/lib/elong/api/static.rb +65 -0
- data/lib/elong/api/static/hotel.rb +55 -0
- data/lib/elong/version.rb +1 -1
- data/spec/elong/api/static/hotel_spec.rb +61 -0
- metadata +35 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4e5ee92e88658bfc0ce4d142f39ca9dd06124ae
|
4
|
+
data.tar.gz: 8e7fbc013cd32a72e7325cf0f3b302aecee87672
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e441a605e07cd90a232f1bd3054941867fabf53c6d5077da6c4f932816f48b5a595619df4b5abddf22ea3ab1825eb616a82df517bd77cc08263cf95c75c6c999
|
7
|
+
data.tar.gz: 34714491e8f801c24ff09185699f9c15bc9359806dc5534637958aa7a740d1cdd1b04176d732e9f62b6219472eb7a03ccd5fd93d3dbe16692b593b360b6dbf5d
|
data/.gitignore
CHANGED
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
|
## 贡献代码
|
data/elong.gemspec
CHANGED
data/lib/elong.rb
CHANGED
@@ -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
|
data/lib/elong/version.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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
|