ly-hotel 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dec119f6636cebb416ad71f2400949ec8cb8700b
4
- data.tar.gz: 71cd2fd95772dbc6ad4a74222406036984f77758
3
+ metadata.gz: eb6336b71f460b415a0dc0bd557c7d83d0104f3a
4
+ data.tar.gz: e0c36d9c9afdad5e868d89011e505b0f2617887d
5
5
  SHA512:
6
- metadata.gz: 778303d1c3849082044a551a1e50f5bdd2986ea61cbe30510d30a675e79cd65085ccea84638fac007937ac57fe099cb5d1b7366e9b137a5cf4fdd28dcc3d1e2b
7
- data.tar.gz: bba0640eb8ab946c47fb25e1d1eb08ebc8c188323c33caba6a055d175478b2e5fdc64f493635de3fa9db97e03d88bf6675b855766dc2d1e0efd72346021cc049
6
+ metadata.gz: 5387f42993e3c06505b233cecafbff276aaf924d8ca95fa6fa9bda2ed3f0a836cbd5423a1ee336e56845efdf6c798978d385afa273af5cccb58f341a9336a77f
7
+ data.tar.gz: 2641c89905d0c23e52b34f63739378292bf483726af8d57ed67b0b1496ae11e772ddbfeb907eec7f09a38545181c814b51e6967d1f86ce922bfdf3b7b03b60e1
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .DS_Store
11
+ .idea/
@@ -1,5 +1,5 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.13.6
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at iefsou@163.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Xiao Jie
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 CHANGED
@@ -26,11 +26,16 @@ TODO: Write usage instructions here
26
26
 
27
27
  ## Development
28
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.
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
30
 
31
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
32
 
33
33
  ## Contributing
34
34
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/krzfyx8g/ly-hotel.
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/iefsou/ly-hotel. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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).
36
41
 
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
2
+ require "rake/testtask"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
5
9
 
6
- task :default => :spec
10
+ task :default => :test
@@ -11,4 +11,4 @@ require "ly/hotel"
11
11
  # Pry.start
12
12
 
13
13
  require "irb"
14
- IRB.start
14
+ IRB.start(__FILE__)
@@ -1,68 +1,89 @@
1
1
  require "ly/hotel/version"
2
- require "digest/md5"
3
- require "active_support/core_ext/hash/conversions"
4
2
  require "uri"
5
3
  require "net/http"
4
+ require "digest/md5"
5
+ require "xmlsimple"
6
+ require "openssl"
7
+ require "base64"
6
8
 
7
9
  module Ly
8
10
  module Hotel
9
- class Api
10
- attr_accessor :req_xml
11
- attr_accessor :resp_xml
12
-
11
+ class API
12
+ attr_reader :req_url
13
+ attr_reader :req_data
14
+ attr_reader :resp
15
+
13
16
  def initialize(account_id, password, api_host, version = "20111128102912")
14
17
  @account_id = account_id
15
18
  @password = password
16
19
  @api_host = api_host
17
20
  @version = version
18
21
  end
19
-
22
+
20
23
  def request(handler, service_name, body = {}, timeout = 7)
21
24
  request = {
22
- "header" => {
23
- "version" => @version,
24
- "accountID" => @account_id,
25
- "serviceName" => service_name,
26
- "digitalSign" => digital_sign(service_name, req_time = req_time()),
27
- "reqTime" => req_time
28
- },
29
- "body" => body
25
+ "header" => {
26
+ "version" => @version,
27
+ "accountID" => @account_id,
28
+ "serviceName" => service_name,
29
+ "digitalSign" => digital_sign(service_name, req_time = req_time()),
30
+ "reqTime" => req_time
31
+ }
30
32
  }
31
- @req_xml = request.to_xml(root: 'request', indent: 0, skip_types: true)
32
- uri = URI.parse "%s/handlers/%sHandler.ashx" % [@api_host, handler]
33
+ if service_name.downcase == 'submithotelorder'
34
+ if body.has_key?('creditCardInfo')
35
+ body['creditCardInfo'].each do |key, value|
36
+ body['creditCardInfo'][key] = credit_card_encrypt(request["header"]["digitalSign"], value) unless value.nil? || value.empty?
37
+ end
38
+ end
39
+ end
40
+ request["body"] = body
41
+ @req_data = XmlSimple.xml_out(request, 'RootName' => 'request', 'AttrPrefix' => true, 'NoIndent' => false, 'SuppressEmpty' => nil)
42
+ uri = URI.parse(@req_url = "%s/handlers/%sHandler.ashx" % [@api_host, handler])
33
43
  resp = Net::HTTP.start(uri.hostname, uri.port) do |http|
34
44
  req = Net::HTTP::Post.new(uri, "Content-Type" => "text/xml; charset=UTF-8")
35
- req.body = @req_xml
45
+ req.body = @req_data
36
46
  http.read_timeout = timeout
37
47
  http.request(req)
38
48
  end
39
- @resp_xml = resp.body.force_encoding("UTF-8")
40
- response = Hash.from_xml(@resp_xml)
49
+ raise RequestError, "HTTP Response: #{resp.code} #{resp.message}" unless resp.is_a?(Net::HTTPSuccess)
50
+ @resp = resp.body.force_encoding("UTF-8")
51
+ response = XmlSimple.xml_in(@resp, 'KeepRoot' => true, 'SuppressEmpty' => true, 'ForceArray' => false)
41
52
  raise Error.new(response["response"]["header"]["rspDesc"], response["response"]["header"]["rspCode"]) unless response["response"]["header"]["rspCode"] == "0000"
42
53
  response['response']['body']
43
54
  end
44
-
55
+
45
56
  private
46
- def req_time(time = Time.now)
47
- time.getgm.getlocal("+08:00").strftime("%Y-%m-%d %H:%M:%S.%L")
48
- end
49
-
50
- def digital_sign(service_name, req_time = req_time())
51
- token = {
57
+ def req_time(time = Time.now)
58
+ time.getgm.getlocal("+08:00").strftime("%Y-%m-%d %H:%M:%S.%L")
59
+ end
60
+
61
+ def digital_sign(service_name, req_time = req_time())
62
+ token = {
52
63
  "AccountID" => @account_id,
53
64
  "ReqTime" => req_time,
54
65
  "ServiceName" => service_name,
55
66
  "Version" => @version
56
- }
57
- md5 = Digest::MD5.new
58
- md5.update token.map { |k, v| "#{k}=#{v}" }.join("&") << @password
59
- md5.hexdigest
60
- end
67
+ }
68
+ md5 = Digest::MD5.new
69
+ md5.update token.map { |k, v| "#{k}=#{v}" }.join("&") << @password
70
+ md5.hexdigest
71
+ end
72
+
73
+ def credit_card_encrypt(key, data)
74
+ cipher = OpenSSL::Cipher::AES.new(256, :ECB)
75
+ cipher.encrypt
76
+ cipher.key = key
77
+ Base64.strict_encode64(cipher.update(data) << cipher.final)
78
+ end
61
79
  end
62
-
80
+
81
+ class RequestError < StandardError;
82
+ end
83
+
63
84
  class Error < StandardError
64
85
  attr_reader :code
65
-
86
+
66
87
  def initialize(message, code = nil)
67
88
  super(message)
68
89
  @code = code
@@ -1,5 +1,5 @@
1
1
  module Ly
2
2
  module Hotel
3
- VERSION = "0.1.4"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -6,12 +6,13 @@ 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 = ["knc74jEs"]
10
- spec.email = ["knc74jes@emailsmail.com"]
9
+ spec.authors = ["Xiao Jie"]
10
+ spec.email = ["iefsou@163.com"]
11
11
 
12
- spec.summary = %q{}
13
- spec.description = %q{LY.com hotel APIs}
14
- spec.homepage = "https://github.com/krzfyx8g/ly-hotel"
12
+ spec.summary = %q{LY.com hotel API for Ruby}
13
+ spec.description = %q{A Ruby library that for LY.com's HTTP-based hotel API.}
14
+ spec.homepage = "https://github.com/iefsou/ly-hotel"
15
+ spec.license = "MIT"
15
16
 
16
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -29,8 +30,8 @@ Gem::Specification.new do |spec|
29
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
31
  spec.require_paths = ["lib"]
31
32
 
32
- spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "bundler", "~> 1.14"
33
34
  spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
35
- spec.add_development_dependency "rails", "~> 5.0"
35
+ spec.add_development_dependency "minitest", "~> 5.0"
36
+ spec.add_development_dependency "xml-simple", "~> 1.1", ">= 1.1.5"
36
37
  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
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - knc74jEs
7
+ - Xiao Jie
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-13 00:00:00.000000000 Z
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '1.14'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: '1.14'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,43 +39,51 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '5.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rails
56
+ name: xml-simple
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.0'
61
+ version: '1.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.1.5
62
65
  type: :development
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
69
  - - "~>"
67
70
  - !ruby/object:Gem::Version
68
- version: '5.0'
69
- description: LY.com hotel APIs
71
+ version: '1.1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.1.5
75
+ description: A Ruby library that for LY.com's HTTP-based hotel API.
70
76
  email:
71
- - knc74jes@emailsmail.com
77
+ - iefsou@163.com
72
78
  executables: []
73
79
  extensions: []
74
80
  extra_rdoc_files: []
75
81
  files:
76
82
  - ".gitignore"
77
83
  - ".travis.yml"
84
+ - CODE_OF_CONDUCT.md
78
85
  - Gemfile
86
+ - LICENSE.txt
79
87
  - README.md
80
88
  - Rakefile
81
89
  - bin/console
@@ -83,8 +91,9 @@ files:
83
91
  - lib/ly/hotel.rb
84
92
  - lib/ly/hotel/version.rb
85
93
  - ly-hotel.gemspec
86
- homepage: https://github.com/krzfyx8g/ly-hotel
87
- licenses: []
94
+ homepage: https://github.com/iefsou/ly-hotel
95
+ licenses:
96
+ - MIT
88
97
  metadata:
89
98
  allowed_push_host: https://rubygems.org
90
99
  post_install_message:
@@ -103,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
112
  version: '0'
104
113
  requirements: []
105
114
  rubyforge_project:
106
- rubygems_version: 2.5.1
115
+ rubygems_version: 2.6.10
107
116
  signing_key:
108
117
  specification_version: 4
109
- summary: ''
118
+ summary: LY.com hotel API for Ruby
110
119
  test_files: []