fastpixapi 1.1.2 → 1.1.4

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 (112) 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 +54 -61
  6. data/lib/fastpix_client/drm_configurations.rb +49 -56
  7. data/lib/fastpix_client/errors.rb +36 -25
  8. data/lib/fastpix_client/fastpixapi.rb +2 -4
  9. data/lib/fastpix_client/in_video_ai_features.rb +108 -168
  10. data/lib/fastpix_client/input_video.rb +70 -77
  11. data/lib/fastpix_client/live_playback.rb +82 -99
  12. data/lib/fastpix_client/manage_live_stream.rb +149 -264
  13. data/lib/fastpix_client/manage_videos.rb +249 -566
  14. data/lib/fastpix_client/metrics.rb +79 -123
  15. data/lib/fastpix_client/models/components/addtrackrequest.rb +6 -2
  16. data/lib/fastpix_client/models/components/addtrackrequest.rbi +2 -0
  17. data/lib/fastpix_client/models/components/addtrackresponse.rb +6 -2
  18. data/lib/fastpix_client/models/components/addtrackresponse.rbi +2 -0
  19. data/lib/fastpix_client/models/components/audiotrack.rb +6 -2
  20. data/lib/fastpix_client/models/components/audiotrack.rbi +2 -0
  21. data/lib/fastpix_client/models/components/createlivestreamresponsedto.rb +10 -18
  22. data/lib/fastpix_client/models/components/createmediarequest.rb +9 -18
  23. data/lib/fastpix_client/models/components/generatetrackresponse.rb +6 -2
  24. data/lib/fastpix_client/models/components/generatetrackresponse.rbi +2 -0
  25. data/lib/fastpix_client/models/components/getallmediaresponse.rb +20 -38
  26. data/lib/fastpix_client/models/components/getallmediaresponse.rbi +2 -0
  27. data/lib/fastpix_client/models/components/getallmediaresponse_mp4support.rb +32 -12
  28. data/lib/fastpix_client/models/components/getallmediaresponse_mp4support.rbi +11 -1
  29. data/lib/fastpix_client/models/components/getallmediaresponse_sourceresolution.rb +2 -0
  30. data/lib/fastpix_client/models/components/getcreatelivestreamresponsedto.rb +9 -20
  31. data/lib/fastpix_client/models/components/{getmediaresponse.rb → getmediadetailresponse.rb} +25 -43
  32. data/lib/fastpix_client/models/components/{getmediaresponse.rbi → getmediadetailresponse.rbi} +4 -2
  33. data/lib/fastpix_client/models/components/{getmediaresponse_maxresolution.rb → getmediadetailresponse_maxresolution.rb} +2 -2
  34. data/lib/fastpix_client/models/components/getmediadetailresponse_maxresolution.rbi +11 -0
  35. data/lib/fastpix_client/models/components/{getmediaresponse_mediaquality.rb → getmediadetailresponse_mediaquality.rb} +2 -2
  36. data/lib/fastpix_client/models/components/getmediadetailresponse_mediaquality.rbi +11 -0
  37. data/lib/fastpix_client/models/components/getmediadetailresponse_mp4support.rb +48 -0
  38. data/lib/fastpix_client/models/components/getmediadetailresponse_mp4support.rbi +21 -0
  39. data/lib/fastpix_client/models/components/{getmediaresponse_sourceresolution.rb → getmediadetailresponse_sourceresolution.rb} +4 -2
  40. data/lib/fastpix_client/models/components/getmediadetailresponse_sourceresolution.rbi +11 -0
  41. data/lib/fastpix_client/models/components/{getmediaresponse_status.rb → getmediadetailresponse_status.rb} +2 -2
  42. data/lib/fastpix_client/models/components/getmediadetailresponse_status.rbi +11 -0
  43. data/lib/fastpix_client/models/components/{getmediaresponse_track.rb → getmediadetailresponse_track.rb} +1 -1
  44. data/lib/fastpix_client/models/components/getmediadetailresponse_track.rbi +11 -0
  45. data/lib/fastpix_client/models/components/live_media_clips.rb +16 -30
  46. data/lib/fastpix_client/models/components/live_media_clips.rbi +2 -0
  47. data/lib/fastpix_client/models/components/live_media_clips_mp4support.rb +32 -12
  48. data/lib/fastpix_client/models/components/live_media_clips_mp4support.rbi +11 -1
  49. data/lib/fastpix_client/models/components/live_media_clips_sourceresolution.rb +2 -0
  50. data/lib/fastpix_client/models/components/media.rb +18 -35
  51. data/lib/fastpix_client/models/components/media.rbi +2 -0
  52. data/lib/fastpix_client/models/components/media_mp4support.rb +32 -12
  53. data/lib/fastpix_client/models/components/media_mp4support.rbi +11 -1
  54. data/lib/fastpix_client/models/components/media_sourceresolution.rb +2 -0
  55. data/lib/fastpix_client/models/components/patchresponsedata.rb +9 -18
  56. data/lib/fastpix_client/models/components/sourceaccessmedia.rb +18 -35
  57. data/lib/fastpix_client/models/components/sourceaccessmedia.rbi +2 -0
  58. data/lib/fastpix_client/models/components/sourceaccessmedia_mp4support.rb +32 -12
  59. data/lib/fastpix_client/models/components/sourceaccessmedia_mp4support.rbi +11 -1
  60. data/lib/fastpix_client/models/components/sourceaccessmedia_sourceresolution.rb +2 -0
  61. data/lib/fastpix_client/models/components/subtitletrack.rb +6 -2
  62. data/lib/fastpix_client/models/components/subtitletrack.rbi +2 -0
  63. data/lib/fastpix_client/models/components/tracksubtitlesgeneraterequest.rb +6 -2
  64. data/lib/fastpix_client/models/components/tracksubtitlesgeneraterequest.rbi +2 -0
  65. data/lib/fastpix_client/models/components/update_media.rb +18 -35
  66. data/lib/fastpix_client/models/components/update_media.rbi +2 -0
  67. data/lib/fastpix_client/models/components/update_media_maxresolution.rb +0 -1
  68. data/lib/fastpix_client/models/components/update_media_mp4support.rb +32 -12
  69. data/lib/fastpix_client/models/components/update_media_mp4support.rbi +11 -1
  70. data/lib/fastpix_client/models/components/updatetrackrequest.rb +7 -7
  71. data/lib/fastpix_client/models/components/updatetrackrequest.rbi +2 -2
  72. data/lib/fastpix_client/models/components/updatetrackresponse.rb +6 -2
  73. data/lib/fastpix_client/models/components/updatetrackresponse.rbi +2 -0
  74. data/lib/fastpix_client/models/components/videotrack.rb +6 -2
  75. data/lib/fastpix_client/models/components/videotrack.rbi +2 -0
  76. data/lib/fastpix_client/models/components/videotrackforgetall.rb +6 -2
  77. data/lib/fastpix_client/models/components/videotrackforgetall.rbi +2 -0
  78. data/lib/fastpix_client/models/components/views.rb +51 -124
  79. data/lib/fastpix_client/models/components.rb +7 -7
  80. data/lib/fastpix_client/models/errors/empty_response_error.rb +15 -0
  81. data/lib/fastpix_client/models/errors.rb +1 -0
  82. data/lib/fastpix_client/models/operations/get_media_response.rb +1 -1
  83. data/lib/fastpix_client/models/operations/get_media_responsebody.rb +2 -2
  84. data/lib/fastpix_client/models/operations/push_media_settings.rb +9 -20
  85. data/lib/fastpix_client/playback.rb +122 -213
  86. data/lib/fastpix_client/playlist.rb +152 -297
  87. data/lib/fastpix_client/sdk_hooks/registration.rb +2 -2
  88. data/lib/fastpix_client/sdk_hooks/types.rb +4 -0
  89. data/lib/fastpix_client/sdkconfiguration.rb +3 -3
  90. data/lib/fastpix_client/signing_keys.rb +76 -120
  91. data/lib/fastpix_client/simulcast_stream.rb +100 -144
  92. data/lib/fastpix_client/start_live_stream.rb +55 -37
  93. data/lib/fastpix_client/utils/forms.rb +97 -101
  94. data/lib/fastpix_client/utils/headers.rb +44 -34
  95. data/lib/fastpix_client/utils/query_params.rb +39 -29
  96. data/lib/fastpix_client/utils/request_bodies.rb +4 -8
  97. data/lib/fastpix_client/utils/security.rb +30 -18
  98. data/lib/fastpix_client/utils/url.rb +83 -60
  99. data/lib/fastpix_client/utils/utils.rb +19 -37
  100. data/lib/fastpix_client/views.rb +69 -93
  101. data/lib/fastpixapi.rb +10 -10
  102. data/lib/openssl_patch.rb +24 -24
  103. metadata +17 -18
  104. data/lib/fastpix_client/models/components/getmediaresponse_maxresolution.rbi +0 -11
  105. data/lib/fastpix_client/models/components/getmediaresponse_mediaquality.rbi +0 -11
  106. data/lib/fastpix_client/models/components/getmediaresponse_mp4support.rb +0 -28
  107. data/lib/fastpix_client/models/components/getmediaresponse_mp4support.rbi +0 -11
  108. data/lib/fastpix_client/models/components/getmediaresponse_sourceresolution.rbi +0 -11
  109. data/lib/fastpix_client/models/components/getmediaresponse_status.rbi +0 -11
  110. data/lib/fastpix_client/models/components/getmediaresponse_track.rbi +0 -11
  111. data/test/sdk_examples_test.rb +0 -20
  112. data/test/test_helper.rb +0 -29
@@ -14,6 +14,54 @@ module FastpixClient
14
14
  extend T::Sig
15
15
  class InputVideo
16
16
  extend T::Sig
17
+
18
+ API_ERROR_OCCURRED = 'API error occurred'
19
+ CONTENT_TYPE_JSON = 'application/json'
20
+ UNKNOWN_CONTENT_TYPE_ERROR = 'Unknown content type received'
21
+
22
+ # Applies the SDK after-request hooks and ensures a usable response is present.
23
+ sig { params(http_response: T.nilable(Faraday::Response), error: T.nilable(StandardError), hook_ctx: SDKHooks::HookContext).returns(Faraday::Response) }
24
+ def apply_after_request_hooks(http_response, error, hook_ctx)
25
+ if http_response.nil? || Utils.error_status?(http_response.status)
26
+ http_response = @sdk_configuration.hooks.after_error(
27
+ error: error,
28
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
29
+ hook_ctx: hook_ctx
30
+ ),
31
+ response: http_response
32
+ )
33
+ else
34
+ http_response = @sdk_configuration.hooks.after_success(
35
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
36
+ hook_ctx: hook_ctx
37
+ ),
38
+ response: http_response
39
+ )
40
+ end
41
+
42
+ if http_response.nil?
43
+ raise error unless error.nil?
44
+ raise ::FastpixClient::Models::Errors::EmptyResponseError, 'no response'
45
+ end
46
+
47
+ http_response
48
+ end
49
+ private :apply_after_request_hooks
50
+
51
+ # Encodes the request body based on its serialized content type.
52
+ sig { params(req_content_type: T.nilable(String), data: T.untyped, form: T.untyped).returns(T.untyped) }
53
+ def encode_request_body(req_content_type, data, form)
54
+ raise ArgumentError, 'request body is required' if data.nil? && form.nil?
55
+
56
+ if form
57
+ Utils.encode_form(form)
58
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
59
+ URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
60
+ else
61
+ data
62
+ end
63
+ end
64
+ private :encode_request_body
17
65
 
18
66
  # Operations for inputting and creating video media
19
67
 
@@ -79,10 +127,11 @@ module FastpixClient
79
127
  #
80
128
  # 4. Use the id in subsequent API calls, such as checking the status of the media with the <a href="https://fastpix.com/docs/video-on-demand-api/manage-videos/get-media">Get Media by ID</a> endpoint to determine when the media is ready for playback.
81
129
  #
82
- # FastPix uses webhooks to tell your application about things that happen in the background, outside of the API regular request flow. For instance, after the media file is created (but not yet processed or encoded), FastPix sends a `POST` request to your specified webhook URL with the event <a href="https://fastpix.com/docs/vod-events/media-events#videomediacreated">video.media.created</a>.
130
+ # FastPix uses webhooks to tell your application about things that happen in the background, outside of the API regular request flow. For instance, after the media file is created (but not yet processed or encoded), FastPix sends a `POST` request to your specified webhook URL with the event <a href="https://fastpix.com/docs/webhooks/media-events#videomediacreated">video.media.created</a>.
83
131
  #
84
132
  #
85
- # After processing completes, monitor the events <a href="https://fastpix.com/docs/vod-events/media-events#videomediaready">video.media.ready</a> and <a href="https://fastpix.com/docs/vod-events/media-events#videomediafailed">video.media.failed</a> to track the status of the media file.
133
+ # After processing completes, monitor the events <a href="https://fastpix.com/docs/webhooks/media-events#videomediaready">video.media.ready</a> and <a href="https://fastpix.com/docs/webhooks/media-events#videomediafailed">video.media.failed</a> to track the status of the media file.
134
+
86
135
  #
87
136
  # Related guide: <a href="https://fastpix.com/docs/upload-videos/upload-videos-from-a-url">Upload videos from URL</a>
88
137
  #
@@ -93,16 +142,8 @@ module FastpixClient
93
142
  headers = T.cast(headers, T::Hash[String, String])
94
143
  req_content_type, data, form = Utils.serialize_request_body(request, false, false, :request, :json)
95
144
  headers['content-type'] = req_content_type
96
- raise StandardError, 'request body is required' if data.nil? && form.nil?
97
-
98
- if form
99
- body = Utils.encode_form(form)
100
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
101
- body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
102
- else
103
- body = data
104
- end
105
- headers['Accept'] = 'application/json'
145
+ body = encode_request_body(req_content_type, data, form)
146
+ headers['Accept'] = CONTENT_TYPE_JSON
106
147
  headers['user-agent'] = @sdk_configuration.user_agent
107
148
 
108
149
  security = @sdk_configuration.security_source&.call
@@ -142,32 +183,12 @@ module FastpixClient
142
183
  rescue StandardError => e
143
184
  error = e
144
185
  ensure
145
- if http_response.nil? || Utils.error_status?(http_response.status)
146
- http_response = @sdk_configuration.hooks.after_error(
147
- error: error,
148
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
149
- hook_ctx: hook_ctx
150
- ),
151
- response: http_response
152
- )
153
- else
154
- http_response = @sdk_configuration.hooks.after_success(
155
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
156
- hook_ctx: hook_ctx
157
- ),
158
- response: http_response
159
- )
160
- end
161
-
162
- if http_response.nil?
163
- raise error if !error.nil?
164
- raise 'no response'
165
- end
186
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
166
187
  end
167
188
 
168
189
  content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
169
190
  if Utils.match_status_code(http_response.status, ['201'])
170
- if Utils.match_content_type(content_type, 'application/json')
191
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
171
192
  http_response = @sdk_configuration.hooks.after_success(
172
193
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
173
194
  hook_ctx: hook_ctx
@@ -185,14 +206,14 @@ module FastpixClient
185
206
 
186
207
  return response
187
208
  else
188
- 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'
209
+ 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
189
210
  end
190
211
  elsif Utils.match_status_code(http_response.status, ['4XX'])
191
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
212
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
192
213
  elsif Utils.match_status_code(http_response.status, ['5XX'])
193
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
214
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
194
215
  else
195
- if Utils.match_content_type(content_type, 'application/json')
216
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
196
217
  http_response = @sdk_configuration.hooks.after_success(
197
218
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
198
219
  hook_ctx: hook_ctx
@@ -210,7 +231,7 @@ module FastpixClient
210
231
 
211
232
  return response
212
233
  else
213
- 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'
234
+ 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
214
235
  end
215
236
  end
216
237
  end
@@ -231,7 +252,7 @@ module FastpixClient
231
252
  #
232
253
  # 2. The response includes an `uploadId` and a signed `url` for direct video file upload.
233
254
  #
234
- # 3. Upload your video file to the provided url by making a PUT request. The API accepts the media file from your device and uploads it to the FastPix platform. (Refer to <a href="https://fastpix.com/docs/upload-videos/upload-videos-from-device#step-3-initiate-the-upload">Step 3: Initiate the upload</a> for complete instructions.)
255
+ # 3. Upload your video file to the provided url by making a PUT request. The API accepts the media file from your device and uploads it to the FastPix platform. (Refer to <a href="https://fastpix.com/docs/upload-videos/upload-videos-from-device#initiate-the-upload-session-web-only">Step 3: Initiate the upload</a> for complete instructions.)
235
256
  #
236
257
  #
237
258
  # 4. Once uploaded, the media undergoes processing and is assigned a unique ID for tracking. Retain this `uploadId` for any future operations related to this upload.
@@ -256,16 +277,8 @@ module FastpixClient
256
277
  headers = T.cast(headers, T::Hash[String, String])
257
278
  req_content_type, data, form = Utils.serialize_request_body(request, false, false, :request, :json)
258
279
  headers['content-type'] = req_content_type
259
- raise StandardError, 'request body is required' if data.nil? && form.nil?
260
-
261
- if form
262
- body = Utils.encode_form(form)
263
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
264
- body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
265
- else
266
- body = data
267
- end
268
- headers['Accept'] = 'application/json'
280
+ body = encode_request_body(req_content_type, data, form)
281
+ headers['Accept'] = CONTENT_TYPE_JSON
269
282
  headers['user-agent'] = @sdk_configuration.user_agent
270
283
 
271
284
  security = @sdk_configuration.security_source&.call
@@ -305,32 +318,12 @@ module FastpixClient
305
318
  rescue StandardError => e
306
319
  error = e
307
320
  ensure
308
- if http_response.nil? || Utils.error_status?(http_response.status)
309
- http_response = @sdk_configuration.hooks.after_error(
310
- error: error,
311
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
312
- hook_ctx: hook_ctx
313
- ),
314
- response: http_response
315
- )
316
- else
317
- http_response = @sdk_configuration.hooks.after_success(
318
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
319
- hook_ctx: hook_ctx
320
- ),
321
- response: http_response
322
- )
323
- end
324
-
325
- if http_response.nil?
326
- raise error if !error.nil?
327
- raise 'no response'
328
- end
321
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
329
322
  end
330
323
 
331
324
  content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
332
325
  if Utils.match_status_code(http_response.status, ['201'])
333
- if Utils.match_content_type(content_type, 'application/json')
326
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
334
327
  http_response = @sdk_configuration.hooks.after_success(
335
328
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
336
329
  hook_ctx: hook_ctx
@@ -348,14 +341,14 @@ module FastpixClient
348
341
 
349
342
  return response
350
343
  else
351
- 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'
344
+ 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
352
345
  end
353
346
  elsif Utils.match_status_code(http_response.status, ['4XX'])
354
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
347
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
355
348
  elsif Utils.match_status_code(http_response.status, ['5XX'])
356
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
349
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
357
350
  else
358
- if Utils.match_content_type(content_type, 'application/json')
351
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
359
352
  http_response = @sdk_configuration.hooks.after_success(
360
353
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
361
354
  hook_ctx: hook_ctx
@@ -373,7 +366,7 @@ module FastpixClient
373
366
 
374
367
  return response
375
368
  else
376
- 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'
369
+ 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
377
370
  end
378
371
  end
379
372
  end
@@ -14,6 +14,57 @@ module FastpixClient
14
14
  extend T::Sig
15
15
  class LivePlayback
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
+ UNKNOWN_CONTENT_TYPE_ERROR = 'Unknown content type received'
23
+ USER_AGENT_HEADER = 'user-agent'
24
+
25
+ # Applies the SDK after-request hooks and ensures a usable response is present.
26
+ sig { params(http_response: T.nilable(Faraday::Response), error: T.nilable(StandardError), hook_ctx: SDKHooks::HookContext).returns(Faraday::Response) }
27
+ def apply_after_request_hooks(http_response, error, hook_ctx)
28
+ if http_response.nil? || Utils.error_status?(http_response.status)
29
+ http_response = @sdk_configuration.hooks.after_error(
30
+ error: error,
31
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
32
+ hook_ctx: hook_ctx
33
+ ),
34
+ response: http_response
35
+ )
36
+ else
37
+ http_response = @sdk_configuration.hooks.after_success(
38
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
39
+ hook_ctx: hook_ctx
40
+ ),
41
+ response: http_response
42
+ )
43
+ end
44
+
45
+ if http_response.nil?
46
+ raise error unless error.nil?
47
+ raise ::FastpixClient::Models::Errors::EmptyResponseError, 'no response'
48
+ end
49
+
50
+ http_response
51
+ end
52
+ private :apply_after_request_hooks
53
+
54
+ # Encodes the request body based on its serialized content type.
55
+ sig { params(req_content_type: T.nilable(String), data: T.untyped, form: T.untyped).returns(T.untyped) }
56
+ def encode_request_body(req_content_type, data, form)
57
+ raise ArgumentError, 'request body is required' if data.nil? && form.nil?
58
+
59
+ if form
60
+ Utils.encode_form(form)
61
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
62
+ URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
63
+ else
64
+ data
65
+ end
66
+ end
67
+ private :encode_request_body
17
68
 
18
69
  # Operations for live stream playback management
19
70
 
@@ -65,17 +116,9 @@ module FastpixClient
65
116
  headers = T.cast(headers, T::Hash[String, String])
66
117
  req_content_type, data, form = Utils.serialize_request_body(request, false, false, :body, :json)
67
118
  headers['content-type'] = req_content_type
68
- raise StandardError, 'request body is required' if data.nil? && form.nil?
69
-
70
- if form
71
- body = Utils.encode_form(form)
72
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
73
- body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
74
- else
75
- body = data
76
- end
77
- headers['Accept'] = 'application/json'
78
- headers['user-agent'] = @sdk_configuration.user_agent
119
+ body = encode_request_body(req_content_type, data, form)
120
+ headers['Accept'] = CONTENT_TYPE_JSON
121
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
79
122
 
80
123
  security = @sdk_configuration.security_source&.call
81
124
 
@@ -114,32 +157,12 @@ module FastpixClient
114
157
  rescue StandardError => e
115
158
  error = e
116
159
  ensure
117
- if http_response.nil? || Utils.error_status?(http_response.status)
118
- http_response = @sdk_configuration.hooks.after_error(
119
- error: error,
120
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
121
- hook_ctx: hook_ctx
122
- ),
123
- response: http_response
124
- )
125
- else
126
- http_response = @sdk_configuration.hooks.after_success(
127
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
128
- hook_ctx: hook_ctx
129
- ),
130
- response: http_response
131
- )
132
- end
133
-
134
- if http_response.nil?
135
- raise error if !error.nil?
136
- raise 'no response'
137
- end
160
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
138
161
  end
139
162
 
140
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
163
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
141
164
  if Utils.match_status_code(http_response.status, ['201'])
142
- if Utils.match_content_type(content_type, 'application/json')
165
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
143
166
  http_response = @sdk_configuration.hooks.after_success(
144
167
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
145
168
  hook_ctx: hook_ctx
@@ -157,14 +180,14 @@ module FastpixClient
157
180
 
158
181
  return response
159
182
  else
160
- 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'
183
+ 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
161
184
  end
162
185
  elsif Utils.match_status_code(http_response.status, ['4XX'])
163
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
186
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
164
187
  elsif Utils.match_status_code(http_response.status, ['5XX'])
165
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
188
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
166
189
  else
167
- if Utils.match_content_type(content_type, 'application/json')
190
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
168
191
  http_response = @sdk_configuration.hooks.after_success(
169
192
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
170
193
  hook_ctx: hook_ctx
@@ -182,7 +205,7 @@ module FastpixClient
182
205
 
183
206
  return response
184
207
  else
185
- 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'
208
+ 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
186
209
  end
187
210
  end
188
211
  end
@@ -210,8 +233,8 @@ module FastpixClient
210
233
  headers = {}
211
234
  headers = T.cast(headers, T::Hash[String, String])
212
235
  query_params = Utils.get_query_params(Models::Operations::DeletePlaybackIdOfStreamRequest, request, nil)
213
- headers['Accept'] = 'application/json'
214
- headers['user-agent'] = @sdk_configuration.user_agent
236
+ headers['Accept'] = CONTENT_TYPE_JSON
237
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
215
238
 
216
239
  security = @sdk_configuration.security_source&.call
217
240
 
@@ -250,32 +273,12 @@ module FastpixClient
250
273
  rescue StandardError => e
251
274
  error = e
252
275
  ensure
253
- if http_response.nil? || Utils.error_status?(http_response.status)
254
- http_response = @sdk_configuration.hooks.after_error(
255
- error: error,
256
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
257
- hook_ctx: hook_ctx
258
- ),
259
- response: http_response
260
- )
261
- else
262
- http_response = @sdk_configuration.hooks.after_success(
263
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
264
- hook_ctx: hook_ctx
265
- ),
266
- response: http_response
267
- )
268
- end
269
-
270
- if http_response.nil?
271
- raise error if !error.nil?
272
- raise 'no response'
273
- end
276
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
274
277
  end
275
278
 
276
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
279
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
277
280
  if Utils.match_status_code(http_response.status, ['200'])
278
- if Utils.match_content_type(content_type, 'application/json')
281
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
279
282
  http_response = @sdk_configuration.hooks.after_success(
280
283
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
281
284
  hook_ctx: hook_ctx
@@ -293,14 +296,14 @@ module FastpixClient
293
296
 
294
297
  return response
295
298
  else
296
- 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'
299
+ 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
297
300
  end
298
301
  elsif Utils.match_status_code(http_response.status, ['4XX'])
299
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
302
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
300
303
  elsif Utils.match_status_code(http_response.status, ['5XX'])
301
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
304
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
302
305
  else
303
- if Utils.match_content_type(content_type, 'application/json')
306
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
304
307
  http_response = @sdk_configuration.hooks.after_success(
305
308
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
306
309
  hook_ctx: hook_ctx
@@ -318,7 +321,7 @@ module FastpixClient
318
321
 
319
322
  return response
320
323
  else
321
- 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'
324
+ 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
322
325
  end
323
326
  end
324
327
  end
@@ -345,8 +348,8 @@ module FastpixClient
345
348
  )
346
349
  headers = {}
347
350
  headers = T.cast(headers, T::Hash[String, String])
348
- headers['Accept'] = 'application/json'
349
- headers['user-agent'] = @sdk_configuration.user_agent
351
+ headers['Accept'] = CONTENT_TYPE_JSON
352
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
350
353
 
351
354
  security = @sdk_configuration.security_source&.call
352
355
 
@@ -384,32 +387,12 @@ module FastpixClient
384
387
  rescue StandardError => e
385
388
  error = e
386
389
  ensure
387
- if http_response.nil? || Utils.error_status?(http_response.status)
388
- http_response = @sdk_configuration.hooks.after_error(
389
- error: error,
390
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
391
- hook_ctx: hook_ctx
392
- ),
393
- response: http_response
394
- )
395
- else
396
- http_response = @sdk_configuration.hooks.after_success(
397
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
398
- hook_ctx: hook_ctx
399
- ),
400
- response: http_response
401
- )
402
- end
403
-
404
- if http_response.nil?
405
- raise error if !error.nil?
406
- raise 'no response'
407
- end
390
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
408
391
  end
409
392
 
410
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
393
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
411
394
  if Utils.match_status_code(http_response.status, ['200'])
412
- if Utils.match_content_type(content_type, 'application/json')
395
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
413
396
  http_response = @sdk_configuration.hooks.after_success(
414
397
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
415
398
  hook_ctx: hook_ctx
@@ -427,14 +410,14 @@ module FastpixClient
427
410
 
428
411
  return response
429
412
  else
430
- 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'
413
+ 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
431
414
  end
432
415
  elsif Utils.match_status_code(http_response.status, ['4XX'])
433
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
416
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
434
417
  elsif Utils.match_status_code(http_response.status, ['5XX'])
435
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
418
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
436
419
  else
437
- if Utils.match_content_type(content_type, 'application/json')
420
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
438
421
  http_response = @sdk_configuration.hooks.after_success(
439
422
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
440
423
  hook_ctx: hook_ctx
@@ -452,7 +435,7 @@ module FastpixClient
452
435
 
453
436
  return response
454
437
  else
455
- 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'
438
+ 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
456
439
  end
457
440
  end
458
441
  end