ly-hotel 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +1 -1
- data/README.md +1 -6
- data/lib/ly/hotel.rb +34 -87
- data/lib/ly/hotel/version.rb +2 -2
- data/ly-hotel.gemspec +6 -7
- metadata +11 -19
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dec119f6636cebb416ad71f2400949ec8cb8700b
|
4
|
+
data.tar.gz: 71cd2fd95772dbc6ad4a74222406036984f77758
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 778303d1c3849082044a551a1e50f5bdd2986ea61cbe30510d30a675e79cd65085ccea84638fac007937ac57fe099cb5d1b7366e9b137a5cf4fdd28dcc3d1e2b
|
7
|
+
data.tar.gz: bba0640eb8ab946c47fb25e1d1eb08ebc8c188323c33caba6a055d175478b2e5fdc64f493635de3fa9db97e03d88bf6675b855766dc2d1e0efd72346021cc049
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -32,10 +32,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/krzfyx8g/ly-hotel.
|
36
|
-
|
37
|
-
|
38
|
-
## License
|
39
|
-
|
40
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/krzfyx8g/ly-hotel.
|
41
36
|
|
data/lib/ly/hotel.rb
CHANGED
@@ -1,124 +1,71 @@
|
|
1
1
|
require "ly/hotel/version"
|
2
|
-
require "xmlsimple"
|
3
2
|
require "digest/md5"
|
3
|
+
require "active_support/core_ext/hash/conversions"
|
4
4
|
require "uri"
|
5
5
|
require "net/http"
|
6
|
-
require "openssl"
|
7
|
-
require "base64"
|
8
6
|
|
9
7
|
module Ly
|
10
8
|
module Hotel
|
11
9
|
class Api
|
10
|
+
attr_accessor :req_xml
|
11
|
+
attr_accessor :resp_xml
|
12
|
+
|
12
13
|
def initialize(account_id, password, api_host, version = "20111128102912")
|
13
14
|
@account_id = account_id
|
14
15
|
@password = password
|
15
|
-
@version = version
|
16
16
|
@api_host = api_host
|
17
|
-
|
18
|
-
|
19
|
-
def generate_digital_sign(service_name, req_time)
|
20
|
-
token_keys = {
|
21
|
-
"AccountID" => @account_id,
|
22
|
-
"ReqTime" => req_time,
|
23
|
-
"ServiceName" => service_name,
|
24
|
-
"Version" => @version
|
25
|
-
}
|
26
|
-
md5 = Digest::MD5.new
|
27
|
-
md5.update token_keys.map { |k, v| "#{k}=#{v}" }.join("&") << @password
|
28
|
-
md5.hexdigest
|
17
|
+
@version = version
|
29
18
|
end
|
30
19
|
|
31
|
-
def
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def credit_card_encrypt(key, data)
|
36
|
-
cipher = OpenSSL::Cipher::AES.new(128, :ECB)
|
37
|
-
cipher.encrypt
|
38
|
-
cipher.key = key
|
39
|
-
Base64.encode64(cipher.update(data) << cipher.final)
|
40
|
-
end
|
41
|
-
|
42
|
-
def request_xml(service_name, body = {}, req_time = generate_req_time, digital_sign = generate_digital_sign(service_name, req_time), options = {})
|
43
|
-
req = {
|
20
|
+
def request(handler, service_name, body = {}, timeout = 7)
|
21
|
+
request = {
|
44
22
|
"header" => {
|
45
23
|
"version" => @version,
|
46
24
|
"accountID" => @account_id,
|
47
25
|
"serviceName" => service_name,
|
48
|
-
"digitalSign" => digital_sign,
|
26
|
+
"digitalSign" => digital_sign(service_name, req_time = req_time()),
|
49
27
|
"reqTime" => req_time
|
50
28
|
},
|
51
29
|
"body" => body
|
52
30
|
}
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
def request(handler, req_xml, timeout = nil)
|
31
|
+
@req_xml = request.to_xml(root: 'request', indent: 0, skip_types: true)
|
57
32
|
uri = URI.parse "%s/handlers/%sHandler.ashx" % [@api_host, handler]
|
58
|
-
|
59
|
-
http.read_timeout = timeout
|
33
|
+
resp = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
60
34
|
req = Net::HTTP::Post.new(uri, "Content-Type" => "text/xml; charset=UTF-8")
|
61
|
-
req.body = req_xml
|
35
|
+
req.body = @req_xml
|
36
|
+
http.read_timeout = timeout
|
62
37
|
http.request(req)
|
63
38
|
end
|
64
|
-
|
39
|
+
@resp_xml = resp.body.force_encoding("UTF-8")
|
40
|
+
response = Hash.from_xml(@resp_xml)
|
41
|
+
raise Error.new(response["response"]["header"]["rspDesc"], response["response"]["header"]["rspCode"]) unless response["response"]["header"]["rspCode"] == "0000"
|
42
|
+
response['response']['body']
|
65
43
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
req_time = generate_req_time
|
71
|
-
|
72
|
-
# Generate digitalSign
|
73
|
-
digital_sign = generate_digital_sign(service_name, req_time)
|
74
|
-
|
75
|
-
# Request & Response, Xml conversion options.
|
76
|
-
if req_options.empty? || resp_options.empty?
|
77
|
-
options = xml_options(handler, service_name)
|
78
|
-
req_options = options[0] if req_options.empty?
|
79
|
-
resp_options = options[1] if resp_options.empty?
|
80
|
-
end
|
81
|
-
|
82
|
-
# Encrypted credit card information.
|
83
|
-
if "#{handler} #{service_name}" == "hotel/Order SubmitHotelOrder" && req_data.has_key?("creditCardInfo")
|
84
|
-
req_data["creditCardInfo"].each do |k, v|
|
85
|
-
req_data["creditCardInfo"][k] = credit_card_encrypt(digital_sign, v)
|
86
|
-
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def req_time(time = Time.now)
|
47
|
+
time.getgm.getlocal("+08:00").strftime("%Y-%m-%d %H:%M:%S.%L")
|
87
48
|
end
|
88
49
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
def xml_options(handler, service_name)
|
101
|
-
req_options = {"RootName" => "request", "AttrPrefix" => true, "SuppressEmpty" => nil, "NoIndent" => false}
|
102
|
-
resp_options = {"ForceArray" => false, "SuppressEmpty" => false}
|
103
|
-
puts "#{handler} #{service_name}"
|
104
|
-
case "#{handler} #{service_name}"
|
105
|
-
when "hotel/Order GetCardTypeList"
|
106
|
-
resp_options.merge!("GroupTags" => {"cardTypeList" => "cardType"})
|
107
|
-
when "hotel/Query GetHotelRoomsWithGuaranteePolicy"
|
108
|
-
resp_options.merge!("ForceArray" => %w(hotelRoomInfo pricePolicyInfo hotelBookPolicy), "GroupTags" => {"pricePolicyList" => "pricePolicyInfo", "hotelBookPolicyList" => "hotelBookPolicy"})
|
50
|
+
def digital_sign(service_name, req_time = req_time())
|
51
|
+
token = {
|
52
|
+
"AccountID" => @account_id,
|
53
|
+
"ReqTime" => req_time,
|
54
|
+
"ServiceName" => service_name,
|
55
|
+
"Version" => @version
|
56
|
+
}
|
57
|
+
md5 = Digest::MD5.new
|
58
|
+
md5.update token.map { |k, v| "#{k}=#{v}" }.join("&") << @password
|
59
|
+
md5.hexdigest
|
109
60
|
end
|
110
|
-
return req_options, resp_options
|
111
|
-
end
|
112
61
|
end
|
113
62
|
|
114
63
|
class Error < StandardError
|
115
|
-
attr_reader :
|
116
|
-
|
117
|
-
|
118
|
-
def initialize(message, req_xml, resp_xml)
|
64
|
+
attr_reader :code
|
65
|
+
|
66
|
+
def initialize(message, code = nil)
|
119
67
|
super(message)
|
120
|
-
@
|
121
|
-
@resp_xml = resp_xml
|
68
|
+
@code = code
|
122
69
|
end
|
123
70
|
end
|
124
71
|
end
|
data/lib/ly/hotel/version.rb
CHANGED
data/ly-hotel.gemspec
CHANGED
@@ -6,13 +6,12 @@ require 'ly/hotel/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ly-hotel"
|
8
8
|
spec.version = Ly::Hotel::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
9
|
+
spec.authors = ["knc74jEs"]
|
10
|
+
spec.email = ["knc74jes@emailsmail.com"]
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage = "https://github.com/krzfyx8g/ly-hotel
|
15
|
-
spec.license = "MIT"
|
12
|
+
spec.summary = %q{}
|
13
|
+
spec.description = %q{LY.com hotel APIs}
|
14
|
+
spec.homepage = "https://github.com/krzfyx8g/ly-hotel"
|
16
15
|
|
17
16
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
17
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
@@ -33,5 +32,5 @@ Gem::Specification.new do |spec|
|
|
33
32
|
spec.add_development_dependency "bundler", "~> 1.13"
|
34
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
34
|
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
-
spec.add_development_dependency "
|
35
|
+
spec.add_development_dependency "rails", "~> 5.0"
|
37
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ly-hotel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- knc74jEs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,28 +53,22 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
- - ">="
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: 1.1.5
|
61
|
+
version: '5.0'
|
65
62
|
type: :development
|
66
63
|
prerelease: false
|
67
64
|
version_requirements: !ruby/object:Gem::Requirement
|
68
65
|
requirements:
|
69
66
|
- - "~>"
|
70
67
|
- !ruby/object:Gem::Version
|
71
|
-
version: '
|
72
|
-
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 1.1.5
|
75
|
-
description: This is a Ly hotel API
|
68
|
+
version: '5.0'
|
69
|
+
description: LY.com hotel APIs
|
76
70
|
email:
|
77
|
-
-
|
71
|
+
- knc74jes@emailsmail.com
|
78
72
|
executables: []
|
79
73
|
extensions: []
|
80
74
|
extra_rdoc_files: []
|
@@ -82,7 +76,6 @@ files:
|
|
82
76
|
- ".gitignore"
|
83
77
|
- ".travis.yml"
|
84
78
|
- Gemfile
|
85
|
-
- LICENSE.txt
|
86
79
|
- README.md
|
87
80
|
- Rakefile
|
88
81
|
- bin/console
|
@@ -90,9 +83,8 @@ files:
|
|
90
83
|
- lib/ly/hotel.rb
|
91
84
|
- lib/ly/hotel/version.rb
|
92
85
|
- ly-hotel.gemspec
|
93
|
-
homepage: https://github.com/krzfyx8g/ly-hotel
|
94
|
-
licenses:
|
95
|
-
- MIT
|
86
|
+
homepage: https://github.com/krzfyx8g/ly-hotel
|
87
|
+
licenses: []
|
96
88
|
metadata:
|
97
89
|
allowed_push_host: https://rubygems.org
|
98
90
|
post_install_message:
|
@@ -114,5 +106,5 @@ rubyforge_project:
|
|
114
106
|
rubygems_version: 2.5.1
|
115
107
|
signing_key:
|
116
108
|
specification_version: 4
|
117
|
-
summary:
|
109
|
+
summary: ''
|
118
110
|
test_files: []
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016 Kezeal
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|