fastpixapi 1.1.2 → 1.1.3

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/crystalline/metadata_fields.rb +56 -48
  3. data/lib/crystalline/types.rb +3 -3
  4. data/lib/crystalline.rb +4 -5
  5. data/lib/fastpix_client/dimensions.rb +51 -58
  6. data/lib/fastpix_client/drm_configurations.rb +49 -56
  7. data/lib/fastpix_client/errors.rb +35 -24
  8. data/lib/fastpix_client/fastpixapi.rb +2 -4
  9. data/lib/fastpix_client/in_video_ai_features.rb +100 -160
  10. data/lib/fastpix_client/input_video.rb +66 -74
  11. data/lib/fastpix_client/live_playback.rb +82 -99
  12. data/lib/fastpix_client/manage_live_stream.rb +136 -252
  13. data/lib/fastpix_client/manage_videos.rb +228 -543
  14. data/lib/fastpix_client/metrics.rb +76 -120
  15. data/lib/fastpix_client/models/components/createlivestreamresponsedto.rb +10 -18
  16. data/lib/fastpix_client/models/components/createmediarequest.rb +9 -18
  17. data/lib/fastpix_client/models/components/getallmediaresponse.rb +13 -29
  18. data/lib/fastpix_client/models/components/getcreatelivestreamresponsedto.rb +9 -20
  19. data/lib/fastpix_client/models/components/getmediaresponse.rb +13 -29
  20. data/lib/fastpix_client/models/components/live_media_clips.rb +9 -21
  21. data/lib/fastpix_client/models/components/media.rb +11 -26
  22. data/lib/fastpix_client/models/components/patchresponsedata.rb +9 -18
  23. data/lib/fastpix_client/models/components/sourceaccessmedia.rb +11 -26
  24. data/lib/fastpix_client/models/components/update_media.rb +11 -26
  25. data/lib/fastpix_client/models/components/views.rb +51 -124
  26. data/lib/fastpix_client/models/errors/empty_response_error.rb +15 -0
  27. data/lib/fastpix_client/models/errors.rb +1 -0
  28. data/lib/fastpix_client/models/operations/push_media_settings.rb +9 -20
  29. data/lib/fastpix_client/playback.rb +122 -213
  30. data/lib/fastpix_client/playlist.rb +150 -296
  31. data/lib/fastpix_client/sdk_hooks/registration.rb +2 -2
  32. data/lib/fastpix_client/sdk_hooks/types.rb +4 -0
  33. data/lib/fastpix_client/sdkconfiguration.rb +3 -3
  34. data/lib/fastpix_client/signing_keys.rb +76 -120
  35. data/lib/fastpix_client/simulcast_stream.rb +97 -141
  36. data/lib/fastpix_client/start_live_stream.rb +51 -33
  37. data/lib/fastpix_client/utils/forms.rb +97 -101
  38. data/lib/fastpix_client/utils/headers.rb +44 -34
  39. data/lib/fastpix_client/utils/query_params.rb +39 -29
  40. data/lib/fastpix_client/utils/request_bodies.rb +4 -8
  41. data/lib/fastpix_client/utils/security.rb +30 -18
  42. data/lib/fastpix_client/utils/url.rb +83 -60
  43. data/lib/fastpix_client/utils/utils.rb +19 -37
  44. data/lib/fastpix_client/views.rb +66 -90
  45. data/lib/fastpixapi.rb +10 -10
  46. data/lib/openssl_patch.rb +24 -24
  47. metadata +3 -2
@@ -14,6 +14,59 @@ module FastpixClient
14
14
  extend T::Sig
15
15
  class Playback
16
16
  extend T::Sig
17
+
18
+ API_ERROR_OCCURRED = 'API error occurred'
19
+ CONTENT_TYPE_HEADER = 'Content-Type'
20
+ CONTENT_TYPE_JSON = 'application/json'
21
+ DEFAULT_CONTENT_TYPE = 'application/octet-stream'
22
+ PLAYBACK_IDS_PATH = '/on-demand/{mediaId}/playback-ids'
23
+ REQUEST_CONTENT_TYPE_HEADER = 'content-type'
24
+ UNKNOWN_CONTENT_TYPE_ERROR = 'Unknown content type received'
25
+ USER_AGENT_HEADER = 'user-agent'
26
+
27
+ # Applies the SDK after-request hooks and ensures a usable response is present.
28
+ sig { params(http_response: T.nilable(Faraday::Response), error: T.nilable(StandardError), hook_ctx: SDKHooks::HookContext).returns(Faraday::Response) }
29
+ def apply_after_request_hooks(http_response, error, hook_ctx)
30
+ if http_response.nil? || Utils.error_status?(http_response.status)
31
+ http_response = @sdk_configuration.hooks.after_error(
32
+ error: error,
33
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
34
+ hook_ctx: hook_ctx
35
+ ),
36
+ response: http_response
37
+ )
38
+ else
39
+ http_response = @sdk_configuration.hooks.after_success(
40
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
41
+ hook_ctx: hook_ctx
42
+ ),
43
+ response: http_response
44
+ )
45
+ end
46
+
47
+ if http_response.nil?
48
+ raise error unless error.nil?
49
+ raise ::FastpixClient::Models::Errors::EmptyResponseError, 'no response'
50
+ end
51
+
52
+ http_response
53
+ end
54
+ private :apply_after_request_hooks
55
+
56
+ # Encodes the request body based on its serialized content type.
57
+ sig { params(req_content_type: T.nilable(String), data: T.untyped, form: T.untyped).returns(T.untyped) }
58
+ def encode_request_body(req_content_type, data, form)
59
+ raise ArgumentError, 'request body is required' if data.nil? && form.nil?
60
+
61
+ if form
62
+ Utils.encode_form(form)
63
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
64
+ URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
65
+ else
66
+ data
67
+ end
68
+ end
69
+ private :encode_request_body
17
70
 
18
71
  # Operations for video playback management
19
72
 
@@ -69,24 +122,16 @@ module FastpixClient
69
122
  url = Utils.generate_url(
70
123
  Models::Operations::CreateMediaPlaybackIdRequest,
71
124
  base_url,
72
- '/on-demand/{mediaId}/playback-ids',
125
+ PLAYBACK_IDS_PATH,
73
126
  request
74
127
  )
75
128
  headers = {}
76
129
  headers = T.cast(headers, T::Hash[String, String])
77
130
  req_content_type, data, form = Utils.serialize_request_body(request, false, false, :body, :json)
78
- headers['content-type'] = req_content_type
79
- raise StandardError, 'request body is required' if data.nil? && form.nil?
80
-
81
- if form
82
- body = Utils.encode_form(form)
83
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
84
- body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
85
- else
86
- body = data
87
- end
88
- headers['Accept'] = 'application/json'
89
- headers['user-agent'] = @sdk_configuration.user_agent
131
+ headers[REQUEST_CONTENT_TYPE_HEADER] = req_content_type
132
+ body = encode_request_body(req_content_type, data, form)
133
+ headers['Accept'] = CONTENT_TYPE_JSON
134
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
90
135
 
91
136
  security = @sdk_configuration.security_source&.call
92
137
 
@@ -125,32 +170,12 @@ module FastpixClient
125
170
  rescue StandardError => e
126
171
  error = e
127
172
  ensure
128
- if http_response.nil? || Utils.error_status?(http_response.status)
129
- http_response = @sdk_configuration.hooks.after_error(
130
- error: error,
131
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
132
- hook_ctx: hook_ctx
133
- ),
134
- response: http_response
135
- )
136
- else
137
- http_response = @sdk_configuration.hooks.after_success(
138
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
139
- hook_ctx: hook_ctx
140
- ),
141
- response: http_response
142
- )
143
- end
144
-
145
- if http_response.nil?
146
- raise error if !error.nil?
147
- raise 'no response'
148
- end
173
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
149
174
  end
150
175
 
151
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
176
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
152
177
  if Utils.match_status_code(http_response.status, ['201'])
153
- if Utils.match_content_type(content_type, 'application/json')
178
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
154
179
  http_response = @sdk_configuration.hooks.after_success(
155
180
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
156
181
  hook_ctx: hook_ctx
@@ -168,14 +193,14 @@ module FastpixClient
168
193
 
169
194
  return response
170
195
  else
171
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
196
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
172
197
  end
173
198
  elsif Utils.match_status_code(http_response.status, ['4XX'])
174
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
199
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
175
200
  elsif Utils.match_status_code(http_response.status, ['5XX'])
176
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
201
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
177
202
  else
178
- if Utils.match_content_type(content_type, 'application/json')
203
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
179
204
  http_response = @sdk_configuration.hooks.after_success(
180
205
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
181
206
  hook_ctx: hook_ctx
@@ -193,7 +218,7 @@ module FastpixClient
193
218
 
194
219
  return response
195
220
  else
196
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
221
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
197
222
  end
198
223
  end
199
224
  end
@@ -219,13 +244,13 @@ module FastpixClient
219
244
  url = Utils.generate_url(
220
245
  Models::Operations::ListPlaybackIdsRequest,
221
246
  base_url,
222
- '/on-demand/{mediaId}/playback-ids',
247
+ PLAYBACK_IDS_PATH,
223
248
  request
224
249
  )
225
250
  headers = {}
226
251
  headers = T.cast(headers, T::Hash[String, String])
227
- headers['Accept'] = 'application/json'
228
- headers['user-agent'] = @sdk_configuration.user_agent
252
+ headers['Accept'] = CONTENT_TYPE_JSON
253
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
229
254
 
230
255
  security = @sdk_configuration.security_source&.call
231
256
 
@@ -263,32 +288,12 @@ module FastpixClient
263
288
  rescue StandardError => e
264
289
  error = e
265
290
  ensure
266
- if http_response.nil? || Utils.error_status?(http_response.status)
267
- http_response = @sdk_configuration.hooks.after_error(
268
- error: error,
269
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
270
- hook_ctx: hook_ctx
271
- ),
272
- response: http_response
273
- )
274
- else
275
- http_response = @sdk_configuration.hooks.after_success(
276
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
277
- hook_ctx: hook_ctx
278
- ),
279
- response: http_response
280
- )
281
- end
282
-
283
- if http_response.nil?
284
- raise error if !error.nil?
285
- raise 'no response'
286
- end
291
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
287
292
  end
288
293
 
289
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
294
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
290
295
  if Utils.match_status_code(http_response.status, ['200'])
291
- if Utils.match_content_type(content_type, 'application/json')
296
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
292
297
  http_response = @sdk_configuration.hooks.after_success(
293
298
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
294
299
  hook_ctx: hook_ctx
@@ -306,14 +311,14 @@ module FastpixClient
306
311
 
307
312
  return response
308
313
  else
309
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
314
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
310
315
  end
311
316
  elsif Utils.match_status_code(http_response.status, ['4XX'])
312
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
317
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
313
318
  elsif Utils.match_status_code(http_response.status, ['5XX'])
314
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
319
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
315
320
  else
316
- if Utils.match_content_type(content_type, 'application/json')
321
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
317
322
  http_response = @sdk_configuration.hooks.after_success(
318
323
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
319
324
  hook_ctx: hook_ctx
@@ -331,7 +336,7 @@ module FastpixClient
331
336
 
332
337
  return response
333
338
  else
334
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
339
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
335
340
  end
336
341
  end
337
342
  end
@@ -362,14 +367,14 @@ module FastpixClient
362
367
  url = Utils.generate_url(
363
368
  Models::Operations::DeleteMediaPlaybackIdRequest,
364
369
  base_url,
365
- '/on-demand/{mediaId}/playback-ids',
370
+ PLAYBACK_IDS_PATH,
366
371
  request
367
372
  )
368
373
  headers = {}
369
374
  headers = T.cast(headers, T::Hash[String, String])
370
375
  query_params = Utils.get_query_params(Models::Operations::DeleteMediaPlaybackIdRequest, request, nil)
371
- headers['Accept'] = 'application/json'
372
- headers['user-agent'] = @sdk_configuration.user_agent
376
+ headers['Accept'] = CONTENT_TYPE_JSON
377
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
373
378
 
374
379
  security = @sdk_configuration.security_source&.call
375
380
 
@@ -408,32 +413,12 @@ module FastpixClient
408
413
  rescue StandardError => e
409
414
  error = e
410
415
  ensure
411
- if http_response.nil? || Utils.error_status?(http_response.status)
412
- http_response = @sdk_configuration.hooks.after_error(
413
- error: error,
414
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
415
- hook_ctx: hook_ctx
416
- ),
417
- response: http_response
418
- )
419
- else
420
- http_response = @sdk_configuration.hooks.after_success(
421
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
422
- hook_ctx: hook_ctx
423
- ),
424
- response: http_response
425
- )
426
- end
427
-
428
- if http_response.nil?
429
- raise error if !error.nil?
430
- raise 'no response'
431
- end
416
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
432
417
  end
433
418
 
434
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
419
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
435
420
  if Utils.match_status_code(http_response.status, ['200'])
436
- if Utils.match_content_type(content_type, 'application/json')
421
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
437
422
  http_response = @sdk_configuration.hooks.after_success(
438
423
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
439
424
  hook_ctx: hook_ctx
@@ -451,14 +436,14 @@ module FastpixClient
451
436
 
452
437
  return response
453
438
  else
454
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
439
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
455
440
  end
456
441
  elsif Utils.match_status_code(http_response.status, ['4XX'])
457
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
442
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
458
443
  elsif Utils.match_status_code(http_response.status, ['5XX'])
459
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
444
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
460
445
  else
461
- if Utils.match_content_type(content_type, 'application/json')
446
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
462
447
  http_response = @sdk_configuration.hooks.after_success(
463
448
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
464
449
  hook_ctx: hook_ctx
@@ -476,7 +461,7 @@ module FastpixClient
476
461
 
477
462
  return response
478
463
  else
479
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
464
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
480
465
  end
481
466
  end
482
467
  end
@@ -508,8 +493,8 @@ module FastpixClient
508
493
  )
509
494
  headers = {}
510
495
  headers = T.cast(headers, T::Hash[String, String])
511
- headers['Accept'] = 'application/json'
512
- headers['user-agent'] = @sdk_configuration.user_agent
496
+ headers['Accept'] = CONTENT_TYPE_JSON
497
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
513
498
 
514
499
  security = @sdk_configuration.security_source&.call
515
500
 
@@ -547,32 +532,12 @@ module FastpixClient
547
532
  rescue StandardError => e
548
533
  error = e
549
534
  ensure
550
- if http_response.nil? || Utils.error_status?(http_response.status)
551
- http_response = @sdk_configuration.hooks.after_error(
552
- error: error,
553
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
554
- hook_ctx: hook_ctx
555
- ),
556
- response: http_response
557
- )
558
- else
559
- http_response = @sdk_configuration.hooks.after_success(
560
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
561
- hook_ctx: hook_ctx
562
- ),
563
- response: http_response
564
- )
565
- end
566
-
567
- if http_response.nil?
568
- raise error if !error.nil?
569
- raise 'no response'
570
- end
535
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
571
536
  end
572
537
 
573
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
538
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
574
539
  if Utils.match_status_code(http_response.status, ['200'])
575
- if Utils.match_content_type(content_type, 'application/json')
540
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
576
541
  http_response = @sdk_configuration.hooks.after_success(
577
542
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
578
543
  hook_ctx: hook_ctx
@@ -590,14 +555,14 @@ module FastpixClient
590
555
 
591
556
  return response
592
557
  else
593
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
558
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
594
559
  end
595
560
  elsif Utils.match_status_code(http_response.status, ['4XX'])
596
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
561
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
597
562
  elsif Utils.match_status_code(http_response.status, ['5XX'])
598
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
563
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
599
564
  else
600
- if Utils.match_content_type(content_type, 'application/json')
565
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
601
566
  http_response = @sdk_configuration.hooks.after_success(
602
567
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
603
568
  hook_ctx: hook_ctx
@@ -615,7 +580,7 @@ module FastpixClient
615
580
 
616
581
  return response
617
582
  else
618
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
583
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
619
584
  end
620
585
  end
621
586
  end
@@ -651,18 +616,10 @@ module FastpixClient
651
616
  headers = {}
652
617
  headers = T.cast(headers, T::Hash[String, String])
653
618
  req_content_type, data, form = Utils.serialize_request_body(request, false, false, :body, :json)
654
- headers['content-type'] = req_content_type
655
- raise StandardError, 'request body is required' if data.nil? && form.nil?
656
-
657
- if form
658
- body = Utils.encode_form(form)
659
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
660
- body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
661
- else
662
- body = data
663
- end
664
- headers['Accept'] = 'application/json'
665
- headers['user-agent'] = @sdk_configuration.user_agent
619
+ headers[REQUEST_CONTENT_TYPE_HEADER] = req_content_type
620
+ body = encode_request_body(req_content_type, data, form)
621
+ headers['Accept'] = CONTENT_TYPE_JSON
622
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
666
623
 
667
624
  security = @sdk_configuration.security_source&.call
668
625
 
@@ -701,32 +658,12 @@ module FastpixClient
701
658
  rescue StandardError => e
702
659
  error = e
703
660
  ensure
704
- if http_response.nil? || Utils.error_status?(http_response.status)
705
- http_response = @sdk_configuration.hooks.after_error(
706
- error: error,
707
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
708
- hook_ctx: hook_ctx
709
- ),
710
- response: http_response
711
- )
712
- else
713
- http_response = @sdk_configuration.hooks.after_success(
714
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
715
- hook_ctx: hook_ctx
716
- ),
717
- response: http_response
718
- )
719
- end
720
-
721
- if http_response.nil?
722
- raise error if !error.nil?
723
- raise 'no response'
724
- end
661
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
725
662
  end
726
663
 
727
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
664
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
728
665
  if Utils.match_status_code(http_response.status, ['200'])
729
- if Utils.match_content_type(content_type, 'application/json')
666
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
730
667
  http_response = @sdk_configuration.hooks.after_success(
731
668
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
732
669
  hook_ctx: hook_ctx
@@ -744,14 +681,14 @@ module FastpixClient
744
681
 
745
682
  return response
746
683
  else
747
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
684
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
748
685
  end
749
686
  elsif Utils.match_status_code(http_response.status, ['4XX'])
750
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
687
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
751
688
  elsif Utils.match_status_code(http_response.status, ['5XX'])
752
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
689
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
753
690
  else
754
- if Utils.match_content_type(content_type, 'application/json')
691
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
755
692
  http_response = @sdk_configuration.hooks.after_success(
756
693
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
757
694
  hook_ctx: hook_ctx
@@ -769,7 +706,7 @@ module FastpixClient
769
706
 
770
707
  return response
771
708
  else
772
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
709
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
773
710
  end
774
711
  end
775
712
  end
@@ -805,18 +742,10 @@ module FastpixClient
805
742
  headers = {}
806
743
  headers = T.cast(headers, T::Hash[String, String])
807
744
  req_content_type, data, form = Utils.serialize_request_body(request, false, false, :body, :json)
808
- headers['content-type'] = req_content_type
809
- raise StandardError, 'request body is required' if data.nil? && form.nil?
810
-
811
- if form
812
- body = Utils.encode_form(form)
813
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
814
- body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
815
- else
816
- body = data
817
- end
818
- headers['Accept'] = 'application/json'
819
- headers['user-agent'] = @sdk_configuration.user_agent
745
+ headers[REQUEST_CONTENT_TYPE_HEADER] = req_content_type
746
+ body = encode_request_body(req_content_type, data, form)
747
+ headers['Accept'] = CONTENT_TYPE_JSON
748
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
820
749
 
821
750
  security = @sdk_configuration.security_source&.call
822
751
 
@@ -855,32 +784,12 @@ module FastpixClient
855
784
  rescue StandardError => e
856
785
  error = e
857
786
  ensure
858
- if http_response.nil? || Utils.error_status?(http_response.status)
859
- http_response = @sdk_configuration.hooks.after_error(
860
- error: error,
861
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
862
- hook_ctx: hook_ctx
863
- ),
864
- response: http_response
865
- )
866
- else
867
- http_response = @sdk_configuration.hooks.after_success(
868
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
869
- hook_ctx: hook_ctx
870
- ),
871
- response: http_response
872
- )
873
- end
874
-
875
- if http_response.nil?
876
- raise error if !error.nil?
877
- raise 'no response'
878
- end
787
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
879
788
  end
880
789
 
881
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
790
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
882
791
  if Utils.match_status_code(http_response.status, ['200'])
883
- if Utils.match_content_type(content_type, 'application/json')
792
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
884
793
  http_response = @sdk_configuration.hooks.after_success(
885
794
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
886
795
  hook_ctx: hook_ctx
@@ -898,14 +807,14 @@ module FastpixClient
898
807
 
899
808
  return response
900
809
  else
901
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
810
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
902
811
  end
903
812
  elsif Utils.match_status_code(http_response.status, ['4XX'])
904
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
813
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
905
814
  elsif Utils.match_status_code(http_response.status, ['5XX'])
906
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
815
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
907
816
  else
908
- if Utils.match_content_type(content_type, 'application/json')
817
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
909
818
  http_response = @sdk_configuration.hooks.after_success(
910
819
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
911
820
  hook_ctx: hook_ctx
@@ -923,7 +832,7 @@ module FastpixClient
923
832
 
924
833
  return response
925
834
  else
926
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
835
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), UNKNOWN_CONTENT_TYPE_ERROR
927
836
  end
928
837
  end
929
838
  end