elong 0.2.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 +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +90 -0
- data/Rakefile +8 -0
- data/elong.gemspec +27 -0
- data/lib/elong.rb +9 -0
- data/lib/elong/api/base.rb +36 -0
- data/lib/elong/api/common.rb +10 -0
- data/lib/elong/api/common/core.rb +17 -0
- data/lib/elong/api/common/creditcard.rb +20 -0
- data/lib/elong/api/ghotel.rb +11 -0
- data/lib/elong/api/ghotel/core.rb +24 -0
- data/lib/elong/api/ghotel/order.rb +54 -0
- data/lib/elong/api/ghotel/search.rb +31 -0
- data/lib/elong/api/hotel.rb +12 -0
- data/lib/elong/api/hotel/core.rb +46 -0
- data/lib/elong/api/hotel/data.rb +45 -0
- data/lib/elong/api/hotel/incr.rb +57 -0
- data/lib/elong/api/hotel/order.rb +86 -0
- data/lib/elong/client.rb +44 -0
- data/lib/elong/request.rb +94 -0
- data/lib/elong/response.rb +74 -0
- data/lib/elong/version.rb +3 -0
- data/spec/elong/api/elong_api_hotel_spec.rb +101 -0
- data/spec/elong/elong_client_spec.rb +40 -0
- data/spec/elong/elong_request_spec.rb +204 -0
- data/spec/elong/elong_response_spec.rb +14 -0
- data/spec/spec_helper.rb +22 -0
- metadata +149 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Elong::Client do
|
5
|
+
subject { @client }
|
6
|
+
|
7
|
+
describe '#初始化' do
|
8
|
+
it '应该允许 client 被实例化' do
|
9
|
+
subject.should be_instance_of Elong::Client
|
10
|
+
end
|
11
|
+
|
12
|
+
it '应该允许 request 被实例化' do
|
13
|
+
subject.request.should_not be_nil
|
14
|
+
subject.request.should be_instance_of Elong::Request
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#调用方法' do
|
19
|
+
context '执行 hotel 方法' do
|
20
|
+
let(:hotel) { subject.hotel }
|
21
|
+
it "必须继承自 Elong::API::Hotel" do
|
22
|
+
hotel.should be_instance_of Elong::API::Hotel::Core
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '执行 ghotel 方法' do
|
27
|
+
let(:ghotel) { subject.ghotel }
|
28
|
+
it "必须继承自 Elong::API::GHotel" do
|
29
|
+
ghotel.should be_instance_of Elong::API::GHotel::Core
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context '执行 common 方法' do
|
34
|
+
let(:common) { subject.common }
|
35
|
+
it "必须继承自 Elong::API::Common" do
|
36
|
+
common.should be_instance_of Elong::API::Common::Core
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Elong::Request do
|
5
|
+
subject { @client.request }
|
6
|
+
|
7
|
+
let(:departure_date) { Time.now }
|
8
|
+
let(:sample_api) {'hotel.list'}
|
9
|
+
let(:sample_data) do
|
10
|
+
params = {
|
11
|
+
'CityId' => @cityId,
|
12
|
+
'ArrivalDate' => @tomorrow,
|
13
|
+
'DepartureDate' => @theDayAfterTomorrow,
|
14
|
+
'PageSize' => 1
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
context '#初始化' do
|
19
|
+
it 'user 不能为空' do
|
20
|
+
subject.user.should_not be_nil
|
21
|
+
subject.user.should_not be_empty
|
22
|
+
subject.user.should eq @user
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'appKey 不能为空' do
|
26
|
+
subject.appKey.should_not be_nil
|
27
|
+
subject.appKey.should_not be_empty
|
28
|
+
#subject.appKey.should eq @appKey
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'secretKey 不能为空' do
|
32
|
+
subject.secretKey.should_not be_nil
|
33
|
+
subject.secretKey.should_not be_empty
|
34
|
+
subject.secretKey.should eq @secretKey
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'domain 不能为空' do
|
38
|
+
subject.domain.should_not be_nil
|
39
|
+
subject.domain.should_not be_empty
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'version 不能为空' do
|
43
|
+
subject.version.should_not be_nil
|
44
|
+
subject.version.should_not be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'local 不能为空' do
|
48
|
+
subject.local.should_not be_nil
|
49
|
+
subject.local.should_not be_empty
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'format 不能为空' do
|
53
|
+
subject.format.should_not be_nil
|
54
|
+
subject.format.should_not be_empty
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'timestamp 默认为空' do
|
58
|
+
subject.timestamp.should be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'signature 默认为空' do
|
62
|
+
subject.signature.should be_nil
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'data 默认为空' do
|
66
|
+
subject.data.should be_nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context '#验证数据' do
|
71
|
+
it '允许修改 version 的值' do
|
72
|
+
subject.version = '1.0'
|
73
|
+
subject.version.should eq('1.0')
|
74
|
+
|
75
|
+
subject.version = '1.1'
|
76
|
+
subject.version.should eq('1.1')
|
77
|
+
|
78
|
+
subject.version = '2.0'
|
79
|
+
subject.version.should eq('2.0')
|
80
|
+
end
|
81
|
+
|
82
|
+
it '允许修改 local 的值' do
|
83
|
+
subject.local = 'en_US'
|
84
|
+
subject.local.should eq('en_US')
|
85
|
+
|
86
|
+
subject.local = 'zh_CN'
|
87
|
+
subject.local.should eq('zh_CN')
|
88
|
+
end
|
89
|
+
|
90
|
+
it '允许 format 的值是 xml 或 json' do
|
91
|
+
subject.format.should match(/(json|xml)/i)
|
92
|
+
end
|
93
|
+
|
94
|
+
it '可以修改 format 的值' do
|
95
|
+
subject.format = 'xml'
|
96
|
+
subject.format.should eq('xml')
|
97
|
+
|
98
|
+
subject.format = 'rss'
|
99
|
+
subject.format.should eq('rss')
|
100
|
+
|
101
|
+
subject.format = 'json'
|
102
|
+
subject.format.should eq('json')
|
103
|
+
end
|
104
|
+
|
105
|
+
it '可以修改 https 的值' do
|
106
|
+
subject.https = true
|
107
|
+
subject.https.should be_true
|
108
|
+
|
109
|
+
subject.https = false
|
110
|
+
subject.https.should be_false
|
111
|
+
end
|
112
|
+
|
113
|
+
it '可以生成 timestamp 的值' do
|
114
|
+
timestamp1 = subject.generateTimestamp
|
115
|
+
subject.timestamp.should eq(timestamp1)
|
116
|
+
|
117
|
+
sleep(1)
|
118
|
+
|
119
|
+
timestamp2 = subject.generateTimestamp
|
120
|
+
subject.timestamp.should eq(timestamp2)
|
121
|
+
|
122
|
+
timestamp2.to_i.should > timestamp1.to_i
|
123
|
+
end
|
124
|
+
|
125
|
+
it '必须与 data 数据吻合' do
|
126
|
+
jsonData = subject.buildData(sample_data)
|
127
|
+
parsedData = JSON.parse(jsonData)
|
128
|
+
|
129
|
+
parsedData.should have_key('Version')
|
130
|
+
parsedData['Version'].should eq(subject.version)
|
131
|
+
|
132
|
+
parsedData.should have_key('Local')
|
133
|
+
parsedData['Local'].should eq(subject.local)
|
134
|
+
|
135
|
+
parsedData.should have_key('Request')
|
136
|
+
parsedData['Request'].size.should == sample_data.size
|
137
|
+
parsedData['Request']['CityId'].should match(/\d+/i)
|
138
|
+
parsedData['Request']['ArrivalDate'].should match(/\d{4}-\d{2}-\d{2}/i)
|
139
|
+
parsedData['Request']['DepartureDate'].should match(/\d{4}-\d{2}-\d{2}/i)
|
140
|
+
end
|
141
|
+
|
142
|
+
it '可以正常生成 signature 数据' do
|
143
|
+
subject.generateTimestamp
|
144
|
+
subject.buildData(sample_data)
|
145
|
+
subject.generateSignature
|
146
|
+
|
147
|
+
subject.signature.should_not be_nil
|
148
|
+
subject.signature.should_not be_empty
|
149
|
+
subject.signature.should have(32).characters
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context '#执行方法' do
|
154
|
+
describe '.execute' do
|
155
|
+
|
156
|
+
it '应该请求的 https 协议接口地址' do
|
157
|
+
subject.https = true
|
158
|
+
res = subject.execute(sample_api, sample_data)
|
159
|
+
subject.https.should be_true
|
160
|
+
|
161
|
+
res = subject.execute(sample_api, sample_data, https=true)
|
162
|
+
subject.https.should be_true
|
163
|
+
end
|
164
|
+
|
165
|
+
it '应该请求的 http 协议接口地址' do
|
166
|
+
subject.https = false
|
167
|
+
res = subject.execute(sample_api, sample_data)
|
168
|
+
subject.https.should be_false
|
169
|
+
|
170
|
+
res = subject.execute(sample_api, sample_data, https=false)
|
171
|
+
subject.https.should be_false
|
172
|
+
end
|
173
|
+
|
174
|
+
it '应该返回 200 状态码' do
|
175
|
+
res = subject.execute(sample_api, sample_data)
|
176
|
+
res.status.should eq(200)
|
177
|
+
end
|
178
|
+
|
179
|
+
it '应该返回 200 状态码' do
|
180
|
+
res = subject.execute(sample_api, sample_data)
|
181
|
+
res.status.should eq(200)
|
182
|
+
end
|
183
|
+
|
184
|
+
it '应该返回 json 数据并正常解析' do
|
185
|
+
subject.format = 'json'
|
186
|
+
|
187
|
+
res = subject.execute(sample_api, sample_data)
|
188
|
+
res.status.should eq(200)
|
189
|
+
|
190
|
+
res.should be_json
|
191
|
+
res.code.should_not be_empty
|
192
|
+
end
|
193
|
+
|
194
|
+
it '应该能够返回 xml 数据并正常解析' do
|
195
|
+
subject.format = 'xml'
|
196
|
+
res = subject.execute(sample_api, sample_data)
|
197
|
+
res.status.should eq(200)
|
198
|
+
|
199
|
+
res.should be_xml
|
200
|
+
res.code.should_not be_empty
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Elong::Response do
|
5
|
+
subject { @client.hotel.list(CityId:'0101', ArrivalDate:'', DepartureDate:'', PageSize:1) }
|
6
|
+
|
7
|
+
describe '#初始化' do
|
8
|
+
it '测试类的继承' do
|
9
|
+
subject.should be_instance_of Elong::Response
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'elong'
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'rexml/document'
|
5
|
+
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.before :all do
|
9
|
+
@user = ''
|
10
|
+
@appKey = ''
|
11
|
+
@secretKey = ''
|
12
|
+
|
13
|
+
@today = Time.now.to_i
|
14
|
+
@tomorrow = DateTime.strptime((@today + 24*3600).to_s, '%s').to_time.strftime('%Y-%m-%d')
|
15
|
+
@theDayAfterTomorrow = DateTime.strptime((@today + 2*24*3600).to_s, '%s').to_time.strftime('%Y-%m-%d')
|
16
|
+
|
17
|
+
@hotelId = '50101002'
|
18
|
+
@cityId = '0101'
|
19
|
+
|
20
|
+
@client = Elong::Client.new(@user, @appKey, @secretKey)
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elong
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- icyleaf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: multi_xml
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Elong OpenAPI wrapper
|
84
|
+
email:
|
85
|
+
- icyleaf.cn@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- elong.gemspec
|
97
|
+
- lib/elong.rb
|
98
|
+
- lib/elong/api/base.rb
|
99
|
+
- lib/elong/api/common.rb
|
100
|
+
- lib/elong/api/common/core.rb
|
101
|
+
- lib/elong/api/common/creditcard.rb
|
102
|
+
- lib/elong/api/ghotel.rb
|
103
|
+
- lib/elong/api/ghotel/core.rb
|
104
|
+
- lib/elong/api/ghotel/order.rb
|
105
|
+
- lib/elong/api/ghotel/search.rb
|
106
|
+
- lib/elong/api/hotel.rb
|
107
|
+
- lib/elong/api/hotel/core.rb
|
108
|
+
- lib/elong/api/hotel/data.rb
|
109
|
+
- lib/elong/api/hotel/incr.rb
|
110
|
+
- lib/elong/api/hotel/order.rb
|
111
|
+
- lib/elong/client.rb
|
112
|
+
- lib/elong/request.rb
|
113
|
+
- lib/elong/response.rb
|
114
|
+
- lib/elong/version.rb
|
115
|
+
- spec/elong/api/elong_api_hotel_spec.rb
|
116
|
+
- spec/elong/elong_client_spec.rb
|
117
|
+
- spec/elong/elong_request_spec.rb
|
118
|
+
- spec/elong/elong_response_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
homepage: http://github.com/icyleaf/elong
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.0.6
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Elong OpenAPI wrapper
|
144
|
+
test_files:
|
145
|
+
- spec/elong/api/elong_api_hotel_spec.rb
|
146
|
+
- spec/elong/elong_client_spec.rb
|
147
|
+
- spec/elong/elong_request_spec.rb
|
148
|
+
- spec/elong/elong_response_spec.rb
|
149
|
+
- spec/spec_helper.rb
|