ding_sdk 0.12.0 → 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 +9 -0
- data/lib/ding_sdk/lookup.rb +51 -6
- data/lib/ding_sdk/otp.rb +274 -45
- 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 +8 -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
|
@@ -49,6 +50,7 @@ module DingSDK
|
|
49
50
|
|
50
51
|
client ||= Faraday.new(**connection_options) do |f|
|
51
52
|
f.request :multipart, {}
|
53
|
+
# f.response :logger, nil, { headers: true, bodies: true, errors: true }
|
52
54
|
end
|
53
55
|
|
54
56
|
if !server_url.nil?
|
@@ -58,8 +60,10 @@ module DingSDK
|
|
58
60
|
end
|
59
61
|
|
60
62
|
server_idx = 0 if server_idx.nil?
|
63
|
+
hooks = SDKHooks::Hooks.new
|
61
64
|
@sdk_configuration = SDKConfiguration.new(
|
62
65
|
client,
|
66
|
+
hooks,
|
63
67
|
retry_config,
|
64
68
|
timeout_ms,
|
65
69
|
security,
|
@@ -67,6 +71,11 @@ module DingSDK
|
|
67
71
|
server_url,
|
68
72
|
server_idx
|
69
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
|
+
|
70
79
|
init_sdks
|
71
80
|
end
|
72
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
|
@@ -43,17 +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
|
+
|
46
49
|
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
47
50
|
timeout ||= @sdk_configuration.timeout
|
48
51
|
|
49
52
|
connection = @sdk_configuration.client
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
57
102
|
end
|
58
103
|
|
59
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
|
@@ -30,25 +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
|
+
|
36
47
|
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
37
48
|
timeout ||= @sdk_configuration.timeout
|
38
49
|
|
39
50
|
connection = @sdk_configuration.client
|
40
51
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
+
)
|
50
87
|
else
|
51
|
-
|
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'
|
52
99
|
end
|
53
100
|
end
|
54
101
|
|
@@ -82,25 +129,71 @@ module DingSDK
|
|
82
129
|
headers = {}
|
83
130
|
req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
|
84
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
|
85
140
|
headers['Accept'] = 'application/json'
|
86
141
|
headers['user-agent'] = @sdk_configuration.user_agent
|
87
142
|
|
143
|
+
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
|
144
|
+
|
88
145
|
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
89
146
|
timeout ||= @sdk_configuration.timeout
|
90
147
|
|
91
148
|
connection = @sdk_configuration.client
|
92
149
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
+
)
|
102
185
|
else
|
103
|
-
|
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'
|
104
197
|
end
|
105
198
|
end
|
106
199
|
|
@@ -134,25 +227,71 @@ module DingSDK
|
|
134
227
|
headers = {}
|
135
228
|
req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
|
136
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
|
137
238
|
headers['Accept'] = 'application/json'
|
138
239
|
headers['user-agent'] = @sdk_configuration.user_agent
|
139
240
|
|
241
|
+
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
|
242
|
+
|
140
243
|
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
141
244
|
timeout ||= @sdk_configuration.timeout
|
142
245
|
|
143
246
|
connection = @sdk_configuration.client
|
144
247
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
+
)
|
154
283
|
else
|
155
|
-
|
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'
|
156
295
|
end
|
157
296
|
end
|
158
297
|
|
@@ -196,16 +335,60 @@ module DingSDK
|
|
196
335
|
headers['Accept'] = 'application/json'
|
197
336
|
headers['user-agent'] = @sdk_configuration.user_agent
|
198
337
|
|
338
|
+
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
|
339
|
+
|
199
340
|
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
200
341
|
timeout ||= @sdk_configuration.timeout
|
201
342
|
|
202
343
|
connection = @sdk_configuration.client
|
203
344
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
209
392
|
end
|
210
393
|
|
211
394
|
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
@@ -238,25 +421,71 @@ module DingSDK
|
|
238
421
|
headers = {}
|
239
422
|
req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
|
240
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
|
241
432
|
headers['Accept'] = 'application/json'
|
242
433
|
headers['user-agent'] = @sdk_configuration.user_agent
|
243
434
|
|
435
|
+
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
|
436
|
+
|
244
437
|
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
245
438
|
timeout ||= @sdk_configuration.timeout
|
246
439
|
|
247
440
|
connection = @sdk_configuration.client
|
248
441
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
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
|
+
)
|
258
477
|
else
|
259
|
-
|
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'
|
260
489
|
end
|
261
490
|
end
|
262
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,6 +22,7 @@ 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)
|
25
27
|
field :timeout, T.nilable(Float)
|
26
28
|
field :security_source, T.nilable(T.proc.returns(T.nilable(::DingSDK::Shared::Security)))
|
@@ -35,6 +37,7 @@ module DingSDK
|
|
35
37
|
sig do
|
36
38
|
params(
|
37
39
|
client: T.nilable(Faraday::Connection),
|
40
|
+
hooks: ::DingSDK::SDKHooks::Hooks,
|
38
41
|
retry_config: T.nilable(::DingSDK::Utils::RetryConfig),
|
39
42
|
timeout_ms: T.nilable(Integer),
|
40
43
|
security: T.nilable(::DingSDK::Shared::Security),
|
@@ -43,8 +46,9 @@ module DingSDK
|
|
43
46
|
server_idx: T.nilable(Integer)
|
44
47
|
).void
|
45
48
|
end
|
46
|
-
def initialize(client, retry_config, timeout_ms, security, security_source, server_url, server_idx)
|
49
|
+
def initialize(client, hooks, retry_config, timeout_ms, security, security_source, server_url, server_idx)
|
47
50
|
@client = client
|
51
|
+
@hooks = hooks
|
48
52
|
@retry_config = retry_config
|
49
53
|
@server_url = server_url
|
50
54
|
@timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
@@ -57,9 +61,9 @@ module DingSDK
|
|
57
61
|
end
|
58
62
|
@language = 'ruby'
|
59
63
|
@openapi_doc_version = '1.0.0'
|
60
|
-
@sdk_version = '0.12.
|
61
|
-
@gen_version = '2.
|
62
|
-
@user_agent = 'speakeasy-sdk/ruby 0.12.
|
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'
|
63
67
|
end
|
64
68
|
|
65
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.12.
|
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
|