elong 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5af2fbccbef85118ae749fc2648e699d5deeb5f3
|
4
|
+
data.tar.gz: 51aec4fb8d9373ce93c26e13d4167e570b4ce37a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d8345090f842c032d13085f489232d154fb66b6b0d49381c554c9849e51b8ac6c6e7b466b30de6a2caff3861becf78ae41d6bb8b64d66bb352bb82c1b7923d4
|
7
|
+
data.tar.gz: 0f279d8fa2aeaba614f949f52391c90eab7bab9d0250c0e25fa0897cd534154516558f005b5a1b403dda6527c14a27a59e5b2b0e63779da9e69f5be6d5ded762
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 icyleaf
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Elong
|
2
|
+
|
3
|
+
艺龙(elong.com) OpenAPI for Ruby
|
4
|
+
|
5
|
+
## 安装
|
6
|
+
|
7
|
+
在你项目的 `Gemfile` 文件添加下行内容:
|
8
|
+
|
9
|
+
gem 'elong'
|
10
|
+
|
11
|
+
保存后执行:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
或者直接执行下行命令安装:
|
16
|
+
|
17
|
+
$ gem install elong
|
18
|
+
|
19
|
+
## 用法
|
20
|
+
|
21
|
+
### 初始化
|
22
|
+
|
23
|
+
user = ''
|
24
|
+
appKey = ''
|
25
|
+
secretKey = ''
|
26
|
+
|
27
|
+
client = Elong::Client.new(user, appKey, secretKey)
|
28
|
+
|
29
|
+
### API 调用
|
30
|
+
|
31
|
+
#### 查看国内酒店指定时间段北京(Id:0101)地区的房源信息
|
32
|
+
|
33
|
+
respone = client.house.list(CityId: '0101',
|
34
|
+
ArrivalDate: '2013-10-1',
|
35
|
+
DepartureDate: '2013-10-7',
|
36
|
+
PageSize: 20))
|
37
|
+
|
38
|
+
#### 取消国内酒店指定 id 的订单
|
39
|
+
|
40
|
+
response = client.hotel.order.cancel(OrderId:'237864278346',
|
41
|
+
CancelCode:'对酒店相关条件不满意')
|
42
|
+
|
43
|
+
|
44
|
+
> 无需在意文档中某些接口必须调用 `https` 协议的接口,代码已经帮你处理好了,调用就行了!
|
45
|
+
|
46
|
+
|
47
|
+
### API 返回
|
48
|
+
|
49
|
+
#### 查看 HTTP 状态码
|
50
|
+
|
51
|
+
puts response.status
|
52
|
+
|
53
|
+
#### 查看 OpenAPI 状态码
|
54
|
+
|
55
|
+
puts response.code
|
56
|
+
|
57
|
+
#### 查看返回的数据内容
|
58
|
+
|
59
|
+
puts response
|
60
|
+
puts response.body
|
61
|
+
puts response.to_s
|
62
|
+
|
63
|
+
以上方式均可。
|
64
|
+
|
65
|
+
#### 返回 JSON 结构化数据(基于 [mutli_json](https://github.com/intridea/multi_json))
|
66
|
+
|
67
|
+
jsonData = response.to_json
|
68
|
+
|
69
|
+
#### 返回 XML 解析数据格式(基于 [mutli_xml](https://github.com/sferik/multi_xml))
|
70
|
+
|
71
|
+
xmlDom = response.to_xml
|
72
|
+
|
73
|
+
支持 ox, libxml, nokogiri, rexml 解析器,比如:
|
74
|
+
|
75
|
+
xmlDom = response.to_xml(:nokogiri)
|
76
|
+
|
77
|
+
|
78
|
+
## 测试用例
|
79
|
+
|
80
|
+
使用中对代码有疑惑,请浏览源码中 spec 中的代码,里面包含了大量的代码用例。
|
81
|
+
填写 `spec/spec_hepler.rb` 中必要的 API 设定可以爬通完整的测试用例。
|
82
|
+
|
83
|
+
|
84
|
+
## 贡献代码
|
85
|
+
|
86
|
+
1. Fork 本仓库
|
87
|
+
2. 创建你自己的 feature 分支 (`git checkout -b my-new-feature`)
|
88
|
+
3. 提交你的代码 (`git commit -am 'Add some feature'`)
|
89
|
+
4. 提交你的分支 (`git push origin my-new-feature`)
|
90
|
+
5. 创建一个新的 Pull Request
|
data/Rakefile
ADDED
data/elong.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'elong/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "elong"
|
8
|
+
spec.version = Elong::VERSION
|
9
|
+
spec.authors = ["icyleaf"]
|
10
|
+
spec.email = ["icyleaf.cn@gmail.com"]
|
11
|
+
spec.description = %q{Elong OpenAPI wrapper}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = "http://github.com/icyleaf/elong"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "rest-client"
|
25
|
+
spec.add_dependency 'multi_json'
|
26
|
+
spec.add_dependency 'multi_xml'
|
27
|
+
end
|
data/lib/elong.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Elong
|
2
|
+
module API
|
3
|
+
# Elong API Base Class
|
4
|
+
class Base
|
5
|
+
|
6
|
+
# Initializes a API Base instance
|
7
|
+
#
|
8
|
+
# @params [Elong::Client] client an instance of Elong::Client
|
9
|
+
# @return [ELong::API::Base]
|
10
|
+
def initialize(client)
|
11
|
+
@client = client
|
12
|
+
end
|
13
|
+
|
14
|
+
# Start a new http request
|
15
|
+
#
|
16
|
+
# @params [String] method the method of called in the instance class
|
17
|
+
# @params [Hash] params the params of called api
|
18
|
+
# @return [Elong::Response]
|
19
|
+
def request(method, params)
|
20
|
+
@client.request.execute(self.buildAPI(method), params)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Build api url with class & methods
|
24
|
+
#
|
25
|
+
# @params [String] method the method of called in the instance class
|
26
|
+
# @return [String]
|
27
|
+
def buildAPI(method)
|
28
|
+
className = self.class.name.split('::').map{|n|
|
29
|
+
n.downcase if ! ['elong', 'api', 'core'].include?n.downcase
|
30
|
+
}.compact.reject{|r| r.empty? if r.class == String}.join('.')
|
31
|
+
methodName = method.downcase
|
32
|
+
return "#{className}.#{methodName}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Elong
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
# Elong Common Core API Class
|
5
|
+
class Core < Elong::API::Base
|
6
|
+
|
7
|
+
# The Creditcard seciont
|
8
|
+
#
|
9
|
+
# @return [Elong::API::Common::Creditcard]
|
10
|
+
def creditcard
|
11
|
+
@creditcard ||= Elong::API::Common::Creditcard.new(@client)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Elong
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
# Elong Creditcard of Common API Class
|
5
|
+
class Creditcard < Elong::API::Base
|
6
|
+
|
7
|
+
# Validate creditcard if or not the CVV must be input
|
8
|
+
#
|
9
|
+
# `https` request
|
10
|
+
#
|
11
|
+
# @params [Hash] params api params
|
12
|
+
# @return [Elong::Response]
|
13
|
+
def validate(params={})
|
14
|
+
self.request(__method__, params, https=true)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Elong
|
2
|
+
module API
|
3
|
+
module GHotel
|
4
|
+
# Elong Global Hotel Core API Class
|
5
|
+
class Core < Elong::API::Base
|
6
|
+
|
7
|
+
# The Global Hotel Search section
|
8
|
+
#
|
9
|
+
# @return [Elong::API::GHotel::Search]
|
10
|
+
def search
|
11
|
+
@search ||= Elong::API::GHotel::Search.new(@client)
|
12
|
+
end
|
13
|
+
|
14
|
+
# The Global Hotel Order section
|
15
|
+
#
|
16
|
+
# @return [Elong::API::GHotel::Order]
|
17
|
+
def order
|
18
|
+
@order ||= Elong::API::GHotel::Order.new(@client)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Elong
|
2
|
+
module API
|
3
|
+
module GHotel
|
4
|
+
# Elong Global Hotel Order API Class
|
5
|
+
class Order < Elong::API::Base
|
6
|
+
|
7
|
+
# The Global Hotel List Order API
|
8
|
+
#
|
9
|
+
# @params [Hash] params api params
|
10
|
+
# @return [Elong::Response]
|
11
|
+
def list(params={})
|
12
|
+
self.request(__method__, params)
|
13
|
+
end
|
14
|
+
|
15
|
+
# The Hotel Order Detail API
|
16
|
+
#
|
17
|
+
# @params [Hash] params api params
|
18
|
+
# @return [Elong::Response]
|
19
|
+
def detail(params={})
|
20
|
+
self.request(__method__, params)
|
21
|
+
end
|
22
|
+
|
23
|
+
# The Hotel Create Order API
|
24
|
+
#
|
25
|
+
# @todo MUST `https` request
|
26
|
+
#
|
27
|
+
# @params [Hash] params api params
|
28
|
+
# @return [Elong::Response]
|
29
|
+
def create(params={})
|
30
|
+
self.request(__method__, params)
|
31
|
+
end
|
32
|
+
|
33
|
+
# The Hotel Cancel Order API
|
34
|
+
#
|
35
|
+
# @params [Hash] params api params
|
36
|
+
# @return [Elong::Response]
|
37
|
+
def cancel(params={})
|
38
|
+
self.request(__method__, params)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# The Hotel Update Order API
|
43
|
+
# ** Its not works in Hongkong, Macao, Taiwan **
|
44
|
+
#
|
45
|
+
# @params [Hash] params api params
|
46
|
+
# @return [Elong::Response]
|
47
|
+
def update(params={})
|
48
|
+
self.request(__method__, params)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Elong
|
2
|
+
module API
|
3
|
+
module GHotel
|
4
|
+
# Elong Global Hotel Search API Class
|
5
|
+
class Search < Elong::API::Base
|
6
|
+
|
7
|
+
# Search and list globalehotel data
|
8
|
+
#
|
9
|
+
# @return [Elong::Response]
|
10
|
+
def list(params={})
|
11
|
+
self.request(__method__, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
# View hotel details data
|
15
|
+
#
|
16
|
+
# @return [Elong::Response]
|
17
|
+
def detail(params={})
|
18
|
+
self.request(__method__, params)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Check hotel room status(type, available numbers)
|
22
|
+
#
|
23
|
+
# @return [Elong::Response]
|
24
|
+
def room(params={})
|
25
|
+
self.request(__method__, params)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Elong
|
2
|
+
module API
|
3
|
+
module Hotel
|
4
|
+
# Elong Hotel Core API Class
|
5
|
+
class Core < Elong::API::Base
|
6
|
+
|
7
|
+
# List hotel data for recent 90 days data.
|
8
|
+
# the result will be cacahed about 10 mins
|
9
|
+
#
|
10
|
+
# @return [Elong::Response]
|
11
|
+
def list(params={})
|
12
|
+
self.request(__method__, params)
|
13
|
+
end
|
14
|
+
|
15
|
+
# View hotel details data
|
16
|
+
#
|
17
|
+
# @return [Elong::Response]
|
18
|
+
def detail(params={})
|
19
|
+
self.request(__method__, params)
|
20
|
+
end
|
21
|
+
|
22
|
+
# The Hotel Data section
|
23
|
+
#
|
24
|
+
# @return [Elong::API::Hotel::Data]
|
25
|
+
def data
|
26
|
+
@data ||= Elong::API::Hotel::Data.new(@client)
|
27
|
+
end
|
28
|
+
|
29
|
+
# The Hotel Order section
|
30
|
+
#
|
31
|
+
# @return [Elong::API::Hotel::Order]
|
32
|
+
def order
|
33
|
+
@order ||= Elong::API::Hotel::Order.new(@client)
|
34
|
+
end
|
35
|
+
|
36
|
+
# The Hotel Incr section
|
37
|
+
#
|
38
|
+
# @return [Elong::API::Hotel::Incr]
|
39
|
+
def incr
|
40
|
+
@incr ||= Elong::API::Hotel::Incr.new(@client)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|