jieshun-parking 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2cf30541d80208f34adca825b070430ab9c403a660ab8396041f3d03d6a9d297
4
+ data.tar.gz: 40f8577ec4775ac3bcd9377cf0efc3d7b9c1f9a2115549f55121c4acaa1e7ed9
5
+ SHA512:
6
+ metadata.gz: 6d1b0b285e0dadaacbffdf3920abdc1044450716e89202ec4aa945697b90f445efd528f2576a3b1b30176f9864e707889549931ecd1bf0cad28aeafca8f6d0ef
7
+ data.tar.gz: e4e4c0aa60c3200aa0abaa1850354504aa8ac1b057a53d8a8755011230744d37848f5e019283f0a25562e4a1a872640c7364de02061615757b0dd9ed069d3b4c
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2009-2013 Nicholas J Humfrey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Jieshun::Parking
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/jieshun/parking`. 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 'jieshun-parking'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jieshun-parking
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 the created tag, 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]/jieshun-parking. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/jieshun-parking/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Jieshun::Parking project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/jieshun-parking/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,42 @@
1
+ module Jieshun
2
+ module Parking
3
+
4
+ class Client
5
+
6
+ def initialize(configuration, http_client = StandardHttpClient.new)
7
+ @configuration = configuration
8
+ @http_client = http_client
9
+ end
10
+
11
+ def create_payment_order(park_code, car_no)
12
+ headers = { }
13
+ hash = {
14
+ serviceId: '3c.pay.createorderbycarno',
15
+ requestType: 'DATA',
16
+ attributes: {
17
+ businesserCode: @configuration.businesser_code,
18
+ parkCode: park_code,
19
+ orderType: 'VNP',
20
+ carNo: car_no
21
+ }
22
+ }
23
+ @http_client.post_json(@configuration.server_url, headers, hash) do |result|
24
+ unless result.successful
25
+ message = "Error result : #{result.inspect}"
26
+ Jieshun::Parking.logger.error(message)
27
+ raise RuntimeError.new(message)
28
+ end
29
+ result_code = result.body[:resultCode]
30
+ if result_code != 0
31
+ message = "Error resultCode #{result_code}, body: #{result[:body]}"
32
+ Jieshun::Parking.logger.error(message)
33
+ raise RuntimeError.new(message)
34
+ end
35
+ yield(result)
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ module Jieshun
2
+ module Parking
3
+
4
+ class Configuration
5
+
6
+ attr_reader :server_url, :businesser_code
7
+
8
+ def initialize(server_url, businesser_code)
9
+ @server_url = server_url
10
+ @businesser_code = businesser_code
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module Jieshun
3
+ module Parking
4
+
5
+ class HttpClient
6
+
7
+ def post_json(server_url, headers, hash)
8
+ raise NotImplementedError.new("You must implement this method.")
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ module Jieshun
2
+ module Parking
3
+
4
+ class StandardHttpClient < HttpClient
5
+
6
+ require 'net/http'
7
+ require 'uri'
8
+ require 'json'
9
+
10
+ def post_json(server_url, headers, hash)
11
+ uri = URI.parse(server_url)
12
+ req = Net::HTTP::Post.new(uri)
13
+ headers.each { |k, v| req[k] = v }
14
+ req["Content-Type"] = "application/json"
15
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
16
+ if Jieshun::Parking.debug_mode && Jieshun::Parking.logger
17
+ Jieshun::Parking.logger.debug("Jieshun Parking Request #{hash}")
18
+ end
19
+ req.body = hash.to_json
20
+ res = http.request(req)
21
+ if Jieshun::Parking.debug_mode && Jieshun::Parking.logger
22
+ Jieshun::Parking.logger.debug("Jieshun Parking Response #{res}")
23
+ end
24
+ successful = res.kind_of?(Net::HTTPSuccess)
25
+ json = JSON.parse(res.body)
26
+ result = Jieshun::Parking::Result.new(successful, ActiveSupport::HashWithIndifferentAccess.new(json.to_hash))
27
+ yield result
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ module Jieshun
2
+ module Parking
3
+
4
+ class Result
5
+
6
+ attr_reader :successful, :body
7
+
8
+ def initialize(successful, body)
9
+ @successful = successful
10
+ @body = body
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jieshun
4
+ module Parking
5
+ VERSION = "0.2.0"
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "parking/version"
4
+ require_relative "parking/configuration"
5
+ require_relative "parking/client"
6
+ require_relative "parking/result"
7
+ require_relative "parking/http/http_client"
8
+ require_relative "parking/http/standard_http_client"
9
+ require 'logger'
10
+
11
+
12
+ module Jieshun
13
+ module Parking
14
+ @logger = Logger.new(STDOUT)
15
+ @debug_mode = true
16
+ class<< self
17
+ attr_accessor :logger, :debug_mode
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jieshun-parking
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - JamesWang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: 捷顺停车场 API, 非官方, Provided by 小可乐科技
28
+ email:
29
+ - james.wang.z81@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE.md
35
+ - README.md
36
+ - lib/jieshun/parking.rb
37
+ - lib/jieshun/parking/client.rb
38
+ - lib/jieshun/parking/configuration.rb
39
+ - lib/jieshun/parking/http/http_client.rb
40
+ - lib/jieshun/parking/http/standard_http_client.rb
41
+ - lib/jieshun/parking/result.rb
42
+ - lib/jieshun/parking/version.rb
43
+ homepage: http://rubygems.org/gems/jieshun-parking
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: http://rubygems.org/gems/jieshun-parking
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.4.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.0.9
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: 捷顺停车场 API
67
+ test_files: []