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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dab6086bb2e157c0139ec21e16885d4187eb6ad2b81c9ea7ba3416dc90c6e89c
|
4
|
+
data.tar.gz: 46e9eff558e6f0cbb0623c79ed6c044335ffbc4178d1e5a4473a25dcf45703ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
->(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
->(
|
86
|
-
|
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
|
-
->(
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
->(
|
102
|
-
|
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,
|
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,
|
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,
|
9
|
+
def post_form(server_url, headers, hash, callback)
|
10
10
|
post(server_url, 'application/x-www-form-urlencoded', headers, hash) do |result|
|
11
|
-
|
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,
|
15
|
+
def post_json(server_url, headers, hash, callback)
|
20
16
|
post(server_url, 'application/json', headers, hash) do |result|
|
21
|
-
|
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
|
|