ding_sdk 0.11.65 → 0.12.1
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 +4 -4
- data/lib/ding_sdk/ding.rb +22 -8
- data/lib/ding_sdk/lookup.rb +56 -7
- data/lib/ding_sdk/otp.rb +299 -50
- data/lib/ding_sdk/sdk_hooks/hooks.rb +101 -0
- data/lib/ding_sdk/sdk_hooks/types.rb +152 -0
- data/lib/ding_sdk/sdkconfiguration.rb +11 -4
- data/lib/ding_sdk/utils/utils.rb +10 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4cfe3cd55a317456d9eb87f7f027b7e23aa8637c049275a278b98fd297f2d5c
|
4
|
+
data.tar.gz: 5836fa1d467c4aac780db2e90fe5ae306f6f365bad304ae5eaa717d061a51600
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 293a1d7b71b9ae242780de3c045d85c44e16d4cd477b6fde70207e4fb348574b07bd9aa0587c5cf1ad267dc0c0ec67a5b6787a293b19f66b0009c7e12b735871
|
7
|
+
data.tar.gz: fa23b1f9f389cbda83cedfda671d752dcc0feae1e0859331e0a3abdcfe662b6f7e44f5b411cf43ff4d17b62679be63d9f8356b7e3535532cdc1e285563172faf
|
data/lib/ding_sdk/ding.rb
CHANGED
@@ -7,6 +7,7 @@ require 'faraday'
|
|
7
7
|
require 'faraday/multipart'
|
8
8
|
require 'faraday/retry'
|
9
9
|
require 'sorbet-runtime'
|
10
|
+
require_relative 'sdk_hooks/hooks'
|
10
11
|
require_relative 'utils/retries'
|
11
12
|
|
12
13
|
module DingSDK
|
@@ -21,6 +22,7 @@ module DingSDK
|
|
21
22
|
params(
|
22
23
|
client: T.nilable(Faraday::Connection),
|
23
24
|
retry_config: T.nilable(::DingSDK::Utils::RetryConfig),
|
25
|
+
timeout_ms: T.nilable(Integer),
|
24
26
|
security: T.nilable(::DingSDK::Shared::Security),
|
25
27
|
security_source: T.nilable(T.proc.returns(::DingSDK::Shared::Security)),
|
26
28
|
server_idx: T.nilable(Integer),
|
@@ -28,23 +30,27 @@ module DingSDK
|
|
28
30
|
url_params: T.nilable(T::Hash[Symbol, String])
|
29
31
|
).void
|
30
32
|
end
|
31
|
-
def initialize(client: nil, retry_config: nil, security: nil, security_source: nil, server_idx: nil, server_url: nil, url_params: nil)
|
33
|
+
def initialize(client: nil, retry_config: nil, timeout_ms: nil, security: nil, security_source: nil, server_idx: nil, server_url: nil, url_params: nil)
|
32
34
|
## Instantiates the SDK configuring it with the provided parameters.
|
33
35
|
# @param [T.nilable(Faraday::Connection)] client The faraday HTTP client to use for all operations
|
34
36
|
# @param [T.nilable(::DingSDK::Utils::RetryConfig)] retry_config The retry configuration to use for all operations
|
37
|
+
# @param [T.nilable(Integer)] timeout_ms Request timeout in milliseconds for all operations
|
35
38
|
# @param [T.nilable(::DingSDK::Shared::Security)] security: The security details required for authentication
|
36
39
|
# @param [T.proc.returns(T.nilable(::DingSDK::Shared::Security))] security_source: A function that returns security details required for authentication
|
37
40
|
# @param [T.nilable(::Integer)] server_idx The index of the server to use for all operations
|
38
41
|
# @param [T.nilable(::String)] server_url The server URL to use for all operations
|
39
42
|
# @param [T.nilable(::Hash<::Symbol, ::String>)] url_params Parameters to optionally template the server URL with
|
40
43
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
connection_options = {
|
45
|
+
request: {
|
46
|
+
params_encoder: Faraday::FlatParamsEncoder
|
47
|
+
}
|
48
|
+
}
|
49
|
+
connection_options[:request][:timeout] = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
50
|
+
|
51
|
+
client ||= Faraday.new(**connection_options) do |f|
|
52
|
+
f.request :multipart, {}
|
53
|
+
# f.response :logger, nil, { headers: true, bodies: true, errors: true }
|
48
54
|
end
|
49
55
|
|
50
56
|
if !server_url.nil?
|
@@ -54,14 +60,22 @@ module DingSDK
|
|
54
60
|
end
|
55
61
|
|
56
62
|
server_idx = 0 if server_idx.nil?
|
63
|
+
hooks = SDKHooks::Hooks.new
|
57
64
|
@sdk_configuration = SDKConfiguration.new(
|
58
65
|
client,
|
66
|
+
hooks,
|
59
67
|
retry_config,
|
68
|
+
timeout_ms,
|
60
69
|
security,
|
61
70
|
security_source,
|
62
71
|
server_url,
|
63
72
|
server_idx
|
64
73
|
)
|
74
|
+
|
75
|
+
original_server_url = @sdk_configuration.get_server_details.first
|
76
|
+
new_server_url, @sdk_configuration.client = hooks.sdk_init(base_url: original_server_url, client: client)
|
77
|
+
@sdk_configuration.server_url = new_server_url if new_server_url != original_server_url
|
78
|
+
|
65
79
|
init_sdks
|
66
80
|
end
|
67
81
|
|
data/lib/ding_sdk/lookup.rb
CHANGED
@@ -7,6 +7,7 @@ require 'faraday'
|
|
7
7
|
require 'faraday/multipart'
|
8
8
|
require 'faraday/retry'
|
9
9
|
require 'sorbet-runtime'
|
10
|
+
require_relative 'sdk_hooks/hooks'
|
10
11
|
require_relative 'utils/retries'
|
11
12
|
|
12
13
|
module DingSDK
|
@@ -21,8 +22,8 @@ module DingSDK
|
|
21
22
|
end
|
22
23
|
|
23
24
|
|
24
|
-
sig { params(customer_uuid: ::String, phone_number: ::String, type: T.nilable(T::Array[::DingSDK::Operations::Type])).returns(::DingSDK::Operations::LookupResponse) }
|
25
|
-
def lookup(customer_uuid, phone_number, type = nil)
|
25
|
+
sig { params(customer_uuid: ::String, phone_number: ::String, type: T.nilable(T::Array[::DingSDK::Operations::Type]), timeout_ms: T.nilable(Integer)).returns(::DingSDK::Operations::LookupResponse) }
|
26
|
+
def lookup(customer_uuid, phone_number, type = nil, timeout_ms = nil)
|
26
27
|
# lookup - Look up for phone number
|
27
28
|
request = ::DingSDK::Operations::LookupRequest.new(
|
28
29
|
|
@@ -43,13 +44,61 @@ module DingSDK
|
|
43
44
|
headers['Accept'] = 'application/json'
|
44
45
|
headers['user-agent'] = @sdk_configuration.user_agent
|
45
46
|
|
47
|
+
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
|
48
|
+
|
49
|
+
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
50
|
+
timeout ||= @sdk_configuration.timeout
|
51
|
+
|
46
52
|
connection = @sdk_configuration.client
|
47
53
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
hook_ctx = SDKHooks::HookContext.new(
|
55
|
+
base_url: base_url,
|
56
|
+
oauth2_scopes: [],
|
57
|
+
operation_id: 'lookup',
|
58
|
+
security_source: @sdk_configuration.security_source
|
59
|
+
)
|
60
|
+
|
61
|
+
error = T.let(nil, T.nilable(StandardError))
|
62
|
+
r = T.let(nil, T.nilable(Faraday::Response))
|
63
|
+
|
64
|
+
begin
|
65
|
+
r = connection.get(url) do |req|
|
66
|
+
req.headers.merge!(headers)
|
67
|
+
req.options.timeout = timeout unless timeout.nil?
|
68
|
+
req.params = query_params
|
69
|
+
Utils.configure_request_security(req, security)
|
70
|
+
|
71
|
+
@sdk_configuration.hooks.before_request(
|
72
|
+
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
|
73
|
+
hook_ctx: hook_ctx
|
74
|
+
),
|
75
|
+
request: req
|
76
|
+
)
|
77
|
+
end
|
78
|
+
rescue StandardError => e
|
79
|
+
error = e
|
80
|
+
ensure
|
81
|
+
if r.nil? || Utils.error_status?(r.status)
|
82
|
+
r = @sdk_configuration.hooks.after_error(
|
83
|
+
error: error,
|
84
|
+
hook_ctx: SDKHooks::AfterErrorHookContext.new(
|
85
|
+
hook_ctx: hook_ctx
|
86
|
+
),
|
87
|
+
response: r
|
88
|
+
)
|
89
|
+
else
|
90
|
+
r = @sdk_configuration.hooks.after_success(
|
91
|
+
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
|
92
|
+
hook_ctx: hook_ctx
|
93
|
+
),
|
94
|
+
response: r
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
if r.nil?
|
99
|
+
raise error if !error.nil?
|
100
|
+
raise 'no response'
|
101
|
+
end
|
53
102
|
end
|
54
103
|
|
55
104
|
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
data/lib/ding_sdk/otp.rb
CHANGED
@@ -7,6 +7,7 @@ require 'faraday'
|
|
7
7
|
require 'faraday/multipart'
|
8
8
|
require 'faraday/retry'
|
9
9
|
require 'sorbet-runtime'
|
10
|
+
require_relative 'sdk_hooks/hooks'
|
10
11
|
require_relative 'utils/retries'
|
11
12
|
|
12
13
|
module DingSDK
|
@@ -21,8 +22,8 @@ module DingSDK
|
|
21
22
|
end
|
22
23
|
|
23
24
|
|
24
|
-
sig { params(request: T.nilable(::DingSDK::Shared::CreateCheckRequest)).returns(::DingSDK::Operations::CheckResponse) }
|
25
|
-
def check(request)
|
25
|
+
sig { params(request: T.nilable(::DingSDK::Shared::CreateCheckRequest), timeout_ms: T.nilable(Integer)).returns(::DingSDK::Operations::CheckResponse) }
|
26
|
+
def check(request, timeout_ms = nil)
|
26
27
|
# check - Check a code
|
27
28
|
url, params = @sdk_configuration.get_server_details
|
28
29
|
base_url = Utils.template_url(url, params)
|
@@ -30,21 +31,71 @@ module DingSDK
|
|
30
31
|
headers = {}
|
31
32
|
req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
|
32
33
|
headers['content-type'] = req_content_type
|
34
|
+
|
35
|
+
if form
|
36
|
+
body = Utils.encode_form(form)
|
37
|
+
elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
|
38
|
+
body = URI.encode_www_form(data)
|
39
|
+
else
|
40
|
+
body = data
|
41
|
+
end
|
33
42
|
headers['Accept'] = 'application/json'
|
34
43
|
headers['user-agent'] = @sdk_configuration.user_agent
|
35
44
|
|
45
|
+
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
|
46
|
+
|
47
|
+
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
48
|
+
timeout ||= @sdk_configuration.timeout
|
49
|
+
|
36
50
|
connection = @sdk_configuration.client
|
37
51
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
52
|
+
hook_ctx = SDKHooks::HookContext.new(
|
53
|
+
base_url: base_url,
|
54
|
+
oauth2_scopes: [],
|
55
|
+
operation_id: 'check',
|
56
|
+
security_source: @sdk_configuration.security_source
|
57
|
+
)
|
58
|
+
|
59
|
+
error = T.let(nil, T.nilable(StandardError))
|
60
|
+
r = T.let(nil, T.nilable(Faraday::Response))
|
61
|
+
|
62
|
+
begin
|
63
|
+
r = connection.post(url) do |req|
|
64
|
+
req.body = body
|
65
|
+
req.headers.merge!(headers)
|
66
|
+
req.options.timeout = timeout unless timeout.nil?
|
67
|
+
Utils.configure_request_security(req, security)
|
68
|
+
|
69
|
+
@sdk_configuration.hooks.before_request(
|
70
|
+
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
|
71
|
+
hook_ctx: hook_ctx
|
72
|
+
),
|
73
|
+
request: req
|
74
|
+
)
|
75
|
+
end
|
76
|
+
rescue StandardError => e
|
77
|
+
error = e
|
78
|
+
ensure
|
79
|
+
if r.nil? || Utils.error_status?(r.status)
|
80
|
+
r = @sdk_configuration.hooks.after_error(
|
81
|
+
error: error,
|
82
|
+
hook_ctx: SDKHooks::AfterErrorHookContext.new(
|
83
|
+
hook_ctx: hook_ctx
|
84
|
+
),
|
85
|
+
response: r
|
86
|
+
)
|
46
87
|
else
|
47
|
-
|
88
|
+
r = @sdk_configuration.hooks.after_success(
|
89
|
+
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
|
90
|
+
hook_ctx: hook_ctx
|
91
|
+
),
|
92
|
+
response: r
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
if r.nil?
|
97
|
+
raise error if !error.nil?
|
98
|
+
raise 'no response'
|
48
99
|
end
|
49
100
|
end
|
50
101
|
|
@@ -69,8 +120,8 @@ module DingSDK
|
|
69
120
|
end
|
70
121
|
|
71
122
|
|
72
|
-
sig { params(request: T.nilable(::DingSDK::Shared::CreateAuthenticationRequest)).returns(::DingSDK::Operations::CreateAuthenticationResponse) }
|
73
|
-
def create_authentication(request)
|
123
|
+
sig { params(request: T.nilable(::DingSDK::Shared::CreateAuthenticationRequest), timeout_ms: T.nilable(Integer)).returns(::DingSDK::Operations::CreateAuthenticationResponse) }
|
124
|
+
def create_authentication(request, timeout_ms = nil)
|
74
125
|
# create_authentication - Send a code
|
75
126
|
url, params = @sdk_configuration.get_server_details
|
76
127
|
base_url = Utils.template_url(url, params)
|
@@ -78,21 +129,71 @@ module DingSDK
|
|
78
129
|
headers = {}
|
79
130
|
req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
|
80
131
|
headers['content-type'] = req_content_type
|
132
|
+
|
133
|
+
if form
|
134
|
+
body = Utils.encode_form(form)
|
135
|
+
elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
|
136
|
+
body = URI.encode_www_form(data)
|
137
|
+
else
|
138
|
+
body = data
|
139
|
+
end
|
81
140
|
headers['Accept'] = 'application/json'
|
82
141
|
headers['user-agent'] = @sdk_configuration.user_agent
|
83
142
|
|
143
|
+
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
|
144
|
+
|
145
|
+
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
146
|
+
timeout ||= @sdk_configuration.timeout
|
147
|
+
|
84
148
|
connection = @sdk_configuration.client
|
85
149
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
150
|
+
hook_ctx = SDKHooks::HookContext.new(
|
151
|
+
base_url: base_url,
|
152
|
+
oauth2_scopes: [],
|
153
|
+
operation_id: 'create-authentication',
|
154
|
+
security_source: @sdk_configuration.security_source
|
155
|
+
)
|
156
|
+
|
157
|
+
error = T.let(nil, T.nilable(StandardError))
|
158
|
+
r = T.let(nil, T.nilable(Faraday::Response))
|
159
|
+
|
160
|
+
begin
|
161
|
+
r = connection.post(url) do |req|
|
162
|
+
req.body = body
|
163
|
+
req.headers.merge!(headers)
|
164
|
+
req.options.timeout = timeout unless timeout.nil?
|
165
|
+
Utils.configure_request_security(req, security)
|
166
|
+
|
167
|
+
@sdk_configuration.hooks.before_request(
|
168
|
+
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
|
169
|
+
hook_ctx: hook_ctx
|
170
|
+
),
|
171
|
+
request: req
|
172
|
+
)
|
173
|
+
end
|
174
|
+
rescue StandardError => e
|
175
|
+
error = e
|
176
|
+
ensure
|
177
|
+
if r.nil? || Utils.error_status?(r.status)
|
178
|
+
r = @sdk_configuration.hooks.after_error(
|
179
|
+
error: error,
|
180
|
+
hook_ctx: SDKHooks::AfterErrorHookContext.new(
|
181
|
+
hook_ctx: hook_ctx
|
182
|
+
),
|
183
|
+
response: r
|
184
|
+
)
|
94
185
|
else
|
95
|
-
|
186
|
+
r = @sdk_configuration.hooks.after_success(
|
187
|
+
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
|
188
|
+
hook_ctx: hook_ctx
|
189
|
+
),
|
190
|
+
response: r
|
191
|
+
)
|
192
|
+
end
|
193
|
+
|
194
|
+
if r.nil?
|
195
|
+
raise error if !error.nil?
|
196
|
+
raise 'no response'
|
96
197
|
end
|
97
198
|
end
|
98
199
|
|
@@ -117,8 +218,8 @@ module DingSDK
|
|
117
218
|
end
|
118
219
|
|
119
220
|
|
120
|
-
sig { params(request: T.nilable(::DingSDK::Shared::FeedbackRequest)).returns(::DingSDK::Operations::FeedbackResponse) }
|
121
|
-
def feedback(request)
|
221
|
+
sig { params(request: T.nilable(::DingSDK::Shared::FeedbackRequest), timeout_ms: T.nilable(Integer)).returns(::DingSDK::Operations::FeedbackResponse) }
|
222
|
+
def feedback(request, timeout_ms = nil)
|
122
223
|
# feedback - Send feedback
|
123
224
|
url, params = @sdk_configuration.get_server_details
|
124
225
|
base_url = Utils.template_url(url, params)
|
@@ -126,21 +227,71 @@ module DingSDK
|
|
126
227
|
headers = {}
|
127
228
|
req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
|
128
229
|
headers['content-type'] = req_content_type
|
230
|
+
|
231
|
+
if form
|
232
|
+
body = Utils.encode_form(form)
|
233
|
+
elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
|
234
|
+
body = URI.encode_www_form(data)
|
235
|
+
else
|
236
|
+
body = data
|
237
|
+
end
|
129
238
|
headers['Accept'] = 'application/json'
|
130
239
|
headers['user-agent'] = @sdk_configuration.user_agent
|
131
240
|
|
241
|
+
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
|
242
|
+
|
243
|
+
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
244
|
+
timeout ||= @sdk_configuration.timeout
|
245
|
+
|
132
246
|
connection = @sdk_configuration.client
|
133
247
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
248
|
+
hook_ctx = SDKHooks::HookContext.new(
|
249
|
+
base_url: base_url,
|
250
|
+
oauth2_scopes: [],
|
251
|
+
operation_id: 'feedback',
|
252
|
+
security_source: @sdk_configuration.security_source
|
253
|
+
)
|
254
|
+
|
255
|
+
error = T.let(nil, T.nilable(StandardError))
|
256
|
+
r = T.let(nil, T.nilable(Faraday::Response))
|
257
|
+
|
258
|
+
begin
|
259
|
+
r = connection.post(url) do |req|
|
260
|
+
req.body = body
|
261
|
+
req.headers.merge!(headers)
|
262
|
+
req.options.timeout = timeout unless timeout.nil?
|
263
|
+
Utils.configure_request_security(req, security)
|
264
|
+
|
265
|
+
@sdk_configuration.hooks.before_request(
|
266
|
+
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
|
267
|
+
hook_ctx: hook_ctx
|
268
|
+
),
|
269
|
+
request: req
|
270
|
+
)
|
271
|
+
end
|
272
|
+
rescue StandardError => e
|
273
|
+
error = e
|
274
|
+
ensure
|
275
|
+
if r.nil? || Utils.error_status?(r.status)
|
276
|
+
r = @sdk_configuration.hooks.after_error(
|
277
|
+
error: error,
|
278
|
+
hook_ctx: SDKHooks::AfterErrorHookContext.new(
|
279
|
+
hook_ctx: hook_ctx
|
280
|
+
),
|
281
|
+
response: r
|
282
|
+
)
|
142
283
|
else
|
143
|
-
|
284
|
+
r = @sdk_configuration.hooks.after_success(
|
285
|
+
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
|
286
|
+
hook_ctx: hook_ctx
|
287
|
+
),
|
288
|
+
response: r
|
289
|
+
)
|
290
|
+
end
|
291
|
+
|
292
|
+
if r.nil?
|
293
|
+
raise error if !error.nil?
|
294
|
+
raise 'no response'
|
144
295
|
end
|
145
296
|
end
|
146
297
|
|
@@ -165,8 +316,8 @@ module DingSDK
|
|
165
316
|
end
|
166
317
|
|
167
318
|
|
168
|
-
sig { params(auth_uuid: ::String).returns(::DingSDK::Operations::GetAuthenticationStatusResponse) }
|
169
|
-
def get_authentication_status(auth_uuid)
|
319
|
+
sig { params(auth_uuid: ::String, timeout_ms: T.nilable(Integer)).returns(::DingSDK::Operations::GetAuthenticationStatusResponse) }
|
320
|
+
def get_authentication_status(auth_uuid, timeout_ms = nil)
|
170
321
|
# get_authentication_status - Get authentication status
|
171
322
|
request = ::DingSDK::Operations::GetAuthenticationStatusRequest.new(
|
172
323
|
|
@@ -184,12 +335,60 @@ module DingSDK
|
|
184
335
|
headers['Accept'] = 'application/json'
|
185
336
|
headers['user-agent'] = @sdk_configuration.user_agent
|
186
337
|
|
338
|
+
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
|
339
|
+
|
340
|
+
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
341
|
+
timeout ||= @sdk_configuration.timeout
|
342
|
+
|
187
343
|
connection = @sdk_configuration.client
|
188
344
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
345
|
+
hook_ctx = SDKHooks::HookContext.new(
|
346
|
+
base_url: base_url,
|
347
|
+
oauth2_scopes: [],
|
348
|
+
operation_id: 'getAuthenticationStatus',
|
349
|
+
security_source: @sdk_configuration.security_source
|
350
|
+
)
|
351
|
+
|
352
|
+
error = T.let(nil, T.nilable(StandardError))
|
353
|
+
r = T.let(nil, T.nilable(Faraday::Response))
|
354
|
+
|
355
|
+
begin
|
356
|
+
r = connection.get(url) do |req|
|
357
|
+
req.headers.merge!(headers)
|
358
|
+
req.options.timeout = timeout unless timeout.nil?
|
359
|
+
Utils.configure_request_security(req, security)
|
360
|
+
|
361
|
+
@sdk_configuration.hooks.before_request(
|
362
|
+
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
|
363
|
+
hook_ctx: hook_ctx
|
364
|
+
),
|
365
|
+
request: req
|
366
|
+
)
|
367
|
+
end
|
368
|
+
rescue StandardError => e
|
369
|
+
error = e
|
370
|
+
ensure
|
371
|
+
if r.nil? || Utils.error_status?(r.status)
|
372
|
+
r = @sdk_configuration.hooks.after_error(
|
373
|
+
error: error,
|
374
|
+
hook_ctx: SDKHooks::AfterErrorHookContext.new(
|
375
|
+
hook_ctx: hook_ctx
|
376
|
+
),
|
377
|
+
response: r
|
378
|
+
)
|
379
|
+
else
|
380
|
+
r = @sdk_configuration.hooks.after_success(
|
381
|
+
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
|
382
|
+
hook_ctx: hook_ctx
|
383
|
+
),
|
384
|
+
response: r
|
385
|
+
)
|
386
|
+
end
|
387
|
+
|
388
|
+
if r.nil?
|
389
|
+
raise error if !error.nil?
|
390
|
+
raise 'no response'
|
391
|
+
end
|
193
392
|
end
|
194
393
|
|
195
394
|
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
@@ -213,8 +412,8 @@ module DingSDK
|
|
213
412
|
end
|
214
413
|
|
215
414
|
|
216
|
-
sig { params(request: T.nilable(::DingSDK::Shared::RetryAuthenticationRequest)).returns(::DingSDK::Operations::RetryResponse) }
|
217
|
-
def retry(request)
|
415
|
+
sig { params(request: T.nilable(::DingSDK::Shared::RetryAuthenticationRequest), timeout_ms: T.nilable(Integer)).returns(::DingSDK::Operations::RetryResponse) }
|
416
|
+
def retry(request, timeout_ms = nil)
|
218
417
|
# retry - Perform a retry
|
219
418
|
url, params = @sdk_configuration.get_server_details
|
220
419
|
base_url = Utils.template_url(url, params)
|
@@ -222,21 +421,71 @@ module DingSDK
|
|
222
421
|
headers = {}
|
223
422
|
req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
|
224
423
|
headers['content-type'] = req_content_type
|
424
|
+
|
425
|
+
if form
|
426
|
+
body = Utils.encode_form(form)
|
427
|
+
elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
|
428
|
+
body = URI.encode_www_form(data)
|
429
|
+
else
|
430
|
+
body = data
|
431
|
+
end
|
225
432
|
headers['Accept'] = 'application/json'
|
226
433
|
headers['user-agent'] = @sdk_configuration.user_agent
|
227
434
|
|
435
|
+
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
|
436
|
+
|
437
|
+
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
438
|
+
timeout ||= @sdk_configuration.timeout
|
439
|
+
|
228
440
|
connection = @sdk_configuration.client
|
229
441
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
442
|
+
hook_ctx = SDKHooks::HookContext.new(
|
443
|
+
base_url: base_url,
|
444
|
+
oauth2_scopes: [],
|
445
|
+
operation_id: 'retry',
|
446
|
+
security_source: @sdk_configuration.security_source
|
447
|
+
)
|
448
|
+
|
449
|
+
error = T.let(nil, T.nilable(StandardError))
|
450
|
+
r = T.let(nil, T.nilable(Faraday::Response))
|
451
|
+
|
452
|
+
begin
|
453
|
+
r = connection.post(url) do |req|
|
454
|
+
req.body = body
|
455
|
+
req.headers.merge!(headers)
|
456
|
+
req.options.timeout = timeout unless timeout.nil?
|
457
|
+
Utils.configure_request_security(req, security)
|
458
|
+
|
459
|
+
@sdk_configuration.hooks.before_request(
|
460
|
+
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
|
461
|
+
hook_ctx: hook_ctx
|
462
|
+
),
|
463
|
+
request: req
|
464
|
+
)
|
465
|
+
end
|
466
|
+
rescue StandardError => e
|
467
|
+
error = e
|
468
|
+
ensure
|
469
|
+
if r.nil? || Utils.error_status?(r.status)
|
470
|
+
r = @sdk_configuration.hooks.after_error(
|
471
|
+
error: error,
|
472
|
+
hook_ctx: SDKHooks::AfterErrorHookContext.new(
|
473
|
+
hook_ctx: hook_ctx
|
474
|
+
),
|
475
|
+
response: r
|
476
|
+
)
|
238
477
|
else
|
239
|
-
|
478
|
+
r = @sdk_configuration.hooks.after_success(
|
479
|
+
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
|
480
|
+
hook_ctx: hook_ctx
|
481
|
+
),
|
482
|
+
response: r
|
483
|
+
)
|
484
|
+
end
|
485
|
+
|
486
|
+
if r.nil?
|
487
|
+
raise error if !error.nil?
|
488
|
+
raise 'no response'
|
240
489
|
end
|
241
490
|
end
|
242
491
|
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
2
|
+
|
3
|
+
# typed: true
|
4
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
require_relative './types'
|
7
|
+
|
8
|
+
require 'sorbet-runtime'
|
9
|
+
|
10
|
+
module DingSDK
|
11
|
+
module SDKHooks
|
12
|
+
class Hooks
|
13
|
+
extend T::Sig
|
14
|
+
|
15
|
+
sig { void }
|
16
|
+
def initialize
|
17
|
+
@sdk_init_hooks = T.let([], T::Array[AbstractSDKInitHook])
|
18
|
+
@before_request_hooks = T.let([], T::Array[AbstractBeforeRequestHook])
|
19
|
+
@after_success_hooks = T.let([], T::Array[AbstractAfterSuccessHook])
|
20
|
+
@after_error_hooks = T.let([], T::Array[AbstractAfterErrorHook])
|
21
|
+
end
|
22
|
+
|
23
|
+
sig { params(hook: AbstractSDKInitHook).void }
|
24
|
+
def register_sdk_init_hook(hook)
|
25
|
+
@sdk_init_hooks << hook
|
26
|
+
end
|
27
|
+
|
28
|
+
sig { params(hook: AbstractBeforeRequestHook).void }
|
29
|
+
def register_before_request_hook(hook)
|
30
|
+
@before_request_hooks << hook
|
31
|
+
end
|
32
|
+
|
33
|
+
sig { params(hook: AbstractAfterSuccessHook).void }
|
34
|
+
def register_after_success_hook(hook)
|
35
|
+
@after_success_hooks << hook
|
36
|
+
end
|
37
|
+
|
38
|
+
sig { params(hook: AbstractAfterErrorHook).void }
|
39
|
+
def register_after_error_hook(hook)
|
40
|
+
@after_error_hooks << hook
|
41
|
+
end
|
42
|
+
|
43
|
+
sig do
|
44
|
+
params(
|
45
|
+
base_url: String,
|
46
|
+
client: Faraday::Connection
|
47
|
+
).returns([String, Faraday::Connection])
|
48
|
+
end
|
49
|
+
def sdk_init(base_url:, client:)
|
50
|
+
@sdk_init_hooks.each do |hook|
|
51
|
+
base_url, client = hook.sdk_init(base_url: base_url, client: client)
|
52
|
+
end
|
53
|
+
|
54
|
+
return base_url, client
|
55
|
+
end
|
56
|
+
|
57
|
+
sig do
|
58
|
+
params(
|
59
|
+
hook_ctx: BeforeRequestHookContext,
|
60
|
+
request: Faraday::Request
|
61
|
+
).returns(Faraday::Request)
|
62
|
+
end
|
63
|
+
def before_request(hook_ctx:, request:)
|
64
|
+
@before_request_hooks.each do |hook|
|
65
|
+
request = hook.before_request(hook_ctx: hook_ctx, request: request)
|
66
|
+
end
|
67
|
+
|
68
|
+
request
|
69
|
+
end
|
70
|
+
|
71
|
+
sig do
|
72
|
+
params(
|
73
|
+
hook_ctx: AfterSuccessHookContext,
|
74
|
+
response: Faraday::Response
|
75
|
+
).returns(Faraday::Response)
|
76
|
+
end
|
77
|
+
def after_success(hook_ctx:, response:)
|
78
|
+
@after_success_hooks.each do |hook|
|
79
|
+
response = hook.after_success(hook_ctx: hook_ctx, response: response)
|
80
|
+
end
|
81
|
+
|
82
|
+
response
|
83
|
+
end
|
84
|
+
|
85
|
+
sig do
|
86
|
+
params(
|
87
|
+
error: T.nilable(StandardError),
|
88
|
+
hook_ctx: AfterErrorHookContext,
|
89
|
+
response: T.nilable(Faraday::Response)
|
90
|
+
).returns(T.nilable(Faraday::Response))
|
91
|
+
end
|
92
|
+
def after_error(error:, hook_ctx:, response:)
|
93
|
+
@after_error_hooks.each do |hook|
|
94
|
+
response = hook.after_error(error: error, hook_ctx: hook_ctx, response: response)
|
95
|
+
end
|
96
|
+
|
97
|
+
response
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
2
|
+
|
3
|
+
# typed: true
|
4
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
require 'sorbet-runtime'
|
7
|
+
|
8
|
+
module DingSDK
|
9
|
+
module SDKHooks
|
10
|
+
class HookContext
|
11
|
+
extend T::Sig
|
12
|
+
|
13
|
+
sig { returns(String) }
|
14
|
+
attr_accessor :base_url
|
15
|
+
|
16
|
+
sig { returns(T.nilable(T::Array[String])) }
|
17
|
+
attr_accessor :oauth2_scopes
|
18
|
+
|
19
|
+
sig { returns(String) }
|
20
|
+
attr_accessor :operation_id
|
21
|
+
|
22
|
+
sig { returns(T.nilable(T.proc.returns(T.untyped))) }
|
23
|
+
attr_accessor :security_source
|
24
|
+
|
25
|
+
sig do
|
26
|
+
params(
|
27
|
+
base_url: String,
|
28
|
+
oauth2_scopes: T.nilable(T::Array[String]),
|
29
|
+
operation_id: String,
|
30
|
+
security_source: T.nilable(T.proc.returns(T.untyped))
|
31
|
+
).void
|
32
|
+
end
|
33
|
+
def initialize(base_url:, oauth2_scopes:, operation_id:, security_source:)
|
34
|
+
@base_url = T.let(base_url, String)
|
35
|
+
@oauth2_scopes = T.let(oauth2_scopes, T.nilable(T::Array[String]))
|
36
|
+
@operation_id = T.let(operation_id, String)
|
37
|
+
@security_source = T.let(security_source, T.nilable(T.proc.returns(T.untyped)))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class BeforeRequestHookContext < HookContext
|
42
|
+
extend T::Sig
|
43
|
+
|
44
|
+
sig do
|
45
|
+
params(
|
46
|
+
hook_ctx: HookContext
|
47
|
+
).void
|
48
|
+
end
|
49
|
+
def initialize(hook_ctx:)
|
50
|
+
super(
|
51
|
+
base_url: hook_ctx.base_url,
|
52
|
+
operation_id: hook_ctx.operation_id,
|
53
|
+
oauth2_scopes: hook_ctx.oauth2_scopes,
|
54
|
+
security_source: hook_ctx.security_source
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class AfterSuccessHookContext < HookContext
|
60
|
+
extend T::Sig
|
61
|
+
|
62
|
+
sig do
|
63
|
+
params(
|
64
|
+
hook_ctx: HookContext
|
65
|
+
).void
|
66
|
+
end
|
67
|
+
def initialize(hook_ctx:)
|
68
|
+
super(
|
69
|
+
base_url: hook_ctx.base_url,
|
70
|
+
operation_id: hook_ctx.operation_id,
|
71
|
+
oauth2_scopes: hook_ctx.oauth2_scopes,
|
72
|
+
security_source: hook_ctx.security_source
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class AfterErrorHookContext < HookContext
|
78
|
+
extend T::Sig
|
79
|
+
|
80
|
+
sig do
|
81
|
+
params(
|
82
|
+
hook_ctx: HookContext
|
83
|
+
).void
|
84
|
+
end
|
85
|
+
def initialize(hook_ctx:)
|
86
|
+
super(
|
87
|
+
base_url: hook_ctx.base_url,
|
88
|
+
operation_id: hook_ctx.operation_id,
|
89
|
+
oauth2_scopes: hook_ctx.oauth2_scopes,
|
90
|
+
security_source: hook_ctx.security_source
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
module AbstractSDKInitHook
|
96
|
+
extend T::Sig
|
97
|
+
extend T::Helpers
|
98
|
+
abstract!
|
99
|
+
|
100
|
+
sig do
|
101
|
+
abstract.params(
|
102
|
+
base_url: String,
|
103
|
+
client: Faraday::Connection
|
104
|
+
).returns([String, Faraday::Connection])
|
105
|
+
end
|
106
|
+
def sdk_init(base_url:, client:); end
|
107
|
+
end
|
108
|
+
|
109
|
+
module AbstractBeforeRequestHook
|
110
|
+
extend T::Sig
|
111
|
+
extend T::Helpers
|
112
|
+
abstract!
|
113
|
+
|
114
|
+
sig do
|
115
|
+
abstract.params(
|
116
|
+
hook_ctx: BeforeRequestHookContext,
|
117
|
+
request: Faraday::Request
|
118
|
+
).returns(Faraday::Request)
|
119
|
+
end
|
120
|
+
def before_request(hook_ctx:, request:); end
|
121
|
+
end
|
122
|
+
|
123
|
+
module AbstractAfterSuccessHook
|
124
|
+
extend T::Sig
|
125
|
+
extend T::Helpers
|
126
|
+
abstract!
|
127
|
+
|
128
|
+
sig do
|
129
|
+
abstract.params(
|
130
|
+
hook_ctx: AfterSuccessHookContext,
|
131
|
+
response: Faraday::Response
|
132
|
+
).returns(Faraday::Response)
|
133
|
+
end
|
134
|
+
def after_success(hook_ctx:, response:); end
|
135
|
+
end
|
136
|
+
|
137
|
+
module AbstractAfterErrorHook
|
138
|
+
extend T::Sig
|
139
|
+
extend T::Helpers
|
140
|
+
abstract!
|
141
|
+
|
142
|
+
sig do
|
143
|
+
abstract.params(
|
144
|
+
error: T.nilable(StandardError),
|
145
|
+
hook_ctx: AfterErrorHookContext,
|
146
|
+
response: T.nilable(Faraday::Response)
|
147
|
+
).returns(T.nilable(Faraday::Response))
|
148
|
+
end
|
149
|
+
def after_error(error:, hook_ctx:, response:); end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -7,6 +7,7 @@ require 'faraday'
|
|
7
7
|
require 'faraday/multipart'
|
8
8
|
require 'faraday/retry'
|
9
9
|
require 'sorbet-runtime'
|
10
|
+
require_relative 'sdk_hooks/hooks'
|
10
11
|
require_relative 'utils/retries'
|
11
12
|
|
12
13
|
module DingSDK
|
@@ -21,7 +22,9 @@ module DingSDK
|
|
21
22
|
extend T::Sig
|
22
23
|
|
23
24
|
field :client, T.nilable(Faraday::Connection)
|
25
|
+
field :hooks, ::DingSDK::SDKHooks::Hooks
|
24
26
|
field :retry_config, T.nilable(::DingSDK::Utils::RetryConfig)
|
27
|
+
field :timeout, T.nilable(Float)
|
25
28
|
field :security_source, T.nilable(T.proc.returns(T.nilable(::DingSDK::Shared::Security)))
|
26
29
|
field :server_url, T.nilable(String)
|
27
30
|
field :server_idx, T.nilable(Integer)
|
@@ -34,17 +37,21 @@ module DingSDK
|
|
34
37
|
sig do
|
35
38
|
params(
|
36
39
|
client: T.nilable(Faraday::Connection),
|
40
|
+
hooks: ::DingSDK::SDKHooks::Hooks,
|
37
41
|
retry_config: T.nilable(::DingSDK::Utils::RetryConfig),
|
42
|
+
timeout_ms: T.nilable(Integer),
|
38
43
|
security: T.nilable(::DingSDK::Shared::Security),
|
39
44
|
security_source: T.nilable(T.proc.returns(::DingSDK::Shared::Security)),
|
40
45
|
server_url: T.nilable(String),
|
41
46
|
server_idx: T.nilable(Integer)
|
42
47
|
).void
|
43
48
|
end
|
44
|
-
def initialize(client, retry_config, security, security_source, server_url, server_idx)
|
49
|
+
def initialize(client, hooks, retry_config, timeout_ms, security, security_source, server_url, server_idx)
|
45
50
|
@client = client
|
51
|
+
@hooks = hooks
|
46
52
|
@retry_config = retry_config
|
47
53
|
@server_url = server_url
|
54
|
+
@timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
48
55
|
@server_idx = server_idx.nil? ? 0 : server_idx
|
49
56
|
raise StandardError, "Invalid server index #{server_idx}" if @server_idx.negative? || @server_idx >= SERVERS.length
|
50
57
|
if !security_source.nil?
|
@@ -54,9 +61,9 @@ module DingSDK
|
|
54
61
|
end
|
55
62
|
@language = 'ruby'
|
56
63
|
@openapi_doc_version = '1.0.0'
|
57
|
-
@sdk_version = '0.
|
58
|
-
@gen_version = '2.
|
59
|
-
@user_agent = 'speakeasy-sdk/ruby 0.
|
64
|
+
@sdk_version = '0.12.1'
|
65
|
+
@gen_version = '2.556.1'
|
66
|
+
@user_agent = 'speakeasy-sdk/ruby 0.12.1 2.556.1 1.0.0 ding_sdk'
|
60
67
|
end
|
61
68
|
|
62
69
|
sig { returns([String, T::Hash[Symbol, String]]) }
|
data/lib/ding_sdk/utils/utils.rb
CHANGED
@@ -351,6 +351,15 @@ module DingSDK
|
|
351
351
|
server_url.delete_suffix('/') + path
|
352
352
|
end
|
353
353
|
|
354
|
+
sig { params(status: Integer).returns(T::Boolean) }
|
355
|
+
def self.error_status?(status)
|
356
|
+
status_major = status / 100
|
357
|
+
return true if status_major == 4
|
358
|
+
return true if status_major == 5
|
359
|
+
|
360
|
+
false
|
361
|
+
end
|
362
|
+
|
354
363
|
sig { params(content_type: String, pattern: String).returns(T::Boolean) }
|
355
364
|
def self.match_content_type(content_type, pattern)
|
356
365
|
return true if content_type == pattern || ['*', '*/*'].include?(pattern)
|
@@ -365,6 +374,7 @@ module DingSDK
|
|
365
374
|
|
366
375
|
sig { params(req: Faraday::Request, security: Object).void }
|
367
376
|
def self.configure_request_security(req, security)
|
377
|
+
return if security.nil?
|
368
378
|
sec_fields = security.fields
|
369
379
|
sec_fields.each do |sec_field|
|
370
380
|
value = security.send(sec_field.name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ding_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -224,6 +224,8 @@ files:
|
|
224
224
|
- lib/ding_sdk/models/shared/signals.rb
|
225
225
|
- lib/ding_sdk/models/shared/status.rb
|
226
226
|
- lib/ding_sdk/otp.rb
|
227
|
+
- lib/ding_sdk/sdk_hooks/hooks.rb
|
228
|
+
- lib/ding_sdk/sdk_hooks/types.rb
|
227
229
|
- lib/ding_sdk/sdkconfiguration.rb
|
228
230
|
- lib/ding_sdk/utils/retries.rb
|
229
231
|
- lib/ding_sdk/utils/utils.rb
|