jieshun-parking 1.0.2 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af48b50290301d62121c001a13e8d3d96f02a127a3d2a81110181eec5ec33ccb
4
- data.tar.gz: 46b22f2a0e64c7a68a1c6cf39e6cb69370ff35da85abf38e6acabe8da017295b
3
+ metadata.gz: dab6086bb2e157c0139ec21e16885d4187eb6ad2b81c9ea7ba3416dc90c6e89c
4
+ data.tar.gz: 46e9eff558e6f0cbb0623c79ed6c044335ffbc4178d1e5a4473a25dcf45703ac
5
5
  SHA512:
6
- metadata.gz: eb58a646851491dfa2992d4cd5c05b948e9b4a84249336e0f4a988f4e3a79bdfdbcc987bfd97f489a75b6545e0d3bca59a3b844302a3b211fcd93771bade1c7f
7
- data.tar.gz: 131c3d12676e8bffeca10cfe0988e9e0462f0a439b4eff9a803f0b6f3a2672c9406832b44ffc23b142a8790c8e7718dba7a398e56ac90dc91b09168fc4011710
6
+ metadata.gz: f32aad0fb6c8e9b902552b6b65f3df9b8d226ec718a32817b75758dca4a1cea231b433fa1050f7069b4c3e8ff14921e4cf3d981aba5afcf96a948a2e4bfd9349
7
+ data.tar.gz: c51e1eda887f5fcc459a63d95f45a5e35fcc0d02c6a5313ffd71aafacb4802a34bf5956d4fdfeaebefeaebf362e6af0596f748cf939c124cd75de79d380ab5ca
@@ -25,12 +25,16 @@ module Jieshun
25
25
  @http_client.post_form("#{@configuration.server_url}/jsaims/login",
26
26
  {},
27
27
  hash,
28
- ->(response) {
29
- auth_token = response['token']
30
- @redis_client.redis_set(REDIS_AUTH_KEY, auth_token, 2 * 60 * 60 - 60) # token will be expired after 2 hours
31
- yield(auth_token)
32
- },
33
- ->(error) { handle_failure(error) })
28
+ ->(callback) {
29
+ if callback.successful
30
+ response = callback.body
31
+ auth_token = response['token']
32
+ @redis_client.redis_set(REDIS_AUTH_KEY, auth_token, 2 * 60 * 60 - 60) # token will be expired after 2 hours
33
+ yield(auth_token)
34
+ else
35
+ handle_failure(callback)
36
+ end
37
+ })
34
38
  else
35
39
  yield(auth_token)
36
40
  end
@@ -82,8 +86,13 @@ module Jieshun
82
86
  @http_client.post_form("#{@configuration.server_url}/jsaims/as",
83
87
  {},
84
88
  hash,
85
- ->(response) { yield(response) },
86
- ->(error) { handle_failure(error) })
89
+ ->(callback) {
90
+ if callback.successful
91
+ yield(callback)
92
+ else
93
+ handle_failure(callback)
94
+ end
95
+ })
87
96
  end
88
97
  end
89
98
 
@@ -52,13 +52,17 @@ module Jieshun
52
52
  @http_client.post_json("#{@configuration.server_url}/api/login",
53
53
  {},
54
54
  hash,
55
- ->(response) {
56
- auth_token = response['tn']
57
- expire_time = response['timeOut'] > 7200 ? response['timeOut'] - 7200 : response['timeOut'] # the token will expire 2 hours in advance
58
- @redis_client.redis_set(REDIS_AUTH_KEY, auth_token, expire_time)
59
- yield(auth_token)
60
- },
61
- ->(error) { handle_failure(error) })
55
+ ->(callback) {
56
+ if callback.successful
57
+ response = callback.body
58
+ auth_token = response['tn']
59
+ expire_time = response['timeOut'] > 7200 ? response['timeOut'] - 7200 : response['timeOut'] # the token will expire 2 hours in advance
60
+ @redis_client.redis_set(REDIS_AUTH_KEY, auth_token, expire_time)
61
+ yield(auth_token)
62
+ else
63
+ handle_failure(callback)
64
+ end
65
+ })
62
66
  end
63
67
 
64
68
  def get_picture_base64(file_path)
@@ -98,8 +102,13 @@ module Jieshun
98
102
  @http_client.post_json("#{@configuration.server_url}/#{api_path}",
99
103
  {},
100
104
  hash,
101
- ->(response) { yield(response) },
102
- ->(error) { handle_failure(error) })
105
+ ->(callback) {
106
+ if callback.successful
107
+ yield(callback)
108
+ else
109
+ handle_failure(callback)
110
+ end
111
+ })
103
112
  end
104
113
  end
105
114
 
@@ -119,11 +128,11 @@ module Jieshun
119
128
  #
120
129
  # 301:IP未绑定
121
130
  def handle_failure(error)
122
- case error['resultCode']
131
+ case error.body['resultCode']
123
132
  when 203
124
133
  @redis_client.redis_del(REDIS_AUTH_KEY)
125
134
  end
126
- raise RuntimeError.new("Unified error handling for data center clients; resultCode:#{error['resultCode']}, message: #{error['message']}")
135
+ raise RuntimeError.new("Unified error handling for data center clients; resultCode:#{error.body['resultCode']}, message: #{error.body['message']}")
127
136
  end
128
137
 
129
138
  def generate_signature(payload)
@@ -4,11 +4,11 @@ module Jieshun
4
4
 
5
5
  class HttpClient
6
6
 
7
- def post_form(server_url, headers, hash, success_callback, failure_callback)
7
+ def post_form(server_url, headers, hash, callback)
8
8
  raise NotImplementedError.new("You must implement this method.")
9
9
  end
10
10
 
11
- def post_json(server_url, headers, hash, success_callback, failure_callback)
11
+ def post_json(server_url, headers, hash, callback)
12
12
  raise NotImplementedError.new("You must implement this method.")
13
13
  end
14
14
 
@@ -6,23 +6,15 @@ module Jieshun
6
6
  require 'json'
7
7
  # 设置连接和读取的超时时间(以秒为单位)
8
8
  TIMEOUT = 30 # 例如,30 秒超时
9
- def post_form(server_url, headers, hash, success_callback, failure_callback)
9
+ def post_form(server_url, headers, hash, callback)
10
10
  post(server_url, 'application/x-www-form-urlencoded', headers, hash) do |result|
11
- if result.successful
12
- success_callback.call(result)
13
- else
14
- failure_callback.call(result)
15
- end
11
+ callback.call(result)
16
12
  end
17
13
  end
18
14
 
19
- def post_json(server_url, headers, hash, success_callback, failure_callback)
15
+ def post_json(server_url, headers, hash, callback)
20
16
  post(server_url, 'application/json', headers, hash) do |result|
21
- if result.successful
22
- success_callback.call(result)
23
- else
24
- failure_callback.call(result)
25
- end
17
+ callback.call(result)
26
18
  end
27
19
  end
28
20
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jieshun
4
4
  module Parking
5
- VERSION = "1.0.2"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jieshun-parking
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LCola