ly-hotel 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b61fd2abb40afa128f62dea6d101da549e3c4848
4
+ data.tar.gz: 8f36bf8c84c04bb2c5184a355c546627ab09a9b8
5
+ SHA512:
6
+ metadata.gz: 7a44ed409df2cfcdd40fc83a1ac01f5e716f84414d7e03486fa1d3cb96154997ac4d350f601ffb6e131b49009d031c00e09e465f03e973a43503055112688660
7
+ data.tar.gz: ae11ab2ce1a0393a4d38d24cbf0f4e017f046c4d344ccdc391ff34b1fdace21a87146d56b691a71e2ccae3baf6e5e22856555c1263913ea6d7244c76c4484ae4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in workspace.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
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.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Ly::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/ly/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 'ly-hotel'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ly-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 spec` 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/krzfyx8g/ly-hotel.git
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).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ly/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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/ly/hotel.rb ADDED
@@ -0,0 +1,121 @@
1
+ require "ly/hotel/version"
2
+ require "xmlsimple"
3
+ require "digest/md5"
4
+ require "uri"
5
+ require "net/http"
6
+ require "openssl"
7
+ require "base64"
8
+
9
+ module Ly
10
+ module Hotel
11
+ class Api
12
+ def initialize(account_id, password, api_host, version = "20111128102912")
13
+ @account_id = account_id
14
+ @password = password
15
+ @version = version
16
+ @api_host = api_host
17
+ end
18
+
19
+ def generate_digital_sign(service_name, timestamp)
20
+ token_keys = {
21
+ "AccountID" => @account_id,
22
+ "ReqTime" => timestamp.strftime("%Y-%m-%d %H:%M:%S.%L"),
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
29
+ end
30
+
31
+ def credit_card_encrypt(key, data)
32
+ cipher = OpenSSL::Cipher::AES.new(128, :ECB)
33
+ cipher.encrypt
34
+ cipher.key = key
35
+ Base64.encode64(cipher.update(data) << cipher.final)
36
+ end
37
+
38
+ def request_xml(service_name, body = {}, timestamp = Time.now, options = {})
39
+ req = {
40
+ "header" => {
41
+ "version" => @version,
42
+ "accountID" => @account_id,
43
+ "serviceName" => service_name,
44
+ "digitalSign" => generate_digital_sign(service_name, timestamp),
45
+ "reqTime" => timestamp.strftime("%Y-%m-%d %H:%M:%S.%L")
46
+ },
47
+ "body" => body
48
+ }
49
+ XmlSimple.xml_out(req, options)
50
+ end
51
+
52
+ def request(handler, req_xml, timeout = nil)
53
+ uri = URI.parse "%s/handlers/%sHandler.ashx" % [@api_host, handler]
54
+ res = Net::HTTP.start(uri.hostname, uri.port) do |http|
55
+ http.read_timeout = timeout
56
+ req = Net::HTTP::Post.new(uri, "Content-Type" => "text/xml; charset=UTF-8")
57
+ req.body = req_xml
58
+ http.request(req)
59
+ end
60
+ res.body.force_encoding("UTF-8")
61
+ end
62
+
63
+ def service_request(handler, service_name, req_data = {}, req_options = {}, resp_options = {})
64
+
65
+ # Current time
66
+ now = Time.now
67
+
68
+ # Generate digitalSign
69
+ digital_sign = generate_digital_sign(service_name, now)
70
+
71
+ # Request & Response, Xml conversion options.
72
+ if req_options.empty? || resp_options.empty?
73
+ options = xml_options(handler, service_name)
74
+ req_options = options[0] if req_options.empty?
75
+ resp_options = options[1] if resp_options.empty?
76
+ end
77
+
78
+ # Encrypted credit card information.
79
+ if "#{handler} #{service_name}" == "hotel/Order SubmitHotelOrder" && req_data.has_key?("creditCardInfo")
80
+ req_data["creditCardInfo"].each do |k, v|
81
+ req_data["creditCardInfo"][k] = credit_card_encrypt(digital_sign, v)
82
+ end
83
+ end
84
+
85
+ # Request
86
+ req_xml = request_xml(service_name, req_data, now, req_options)
87
+ resp_xml = request(handler, req_xml)
88
+ result = XmlSimple.xml_in(resp_xml, resp_options)
89
+
90
+ # Exception handling.
91
+ raise Error.new(result["header"]["rspDesc"], req_xml, resp_xml) unless result["header"]["rspCode"] == "0000"
92
+
93
+ return result["body"], req_xml, resp_xml
94
+ end
95
+
96
+ def xml_options(handler, service_name)
97
+ req_options = {"RootName" => "request", "AttrPrefix" => true, "SuppressEmpty" => nil, "NoIndent" => false}
98
+ resp_options = {"ForceArray" => false, "SuppressEmpty" => false}
99
+ puts "#{handler} #{service_name}"
100
+ case "#{handler} #{service_name}"
101
+ when "hotel/Order GetCardTypeList"
102
+ resp_options.merge!("GroupTags" => {"cardTypeList" => "cardType"})
103
+ when "hotel/Query GetHotelRoomsWithGuaranteePolicy"
104
+ resp_options.merge!("ForceArray" => %w(hotelRoomInfo pricePolicyInfo hotelBookPolicy), "GroupTags" => {"pricePolicyList" => "pricePolicyInfo", "hotelBookPolicyList" => "hotelBookPolicy"})
105
+ end
106
+ return req_options, resp_options
107
+ end
108
+ end
109
+
110
+ class Error < StandardError
111
+ attr_reader :req_xml
112
+ attr_reader :resp_xml
113
+
114
+ def initialize(message, req_xml, resp_xml)
115
+ super(message)
116
+ @req_xml = req_xml
117
+ @resp_xml = resp_xml
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,5 @@
1
+ module Ly
2
+ module Hotel
3
+ VERSION = "0.1.2"
4
+ end
5
+ end
data/ly-hotel.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ly/hotel/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ly-hotel"
8
+ spec.version = Ly::Hotel::VERSION
9
+ spec.authors = ["UVzxV6cy"]
10
+ spec.email = ["uvzxv6cy@emailsmail.com"]
11
+
12
+ spec.summary = "Ly hotel API"
13
+ spec.description = "This is a Ly hotel API"
14
+ spec.homepage = "https://github.com/krzfyx8g/ly-hotel.git"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.13"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "xml-simple", "~> 1.1", ">= 1.1.5"
37
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ly-hotel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - UVzxV6cy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-14 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: xml-simple
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.1.5
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.1.5
75
+ description: This is a Ly hotel API
76
+ email:
77
+ - uvzxv6cy@emailsmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".travis.yml"
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/ly/hotel.rb
91
+ - lib/ly/hotel/version.rb
92
+ - ly-hotel.gemspec
93
+ homepage: https://github.com/krzfyx8g/ly-hotel.git
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ allowed_push_host: https://rubygems.org
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Ly hotel API
118
+ test_files: []