dub 0.2.2.pre.alpha.78 → 0.2.2.pre.alpha.79

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.
@@ -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 OpenApiSDK
@@ -21,8 +22,8 @@ module OpenApiSDK
21
22
  end
22
23
 
23
24
 
24
- sig { params(request: T.nilable(::OpenApiSDK::Operations::TrackLeadRequestBody)).returns(::OpenApiSDK::Operations::TrackLeadResponse) }
25
- def lead(request)
25
+ sig { params(request: T.nilable(::OpenApiSDK::Operations::TrackLeadRequestBody), timeout_ms: T.nilable(Integer)).returns(::OpenApiSDK::Operations::TrackLeadResponse) }
26
+ def lead(request, timeout_ms = nil)
26
27
  # lead - Track a lead
27
28
  # Track a lead for a short link.
28
29
  url, params = @sdk_configuration.get_server_details
@@ -31,21 +32,71 @@ module OpenApiSDK
31
32
  headers = {}
32
33
  req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
33
34
  headers['content-type'] = req_content_type
35
+
36
+ if form
37
+ body = Utils.encode_form(form)
38
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
39
+ body = URI.encode_www_form(data)
40
+ else
41
+ body = data
42
+ end
34
43
  headers['Accept'] = 'application/json'
35
44
  headers['user-agent'] = @sdk_configuration.user_agent
36
45
 
46
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
47
+
48
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
49
+ timeout ||= @sdk_configuration.timeout
50
+
37
51
  connection = @sdk_configuration.client
38
52
 
39
- r = connection.post(url) do |req|
40
- req.headers = headers
41
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
42
- Utils.configure_request_security(req, security) if !security.nil?
43
- if form
44
- req.body = Utils.encode_form(form)
45
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
46
- req.body = URI.encode_www_form(data)
53
+ hook_ctx = SDKHooks::HookContext.new(
54
+ base_url: base_url,
55
+ oauth2_scopes: [],
56
+ operation_id: 'trackLead',
57
+ security_source: @sdk_configuration.security_source
58
+ )
59
+
60
+ error = T.let(nil, T.nilable(StandardError))
61
+ r = T.let(nil, T.nilable(Faraday::Response))
62
+
63
+ begin
64
+ r = connection.post(url) do |req|
65
+ req.body = body
66
+ req.headers.merge!(headers)
67
+ req.options.timeout = timeout unless timeout.nil?
68
+ Utils.configure_request_security(req, security)
69
+
70
+ @sdk_configuration.hooks.before_request(
71
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
72
+ hook_ctx: hook_ctx
73
+ ),
74
+ request: req
75
+ )
76
+ end
77
+ rescue StandardError => e
78
+ error = e
79
+ ensure
80
+ if r.nil? || Utils.error_status?(r.status)
81
+ r = @sdk_configuration.hooks.after_error(
82
+ error: error,
83
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
84
+ hook_ctx: hook_ctx
85
+ ),
86
+ response: r
87
+ )
47
88
  else
48
- req.body = data
89
+ r = @sdk_configuration.hooks.after_success(
90
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
91
+ hook_ctx: hook_ctx
92
+ ),
93
+ response: r
94
+ )
95
+ end
96
+
97
+ if r.nil?
98
+ raise error if !error.nil?
99
+ raise 'no response'
49
100
  end
50
101
  end
51
102
 
@@ -110,8 +161,8 @@ module OpenApiSDK
110
161
  end
111
162
 
112
163
 
113
- sig { params(request: T.nilable(::OpenApiSDK::Operations::TrackSaleRequestBody)).returns(::OpenApiSDK::Operations::TrackSaleResponse) }
114
- def sale(request)
164
+ sig { params(request: T.nilable(::OpenApiSDK::Operations::TrackSaleRequestBody), timeout_ms: T.nilable(Integer)).returns(::OpenApiSDK::Operations::TrackSaleResponse) }
165
+ def sale(request, timeout_ms = nil)
115
166
  # sale - Track a sale
116
167
  # Track a sale for a short link.
117
168
  url, params = @sdk_configuration.get_server_details
@@ -120,21 +171,71 @@ module OpenApiSDK
120
171
  headers = {}
121
172
  req_content_type, data, form = Utils.serialize_request_body(request, :request, :json)
122
173
  headers['content-type'] = req_content_type
174
+
175
+ if form
176
+ body = Utils.encode_form(form)
177
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
178
+ body = URI.encode_www_form(data)
179
+ else
180
+ body = data
181
+ end
123
182
  headers['Accept'] = 'application/json'
124
183
  headers['user-agent'] = @sdk_configuration.user_agent
125
184
 
185
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
186
+
187
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
188
+ timeout ||= @sdk_configuration.timeout
189
+
126
190
  connection = @sdk_configuration.client
127
191
 
128
- r = connection.post(url) do |req|
129
- req.headers = headers
130
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
131
- Utils.configure_request_security(req, security) if !security.nil?
132
- if form
133
- req.body = Utils.encode_form(form)
134
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
135
- req.body = URI.encode_www_form(data)
192
+ hook_ctx = SDKHooks::HookContext.new(
193
+ base_url: base_url,
194
+ oauth2_scopes: [],
195
+ operation_id: 'trackSale',
196
+ security_source: @sdk_configuration.security_source
197
+ )
198
+
199
+ error = T.let(nil, T.nilable(StandardError))
200
+ r = T.let(nil, T.nilable(Faraday::Response))
201
+
202
+ begin
203
+ r = connection.post(url) do |req|
204
+ req.body = body
205
+ req.headers.merge!(headers)
206
+ req.options.timeout = timeout unless timeout.nil?
207
+ Utils.configure_request_security(req, security)
208
+
209
+ @sdk_configuration.hooks.before_request(
210
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
211
+ hook_ctx: hook_ctx
212
+ ),
213
+ request: req
214
+ )
215
+ end
216
+ rescue StandardError => e
217
+ error = e
218
+ ensure
219
+ if r.nil? || Utils.error_status?(r.status)
220
+ r = @sdk_configuration.hooks.after_error(
221
+ error: error,
222
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
223
+ hook_ctx: hook_ctx
224
+ ),
225
+ response: r
226
+ )
136
227
  else
137
- req.body = data
228
+ r = @sdk_configuration.hooks.after_success(
229
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
230
+ hook_ctx: hook_ctx
231
+ ),
232
+ response: r
233
+ )
234
+ end
235
+
236
+ if r.nil?
237
+ raise error if !error.nil?
238
+ raise 'no response'
138
239
  end
139
240
  end
140
241
 
@@ -351,6 +351,15 @@ module OpenApiSDK
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 OpenApiSDK
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)
@@ -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 OpenApiSDK
@@ -21,8 +22,8 @@ module OpenApiSDK
21
22
  end
22
23
 
23
24
 
24
- sig { params(request: T.nilable(::OpenApiSDK::Operations::GetWorkspaceRequest)).returns(::OpenApiSDK::Operations::GetWorkspaceResponse) }
25
- def get(request)
25
+ sig { params(request: T.nilable(::OpenApiSDK::Operations::GetWorkspaceRequest), timeout_ms: T.nilable(Integer)).returns(::OpenApiSDK::Operations::GetWorkspaceResponse) }
26
+ def get(request, timeout_ms = nil)
26
27
  # get - Retrieve a workspace
27
28
  # Retrieve a workspace for the authenticated user.
28
29
  url, params = @sdk_configuration.get_server_details
@@ -37,12 +38,60 @@ module OpenApiSDK
37
38
  headers['Accept'] = 'application/json'
38
39
  headers['user-agent'] = @sdk_configuration.user_agent
39
40
 
41
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
42
+
43
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
44
+ timeout ||= @sdk_configuration.timeout
45
+
40
46
  connection = @sdk_configuration.client
41
47
 
42
- r = connection.get(url) do |req|
43
- req.headers = headers
44
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
45
- Utils.configure_request_security(req, security) if !security.nil?
48
+ hook_ctx = SDKHooks::HookContext.new(
49
+ base_url: base_url,
50
+ oauth2_scopes: [],
51
+ operation_id: 'getWorkspace',
52
+ security_source: @sdk_configuration.security_source
53
+ )
54
+
55
+ error = T.let(nil, T.nilable(StandardError))
56
+ r = T.let(nil, T.nilable(Faraday::Response))
57
+
58
+ begin
59
+ r = connection.get(url) do |req|
60
+ req.headers.merge!(headers)
61
+ req.options.timeout = timeout unless timeout.nil?
62
+ Utils.configure_request_security(req, security)
63
+
64
+ @sdk_configuration.hooks.before_request(
65
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
66
+ hook_ctx: hook_ctx
67
+ ),
68
+ request: req
69
+ )
70
+ end
71
+ rescue StandardError => e
72
+ error = e
73
+ ensure
74
+ if r.nil? || Utils.error_status?(r.status)
75
+ r = @sdk_configuration.hooks.after_error(
76
+ error: error,
77
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
78
+ hook_ctx: hook_ctx
79
+ ),
80
+ response: r
81
+ )
82
+ else
83
+ r = @sdk_configuration.hooks.after_success(
84
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
85
+ hook_ctx: hook_ctx
86
+ ),
87
+ response: r
88
+ )
89
+ end
90
+
91
+ if r.nil?
92
+ raise error if !error.nil?
93
+ raise 'no response'
94
+ end
46
95
  end
47
96
 
48
97
  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
@@ -106,8 +155,8 @@ module OpenApiSDK
106
155
  end
107
156
 
108
157
 
109
- sig { params(request: T.nilable(::OpenApiSDK::Operations::UpdateWorkspaceRequest)).returns(::OpenApiSDK::Operations::UpdateWorkspaceResponse) }
110
- def update(request)
158
+ sig { params(request: T.nilable(::OpenApiSDK::Operations::UpdateWorkspaceRequest), timeout_ms: T.nilable(Integer)).returns(::OpenApiSDK::Operations::UpdateWorkspaceResponse) }
159
+ def update(request, timeout_ms = nil)
111
160
  # update - Update a workspace
112
161
  # Update a workspace by ID or slug.
113
162
  url, params = @sdk_configuration.get_server_details
@@ -121,21 +170,71 @@ module OpenApiSDK
121
170
  headers = {}
122
171
  req_content_type, data, form = Utils.serialize_request_body(request, :request_body, :json)
123
172
  headers['content-type'] = req_content_type
173
+
174
+ if form
175
+ body = Utils.encode_form(form)
176
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
177
+ body = URI.encode_www_form(data)
178
+ else
179
+ body = data
180
+ end
124
181
  headers['Accept'] = 'application/json'
125
182
  headers['user-agent'] = @sdk_configuration.user_agent
126
183
 
184
+ security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
185
+
186
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
187
+ timeout ||= @sdk_configuration.timeout
188
+
127
189
  connection = @sdk_configuration.client
128
190
 
129
- r = connection.patch(url) do |req|
130
- req.headers = headers
131
- security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
132
- Utils.configure_request_security(req, security) if !security.nil?
133
- if form
134
- req.body = Utils.encode_form(form)
135
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
136
- req.body = URI.encode_www_form(data)
191
+ hook_ctx = SDKHooks::HookContext.new(
192
+ base_url: base_url,
193
+ oauth2_scopes: [],
194
+ operation_id: 'updateWorkspace',
195
+ security_source: @sdk_configuration.security_source
196
+ )
197
+
198
+ error = T.let(nil, T.nilable(StandardError))
199
+ r = T.let(nil, T.nilable(Faraday::Response))
200
+
201
+ begin
202
+ r = connection.patch(url) do |req|
203
+ req.body = body
204
+ req.headers.merge!(headers)
205
+ req.options.timeout = timeout unless timeout.nil?
206
+ Utils.configure_request_security(req, security)
207
+
208
+ @sdk_configuration.hooks.before_request(
209
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
210
+ hook_ctx: hook_ctx
211
+ ),
212
+ request: req
213
+ )
214
+ end
215
+ rescue StandardError => e
216
+ error = e
217
+ ensure
218
+ if r.nil? || Utils.error_status?(r.status)
219
+ r = @sdk_configuration.hooks.after_error(
220
+ error: error,
221
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
222
+ hook_ctx: hook_ctx
223
+ ),
224
+ response: r
225
+ )
137
226
  else
138
- req.body = data
227
+ r = @sdk_configuration.hooks.after_success(
228
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
229
+ hook_ctx: hook_ctx
230
+ ),
231
+ response: r
232
+ )
233
+ end
234
+
235
+ if r.nil?
236
+ raise error if !error.nil?
237
+ raise 'no response'
139
238
  end
140
239
  end
141
240
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2.pre.alpha.78
4
+ version: 0.2.2.pre.alpha.79
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-17 00:00:00.000000000 Z
11
+ date: 2025-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -411,6 +411,9 @@ files:
411
411
  - lib/open_api_sdk/models/shared/workspaceschema.rb
412
412
  - lib/open_api_sdk/partners.rb
413
413
  - lib/open_api_sdk/qr_codes.rb
414
+ - lib/open_api_sdk/sdk_hooks/hooks.rb
415
+ - lib/open_api_sdk/sdk_hooks/registration.rb
416
+ - lib/open_api_sdk/sdk_hooks/types.rb
414
417
  - lib/open_api_sdk/sdkconfiguration.rb
415
418
  - lib/open_api_sdk/tags.rb
416
419
  - lib/open_api_sdk/track.rb