elong-hotel 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +26 -0
- data/README.md +35 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/elong-hotel.gemspec +36 -0
- data/lib/elong/hotel.rb +92 -0
- data/lib/elong/hotel/version.rb +5 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9a1b73a5642e37c978f73ff63acea30c295b85806906592699dcc872382aa267
|
4
|
+
data.tar.gz: 54cb38a3b27d9a8f5bd056631568334c17337a02c74830a3ee065123092e6c64
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f709aee3c933abc8323ae197ec30e693e8ac2bdee2e9c964237173ec9959949e29261031f51252856698ee8284eeb5b4875afdd0c44c3dc94d28b0c293ccae7
|
7
|
+
data.tar.gz: d45587b5f55e5a60ab5a87e5c238a81cbe473a7116f943265064afab818182fc828c0e0df2931cc47b0bed13d3c92563ccf1113b85049112626d4c52f1846a5e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
elong-hotel (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
mini_portile2 (2.3.0)
|
10
|
+
minitest (5.11.3)
|
11
|
+
nokogiri (1.8.4)
|
12
|
+
mini_portile2 (~> 2.3.0)
|
13
|
+
rake (10.5.0)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler (~> 1.16)
|
20
|
+
elong-hotel!
|
21
|
+
minitest (~> 5.0)
|
22
|
+
nokogiri (~> 1.8, >= 1.8.4)
|
23
|
+
rake (~> 10.0)
|
24
|
+
|
25
|
+
BUNDLED WITH
|
26
|
+
1.16.4
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Elong::Hotel
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/elong/hotel`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'elong-hotel'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install elong-hotel
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/elong-hotel.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "elong/hotel"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/elong-hotel.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "elong/hotel/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "elong-hotel"
|
8
|
+
spec.version = Elong::Hotel::VERSION
|
9
|
+
spec.authors = ["Xiao Jie"]
|
10
|
+
spec.email = ["iefsou@163.com"]
|
11
|
+
|
12
|
+
spec.summary = nil
|
13
|
+
|
14
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
15
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
16
|
+
if spec.respond_to?(:metadata)
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
else
|
19
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
20
|
+
"public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
35
|
+
spec.add_development_dependency "nokogiri", "~> 1.8", ">= 1.8.4"
|
36
|
+
end
|
data/lib/elong/hotel.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require "elong/hotel/version"
|
2
|
+
require "json"
|
3
|
+
require "uri"
|
4
|
+
require "net/http"
|
5
|
+
require "net/https"
|
6
|
+
require "digest"
|
7
|
+
require "openssl"
|
8
|
+
require "base64"
|
9
|
+
require "nokogiri"
|
10
|
+
|
11
|
+
module Elong
|
12
|
+
module Hotel
|
13
|
+
class Static
|
14
|
+
|
15
|
+
def initialize(devel = false)
|
16
|
+
@devel = devel
|
17
|
+
end
|
18
|
+
|
19
|
+
def geo_data(lang = 'cn')
|
20
|
+
request("geo_#{lang}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def hotel_detail(hotel_id, lang = 'cn')
|
24
|
+
request("#{lang}/#{hotel_id[-2..-1]}/#{hotel_id}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def request(path)
|
28
|
+
url = URI("http://api.elongstatic.com#{'/test' if @devel}/xml/v2.0/hotel/#{path}.xml")
|
29
|
+
puts url
|
30
|
+
http = Net::HTTP.new(url.host, url.port)
|
31
|
+
request = Net::HTTP::Get.new(url)
|
32
|
+
response = http.request(request)
|
33
|
+
Nokogiri::XML(response.read_body)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Dynamic
|
38
|
+
|
39
|
+
def initialize(user, appkey, secretkey, devel = false)
|
40
|
+
@user = user
|
41
|
+
@appkey = appkey
|
42
|
+
@secretkey = secretkey
|
43
|
+
@devel = devel
|
44
|
+
end
|
45
|
+
|
46
|
+
def des_encrypt(des_text, des_key)
|
47
|
+
des = OpenSSL::Cipher.new("DES-CBC")
|
48
|
+
des.encrypt
|
49
|
+
des.key = des_key
|
50
|
+
des.iv = des_key
|
51
|
+
cipher = des.update(des_text) + des.final
|
52
|
+
cipher.unpack('H*')[0]
|
53
|
+
end
|
54
|
+
|
55
|
+
def request(method, request)
|
56
|
+
params = {
|
57
|
+
format: "json",
|
58
|
+
method: method,
|
59
|
+
user: @user,
|
60
|
+
timestamp: Time.now.to_i.to_s
|
61
|
+
}
|
62
|
+
if method == "common.creditcard.validate"
|
63
|
+
request[:CreditCardNo] = des_encrypt("#{params[:timestamp]}##{request[:CreditCardNo]}", @appkey[-8..-1])
|
64
|
+
elsif method == "hotel.order.create" and request.has_key? :CreditCard
|
65
|
+
request[:CreditCard][:Number] = des_encrypt("#{params[:timestamp]}##{request[:CreditCard][:Number]}", @appkey[-8..-1])
|
66
|
+
end
|
67
|
+
params[:data] = {Version: "1.33", Local: "zh_CN", Request: request}.to_json
|
68
|
+
params[:signature] = Digest::MD5.hexdigest(params[:timestamp] + Digest::MD5.hexdigest(params[:data] + @appkey) + @secretkey)
|
69
|
+
puts params.to_json
|
70
|
+
url = URI("http://api#{'-test' if @devel}.elong.com/rest")
|
71
|
+
if %w(common.creditcard.validate hotel.order.create).include? method
|
72
|
+
url.scheme = "https"
|
73
|
+
url.port = 443
|
74
|
+
end
|
75
|
+
http = Net::HTTP.new(url.host, url.port)
|
76
|
+
if url.scheme == "https"
|
77
|
+
http.use_ssl = true
|
78
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
79
|
+
end
|
80
|
+
request = Net::HTTP::Post.new(url)
|
81
|
+
request["Content-Type"] = 'application/x-www-form-urlencoded; charset=UTF-8'
|
82
|
+
request.body = URI.encode_www_form(params)
|
83
|
+
response = http.request(request)
|
84
|
+
json = JSON.parse(response.read_body)
|
85
|
+
if json["Code"] != "0"
|
86
|
+
raise json["Code"]
|
87
|
+
end
|
88
|
+
json["Result"]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elong-hotel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xiao Jie
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-07 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.8.4
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.8'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.8.4
|
75
|
+
description:
|
76
|
+
email:
|
77
|
+
- iefsou@163.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".travis.yml"
|
84
|
+
- Gemfile
|
85
|
+
- Gemfile.lock
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- elong-hotel.gemspec
|
91
|
+
- lib/elong/hotel.rb
|
92
|
+
- lib/elong/hotel/version.rb
|
93
|
+
homepage:
|
94
|
+
licenses: []
|
95
|
+
metadata:
|
96
|
+
allowed_push_host: https://rubygems.org
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.7.7
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: ''
|
117
|
+
test_files: []
|