moov_ruby 0.1.30 → 0.1.31

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/moov/client.rb +2 -1
  3. data/lib/moov/models/components/amountdecimalvalidationerror.rb +37 -0
  4. data/lib/moov/models/components/amountdecimalvalidationerror.rbi +15 -0
  5. data/lib/moov/models/components/assignproductimage.rb +33 -0
  6. data/lib/moov/models/components/assignproductimage.rbi +13 -0
  7. data/lib/moov/models/components/assignproductimagevalidationerror.rb +33 -0
  8. data/lib/moov/models/components/assignproductimagevalidationerror.rbi +13 -0
  9. data/lib/moov/models/components/createproductoption.rb +49 -0
  10. data/lib/moov/models/components/createproductoption.rbi +19 -0
  11. data/lib/moov/models/components/createproductoptiongroup.rb +55 -0
  12. data/lib/moov/models/components/createproductoptiongroup.rbi +21 -0
  13. data/lib/moov/models/components/product.rb +69 -0
  14. data/lib/moov/models/components/product.rbi +29 -0
  15. data/lib/moov/models/components/productimagemetadata.rb +41 -0
  16. data/lib/moov/models/components/productimagemetadata.rbi +17 -0
  17. data/lib/moov/models/components/productoption.rb +49 -0
  18. data/lib/moov/models/components/productoption.rbi +19 -0
  19. data/lib/moov/models/components/productoptiongroup.rb +55 -0
  20. data/lib/moov/models/components/productoptiongroup.rbi +21 -0
  21. data/lib/moov/models/components/productoptiongroupvalidationerror.rb +49 -0
  22. data/lib/moov/models/components/productoptiongroupvalidationerror.rbi +21 -0
  23. data/lib/moov/models/components/productoptionvalidationerror.rb +45 -0
  24. data/lib/moov/models/components/productoptionvalidationerror.rbi +19 -0
  25. data/lib/moov/models/components/productrequest.rb +53 -0
  26. data/lib/moov/models/components/productrequest.rbi +21 -0
  27. data/lib/moov/models/components.rb +12 -0
  28. data/lib/moov/models/errors/productrequestvalidationerror.rb +53 -0
  29. data/lib/moov/models/errors/productrequestvalidationerror.rbi +23 -0
  30. data/lib/moov/models/errors.rb +1 -0
  31. data/lib/moov/models/operations/createproduct_request.rb +49 -0
  32. data/lib/moov/models/operations/createproduct_request.rbi +17 -0
  33. data/lib/moov/models/operations/createproduct_response.rb +49 -0
  34. data/lib/moov/models/operations/createproduct_response.rbi +21 -0
  35. data/lib/moov/models/operations/disableproduct_request.rb +49 -0
  36. data/lib/moov/models/operations/disableproduct_request.rbi +17 -0
  37. data/lib/moov/models/operations/disableproduct_response.rb +45 -0
  38. data/lib/moov/models/operations/disableproduct_response.rbi +19 -0
  39. data/lib/moov/models/operations/getproduct_request.rb +49 -0
  40. data/lib/moov/models/operations/getproduct_request.rbi +17 -0
  41. data/lib/moov/models/operations/getproduct_response.rb +49 -0
  42. data/lib/moov/models/operations/getproduct_response.rbi +21 -0
  43. data/lib/moov/models/operations/listproducts_request.rb +53 -0
  44. data/lib/moov/models/operations/listproducts_request.rbi +19 -0
  45. data/lib/moov/models/operations/listproducts_response.rb +49 -0
  46. data/lib/moov/models/operations/listproducts_response.rbi +21 -0
  47. data/lib/moov/models/operations/updateproduct_request.rb +53 -0
  48. data/lib/moov/models/operations/updateproduct_request.rbi +19 -0
  49. data/lib/moov/models/operations/updateproduct_response.rb +49 -0
  50. data/lib/moov/models/operations/updateproduct_response.rbi +21 -0
  51. data/lib/moov/models/operations.rb +10 -0
  52. data/lib/moov/products.rb +732 -0
  53. data/lib/moov/sdkconfiguration.rb +2 -2
  54. data/lib/moov_ruby.rb +1 -0
  55. metadata +49 -2
@@ -0,0 +1,732 @@
1
+ # Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
2
+
3
+ # typed: true
4
+ # frozen_string_literal: true
5
+
6
+ require 'faraday'
7
+ require 'faraday/multipart'
8
+ require 'faraday/retry'
9
+ require 'sorbet-runtime'
10
+ require_relative 'sdk_hooks/hooks'
11
+ require_relative 'utils/retries'
12
+
13
+ module Moov
14
+ extend T::Sig
15
+ class Products
16
+ extend T::Sig
17
+
18
+
19
+
20
+ sig { params(sdk_config: SDKConfiguration).void }
21
+ def initialize(sdk_config)
22
+ @sdk_configuration = sdk_config
23
+
24
+ end
25
+
26
+ sig { params(base_url: String, url_variables: T.nilable(T::Hash[Symbol, T.any(String, T::Enum)])).returns(String) }
27
+ def get_url(base_url:, url_variables: nil)
28
+ sd_base_url, sd_options = @sdk_configuration.get_server_details
29
+
30
+ if base_url.nil?
31
+ base_url = sd_base_url
32
+ end
33
+
34
+ if url_variables.nil?
35
+ url_variables = sd_options
36
+ end
37
+
38
+ return Utils.template_url base_url, url_variables
39
+ end
40
+
41
+
42
+ sig { params(account_id: ::String, x_moov_version: T.nilable(::String), skip: T.nilable(::Integer), count: T.nilable(::Integer), timeout_ms: T.nilable(Integer)).returns(Models::Operations::ListProductsResponse) }
43
+ def list(account_id:, x_moov_version: nil, skip: nil, count: nil, timeout_ms: nil)
44
+ # list - List active (non-disabled) products for an account.
45
+ request = Models::Operations::ListProductsRequest.new(
46
+ account_id: account_id,
47
+ x_moov_version: x_moov_version,
48
+ skip: skip,
49
+ count: count
50
+ )
51
+ url, params = @sdk_configuration.get_server_details
52
+ base_url = Utils.template_url(url, params)
53
+ url = Utils.generate_url(
54
+ Models::Operations::ListProductsRequest,
55
+ base_url,
56
+ '/accounts/{accountID}/products',
57
+ request,
58
+ @sdk_configuration.globals
59
+ )
60
+ headers = Utils.get_headers(request, @sdk_configuration.globals)
61
+ headers = T.cast(headers, T::Hash[String, String])
62
+ query_params = Utils.get_query_params(Models::Operations::ListProductsRequest, request, nil, @sdk_configuration.globals)
63
+ headers['Accept'] = 'application/json'
64
+ headers['user-agent'] = @sdk_configuration.user_agent
65
+
66
+ security = @sdk_configuration.security_source&.call
67
+
68
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
69
+ timeout ||= @sdk_configuration.timeout
70
+
71
+
72
+ connection = @sdk_configuration.client
73
+
74
+ hook_ctx = SDKHooks::HookContext.new(
75
+ config: @sdk_configuration,
76
+ base_url: base_url,
77
+ oauth2_scopes: nil,
78
+ operation_id: 'listProducts',
79
+ security_source: @sdk_configuration.security_source
80
+ )
81
+
82
+ error = T.let(nil, T.nilable(StandardError))
83
+ http_response = T.let(nil, T.nilable(Faraday::Response))
84
+
85
+
86
+ begin
87
+ http_response = T.must(connection).get(url) do |req|
88
+ req.headers.merge!(headers)
89
+ req.options.timeout = timeout unless timeout.nil?
90
+ req.params = query_params
91
+ Utils.configure_request_security(req, security)
92
+
93
+ @sdk_configuration.hooks.before_request(
94
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
95
+ hook_ctx: hook_ctx
96
+ ),
97
+ request: req
98
+ )
99
+ end
100
+ rescue StandardError => e
101
+ error = e
102
+ ensure
103
+ if http_response.nil? || Utils.error_status?(http_response.status)
104
+ http_response = @sdk_configuration.hooks.after_error(
105
+ error: error,
106
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
107
+ hook_ctx: hook_ctx
108
+ ),
109
+ response: http_response
110
+ )
111
+ else
112
+ http_response = @sdk_configuration.hooks.after_success(
113
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
114
+ hook_ctx: hook_ctx
115
+ ),
116
+ response: http_response
117
+ )
118
+ end
119
+
120
+ if http_response.nil?
121
+ raise error if !error.nil?
122
+ raise 'no response'
123
+ end
124
+ end
125
+
126
+ content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
127
+ if Utils.match_status_code(http_response.status, ['200'])
128
+ if Utils.match_content_type(content_type, 'application/json')
129
+ http_response = @sdk_configuration.hooks.after_success(
130
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
131
+ hook_ctx: hook_ctx
132
+ ),
133
+ response: http_response
134
+ )
135
+ response_data = http_response.env.response_body
136
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Crystalline::Array.new(Models::Components::Product))
137
+ response = Models::Operations::ListProductsResponse.new(
138
+ status_code: http_response.status,
139
+ content_type: content_type,
140
+ raw_response: http_response,
141
+ headers: http_response.headers,
142
+ products: T.unsafe(obj)
143
+ )
144
+
145
+ return response
146
+ else
147
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
148
+ end
149
+ elsif Utils.match_status_code(http_response.status, ['401', '403', '429'])
150
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
151
+ elsif Utils.match_status_code(http_response.status, ['500', '504'])
152
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
153
+ elsif Utils.match_status_code(http_response.status, ['4XX'])
154
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
155
+ elsif Utils.match_status_code(http_response.status, ['5XX'])
156
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
157
+ else
158
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
159
+
160
+ end
161
+ end
162
+
163
+
164
+ sig { params(product_request: Models::Components::ProductRequest, account_id: ::String, x_moov_version: T.nilable(::String), timeout_ms: T.nilable(Integer)).returns(Models::Operations::CreateProductResponse) }
165
+ def create(product_request:, account_id:, x_moov_version: nil, timeout_ms: nil)
166
+ # create - Creates a new product for the specified account.
167
+ request = Models::Operations::CreateProductRequest.new(
168
+ account_id: account_id,
169
+ product_request: product_request,
170
+ x_moov_version: x_moov_version
171
+ )
172
+ url, params = @sdk_configuration.get_server_details
173
+ base_url = Utils.template_url(url, params)
174
+ url = Utils.generate_url(
175
+ Models::Operations::CreateProductRequest,
176
+ base_url,
177
+ '/accounts/{accountID}/products',
178
+ request,
179
+ @sdk_configuration.globals
180
+ )
181
+ headers = Utils.get_headers(request, @sdk_configuration.globals)
182
+ headers = T.cast(headers, T::Hash[String, String])
183
+ req_content_type, data, form = Utils.serialize_request_body(request, false, false, :product_request, :json)
184
+ headers['content-type'] = req_content_type
185
+ raise StandardError, 'request body is required' if data.nil? && form.nil?
186
+
187
+ if form
188
+ body = Utils.encode_form(form)
189
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
190
+ body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
191
+ else
192
+ body = data
193
+ end
194
+ headers['Accept'] = 'application/json'
195
+ headers['user-agent'] = @sdk_configuration.user_agent
196
+
197
+ security = @sdk_configuration.security_source&.call
198
+
199
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
200
+ timeout ||= @sdk_configuration.timeout
201
+
202
+
203
+ connection = @sdk_configuration.client
204
+
205
+ hook_ctx = SDKHooks::HookContext.new(
206
+ config: @sdk_configuration,
207
+ base_url: base_url,
208
+ oauth2_scopes: nil,
209
+ operation_id: 'createProduct',
210
+ security_source: @sdk_configuration.security_source
211
+ )
212
+
213
+ error = T.let(nil, T.nilable(StandardError))
214
+ http_response = T.let(nil, T.nilable(Faraday::Response))
215
+
216
+
217
+ begin
218
+ http_response = T.must(connection).post(url) do |req|
219
+ req.body = body
220
+ req.headers.merge!(headers)
221
+ req.options.timeout = timeout unless timeout.nil?
222
+ Utils.configure_request_security(req, security)
223
+
224
+ @sdk_configuration.hooks.before_request(
225
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
226
+ hook_ctx: hook_ctx
227
+ ),
228
+ request: req
229
+ )
230
+ end
231
+ rescue StandardError => e
232
+ error = e
233
+ ensure
234
+ if http_response.nil? || Utils.error_status?(http_response.status)
235
+ http_response = @sdk_configuration.hooks.after_error(
236
+ error: error,
237
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
238
+ hook_ctx: hook_ctx
239
+ ),
240
+ response: http_response
241
+ )
242
+ else
243
+ http_response = @sdk_configuration.hooks.after_success(
244
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
245
+ hook_ctx: hook_ctx
246
+ ),
247
+ response: http_response
248
+ )
249
+ end
250
+
251
+ if http_response.nil?
252
+ raise error if !error.nil?
253
+ raise 'no response'
254
+ end
255
+ end
256
+
257
+ content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
258
+ if Utils.match_status_code(http_response.status, ['201'])
259
+ if Utils.match_content_type(content_type, 'application/json')
260
+ http_response = @sdk_configuration.hooks.after_success(
261
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
262
+ hook_ctx: hook_ctx
263
+ ),
264
+ response: http_response
265
+ )
266
+ response_data = http_response.env.response_body
267
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Components::Product)
268
+ response = Models::Operations::CreateProductResponse.new(
269
+ status_code: http_response.status,
270
+ content_type: content_type,
271
+ raw_response: http_response,
272
+ headers: http_response.headers,
273
+ product: T.unsafe(obj)
274
+ )
275
+
276
+ return response
277
+ else
278
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
279
+ end
280
+ elsif Utils.match_status_code(http_response.status, ['400', '409'])
281
+ if Utils.match_content_type(content_type, 'application/json')
282
+ http_response = @sdk_configuration.hooks.after_success(
283
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
284
+ hook_ctx: hook_ctx
285
+ ),
286
+ response: http_response
287
+ )
288
+ response_data = http_response.env.response_body
289
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::GenericError)
290
+ obj.raw_response = http_response
291
+ raise obj
292
+ else
293
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
294
+ end
295
+ elsif Utils.match_status_code(http_response.status, ['422'])
296
+ if Utils.match_content_type(content_type, 'application/json')
297
+ http_response = @sdk_configuration.hooks.after_success(
298
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
299
+ hook_ctx: hook_ctx
300
+ ),
301
+ response: http_response
302
+ )
303
+ response_data = http_response.env.response_body
304
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::ProductRequestValidationError)
305
+ obj.raw_response = http_response
306
+ raise obj
307
+ else
308
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
309
+ end
310
+ elsif Utils.match_status_code(http_response.status, ['401', '403', '404', '429'])
311
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
312
+ elsif Utils.match_status_code(http_response.status, ['500', '504'])
313
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
314
+ elsif Utils.match_status_code(http_response.status, ['4XX'])
315
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
316
+ elsif Utils.match_status_code(http_response.status, ['5XX'])
317
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
318
+ else
319
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
320
+
321
+ end
322
+ end
323
+
324
+
325
+ sig { params(account_id: ::String, product_id: ::String, x_moov_version: T.nilable(::String), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetProductResponse) }
326
+ def get(account_id:, product_id:, x_moov_version: nil, timeout_ms: nil)
327
+ # get - Retrieve a product by ID.
328
+ request = Models::Operations::GetProductRequest.new(
329
+ account_id: account_id,
330
+ product_id: product_id,
331
+ x_moov_version: x_moov_version
332
+ )
333
+ url, params = @sdk_configuration.get_server_details
334
+ base_url = Utils.template_url(url, params)
335
+ url = Utils.generate_url(
336
+ Models::Operations::GetProductRequest,
337
+ base_url,
338
+ '/accounts/{accountID}/products/{productID}',
339
+ request,
340
+ @sdk_configuration.globals
341
+ )
342
+ headers = Utils.get_headers(request, @sdk_configuration.globals)
343
+ headers = T.cast(headers, T::Hash[String, String])
344
+ headers['Accept'] = 'application/json'
345
+ headers['user-agent'] = @sdk_configuration.user_agent
346
+
347
+ security = @sdk_configuration.security_source&.call
348
+
349
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
350
+ timeout ||= @sdk_configuration.timeout
351
+
352
+
353
+ connection = @sdk_configuration.client
354
+
355
+ hook_ctx = SDKHooks::HookContext.new(
356
+ config: @sdk_configuration,
357
+ base_url: base_url,
358
+ oauth2_scopes: nil,
359
+ operation_id: 'getProduct',
360
+ security_source: @sdk_configuration.security_source
361
+ )
362
+
363
+ error = T.let(nil, T.nilable(StandardError))
364
+ http_response = T.let(nil, T.nilable(Faraday::Response))
365
+
366
+
367
+ begin
368
+ http_response = T.must(connection).get(url) do |req|
369
+ req.headers.merge!(headers)
370
+ req.options.timeout = timeout unless timeout.nil?
371
+ Utils.configure_request_security(req, security)
372
+
373
+ @sdk_configuration.hooks.before_request(
374
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
375
+ hook_ctx: hook_ctx
376
+ ),
377
+ request: req
378
+ )
379
+ end
380
+ rescue StandardError => e
381
+ error = e
382
+ ensure
383
+ if http_response.nil? || Utils.error_status?(http_response.status)
384
+ http_response = @sdk_configuration.hooks.after_error(
385
+ error: error,
386
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
387
+ hook_ctx: hook_ctx
388
+ ),
389
+ response: http_response
390
+ )
391
+ else
392
+ http_response = @sdk_configuration.hooks.after_success(
393
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
394
+ hook_ctx: hook_ctx
395
+ ),
396
+ response: http_response
397
+ )
398
+ end
399
+
400
+ if http_response.nil?
401
+ raise error if !error.nil?
402
+ raise 'no response'
403
+ end
404
+ end
405
+
406
+ content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
407
+ if Utils.match_status_code(http_response.status, ['200'])
408
+ if Utils.match_content_type(content_type, 'application/json')
409
+ http_response = @sdk_configuration.hooks.after_success(
410
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
411
+ hook_ctx: hook_ctx
412
+ ),
413
+ response: http_response
414
+ )
415
+ response_data = http_response.env.response_body
416
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Components::Product)
417
+ response = Models::Operations::GetProductResponse.new(
418
+ status_code: http_response.status,
419
+ content_type: content_type,
420
+ raw_response: http_response,
421
+ headers: http_response.headers,
422
+ product: T.unsafe(obj)
423
+ )
424
+
425
+ return response
426
+ else
427
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
428
+ end
429
+ elsif Utils.match_status_code(http_response.status, ['401', '403', '404', '429'])
430
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
431
+ elsif Utils.match_status_code(http_response.status, ['500', '504'])
432
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
433
+ elsif Utils.match_status_code(http_response.status, ['4XX'])
434
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
435
+ elsif Utils.match_status_code(http_response.status, ['5XX'])
436
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
437
+ else
438
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
439
+
440
+ end
441
+ end
442
+
443
+
444
+ sig { params(product_request: Models::Components::ProductRequest, account_id: ::String, product_id: ::String, x_moov_version: T.nilable(::String), timeout_ms: T.nilable(Integer)).returns(Models::Operations::UpdateProductResponse) }
445
+ def update(product_request:, account_id:, product_id:, x_moov_version: nil, timeout_ms: nil)
446
+ # update - Update a product and its options.
447
+ request = Models::Operations::UpdateProductRequest.new(
448
+ account_id: account_id,
449
+ product_id: product_id,
450
+ product_request: product_request,
451
+ x_moov_version: x_moov_version
452
+ )
453
+ url, params = @sdk_configuration.get_server_details
454
+ base_url = Utils.template_url(url, params)
455
+ url = Utils.generate_url(
456
+ Models::Operations::UpdateProductRequest,
457
+ base_url,
458
+ '/accounts/{accountID}/products/{productID}',
459
+ request,
460
+ @sdk_configuration.globals
461
+ )
462
+ headers = Utils.get_headers(request, @sdk_configuration.globals)
463
+ headers = T.cast(headers, T::Hash[String, String])
464
+ req_content_type, data, form = Utils.serialize_request_body(request, false, false, :product_request, :json)
465
+ headers['content-type'] = req_content_type
466
+ raise StandardError, 'request body is required' if data.nil? && form.nil?
467
+
468
+ if form
469
+ body = Utils.encode_form(form)
470
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
471
+ body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
472
+ else
473
+ body = data
474
+ end
475
+ headers['Accept'] = 'application/json'
476
+ headers['user-agent'] = @sdk_configuration.user_agent
477
+
478
+ security = @sdk_configuration.security_source&.call
479
+
480
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
481
+ timeout ||= @sdk_configuration.timeout
482
+
483
+
484
+ connection = @sdk_configuration.client
485
+
486
+ hook_ctx = SDKHooks::HookContext.new(
487
+ config: @sdk_configuration,
488
+ base_url: base_url,
489
+ oauth2_scopes: nil,
490
+ operation_id: 'updateProduct',
491
+ security_source: @sdk_configuration.security_source
492
+ )
493
+
494
+ error = T.let(nil, T.nilable(StandardError))
495
+ http_response = T.let(nil, T.nilable(Faraday::Response))
496
+
497
+
498
+ begin
499
+ http_response = T.must(connection).put(url) do |req|
500
+ req.body = body
501
+ req.headers.merge!(headers)
502
+ req.options.timeout = timeout unless timeout.nil?
503
+ Utils.configure_request_security(req, security)
504
+
505
+ @sdk_configuration.hooks.before_request(
506
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
507
+ hook_ctx: hook_ctx
508
+ ),
509
+ request: req
510
+ )
511
+ end
512
+ rescue StandardError => e
513
+ error = e
514
+ ensure
515
+ if http_response.nil? || Utils.error_status?(http_response.status)
516
+ http_response = @sdk_configuration.hooks.after_error(
517
+ error: error,
518
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
519
+ hook_ctx: hook_ctx
520
+ ),
521
+ response: http_response
522
+ )
523
+ else
524
+ http_response = @sdk_configuration.hooks.after_success(
525
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
526
+ hook_ctx: hook_ctx
527
+ ),
528
+ response: http_response
529
+ )
530
+ end
531
+
532
+ if http_response.nil?
533
+ raise error if !error.nil?
534
+ raise 'no response'
535
+ end
536
+ end
537
+
538
+ content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
539
+ if Utils.match_status_code(http_response.status, ['200'])
540
+ if Utils.match_content_type(content_type, 'application/json')
541
+ http_response = @sdk_configuration.hooks.after_success(
542
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
543
+ hook_ctx: hook_ctx
544
+ ),
545
+ response: http_response
546
+ )
547
+ response_data = http_response.env.response_body
548
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Components::Product)
549
+ response = Models::Operations::UpdateProductResponse.new(
550
+ status_code: http_response.status,
551
+ content_type: content_type,
552
+ raw_response: http_response,
553
+ headers: http_response.headers,
554
+ product: T.unsafe(obj)
555
+ )
556
+
557
+ return response
558
+ else
559
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
560
+ end
561
+ elsif Utils.match_status_code(http_response.status, ['400', '409'])
562
+ if Utils.match_content_type(content_type, 'application/json')
563
+ http_response = @sdk_configuration.hooks.after_success(
564
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
565
+ hook_ctx: hook_ctx
566
+ ),
567
+ response: http_response
568
+ )
569
+ response_data = http_response.env.response_body
570
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::GenericError)
571
+ obj.raw_response = http_response
572
+ raise obj
573
+ else
574
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
575
+ end
576
+ elsif Utils.match_status_code(http_response.status, ['422'])
577
+ if Utils.match_content_type(content_type, 'application/json')
578
+ http_response = @sdk_configuration.hooks.after_success(
579
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
580
+ hook_ctx: hook_ctx
581
+ ),
582
+ response: http_response
583
+ )
584
+ response_data = http_response.env.response_body
585
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::ProductRequestValidationError)
586
+ obj.raw_response = http_response
587
+ raise obj
588
+ else
589
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
590
+ end
591
+ elsif Utils.match_status_code(http_response.status, ['401', '403', '404', '429'])
592
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
593
+ elsif Utils.match_status_code(http_response.status, ['500', '504'])
594
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
595
+ elsif Utils.match_status_code(http_response.status, ['4XX'])
596
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
597
+ elsif Utils.match_status_code(http_response.status, ['5XX'])
598
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
599
+ else
600
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
601
+
602
+ end
603
+ end
604
+
605
+
606
+ sig { params(account_id: ::String, product_id: ::String, x_moov_version: T.nilable(::String), timeout_ms: T.nilable(Integer)).returns(Models::Operations::DisableProductResponse) }
607
+ def disable(account_id:, product_id:, x_moov_version: nil, timeout_ms: nil)
608
+ # disable - Disable a product by ID.
609
+ #
610
+ # The product will no longer be available, but will remain in the system for historical and reporting purposes.
611
+ request = Models::Operations::DisableProductRequest.new(
612
+ account_id: account_id,
613
+ product_id: product_id,
614
+ x_moov_version: x_moov_version
615
+ )
616
+ url, params = @sdk_configuration.get_server_details
617
+ base_url = Utils.template_url(url, params)
618
+ url = Utils.generate_url(
619
+ Models::Operations::DisableProductRequest,
620
+ base_url,
621
+ '/accounts/{accountID}/products/{productID}',
622
+ request,
623
+ @sdk_configuration.globals
624
+ )
625
+ headers = Utils.get_headers(request, @sdk_configuration.globals)
626
+ headers = T.cast(headers, T::Hash[String, String])
627
+ headers['Accept'] = 'application/json'
628
+ headers['user-agent'] = @sdk_configuration.user_agent
629
+
630
+ security = @sdk_configuration.security_source&.call
631
+
632
+ timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
633
+ timeout ||= @sdk_configuration.timeout
634
+
635
+
636
+ connection = @sdk_configuration.client
637
+
638
+ hook_ctx = SDKHooks::HookContext.new(
639
+ config: @sdk_configuration,
640
+ base_url: base_url,
641
+ oauth2_scopes: nil,
642
+ operation_id: 'disableProduct',
643
+ security_source: @sdk_configuration.security_source
644
+ )
645
+
646
+ error = T.let(nil, T.nilable(StandardError))
647
+ http_response = T.let(nil, T.nilable(Faraday::Response))
648
+
649
+
650
+ begin
651
+ http_response = T.must(connection).delete(url) do |req|
652
+ req.headers.merge!(headers)
653
+ req.options.timeout = timeout unless timeout.nil?
654
+ Utils.configure_request_security(req, security)
655
+
656
+ @sdk_configuration.hooks.before_request(
657
+ hook_ctx: SDKHooks::BeforeRequestHookContext.new(
658
+ hook_ctx: hook_ctx
659
+ ),
660
+ request: req
661
+ )
662
+ end
663
+ rescue StandardError => e
664
+ error = e
665
+ ensure
666
+ if http_response.nil? || Utils.error_status?(http_response.status)
667
+ http_response = @sdk_configuration.hooks.after_error(
668
+ error: error,
669
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
670
+ hook_ctx: hook_ctx
671
+ ),
672
+ response: http_response
673
+ )
674
+ else
675
+ http_response = @sdk_configuration.hooks.after_success(
676
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
677
+ hook_ctx: hook_ctx
678
+ ),
679
+ response: http_response
680
+ )
681
+ end
682
+
683
+ if http_response.nil?
684
+ raise error if !error.nil?
685
+ raise 'no response'
686
+ end
687
+ end
688
+
689
+ content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
690
+ if Utils.match_status_code(http_response.status, ['204'])
691
+ http_response = @sdk_configuration.hooks.after_success(
692
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
693
+ hook_ctx: hook_ctx
694
+ ),
695
+ response: http_response
696
+ )
697
+ return Models::Operations::DisableProductResponse.new(
698
+ status_code: http_response.status,
699
+ content_type: content_type,
700
+ raw_response: http_response,
701
+ headers: {}
702
+ )
703
+ elsif Utils.match_status_code(http_response.status, ['400', '409'])
704
+ if Utils.match_content_type(content_type, 'application/json')
705
+ http_response = @sdk_configuration.hooks.after_success(
706
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
707
+ hook_ctx: hook_ctx
708
+ ),
709
+ response: http_response
710
+ )
711
+ response_data = http_response.env.response_body
712
+ obj = Crystalline.unmarshal_json(JSON.parse(response_data), Models::Errors::GenericError)
713
+ obj.raw_response = http_response
714
+ raise obj
715
+ else
716
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
717
+ end
718
+ elsif Utils.match_status_code(http_response.status, ['401', '403', '404', '429'])
719
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
720
+ elsif Utils.match_status_code(http_response.status, ['500', '504'])
721
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
722
+ elsif Utils.match_status_code(http_response.status, ['4XX'])
723
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
724
+ elsif Utils.match_status_code(http_response.status, ['5XX'])
725
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
726
+ else
727
+ raise ::Moov::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
728
+
729
+ end
730
+ end
731
+ end
732
+ end