fastpixapi 1.1.1 → 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 (122) 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 +55 -62
  6. data/lib/fastpix_client/drm_configurations.rb +51 -58
  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 +75 -83
  11. data/lib/fastpix_client/live_playback.rb +82 -99
  12. data/lib/fastpix_client/manage_live_stream.rb +145 -261
  13. data/lib/fastpix_client/manage_videos.rb +252 -567
  14. data/lib/fastpix_client/metrics.rb +82 -126
  15. data/lib/fastpix_client/models/components/addtrackrequest.rb +1 -1
  16. data/lib/fastpix_client/models/components/createlivestreamresponsedto.rb +10 -18
  17. data/lib/fastpix_client/models/components/createmediarequest.rb +10 -19
  18. data/lib/fastpix_client/models/components/deletesigningkeyresponse.rb +6 -2
  19. data/lib/fastpix_client/models/components/deletesigningkeyresponsedata.rb +33 -0
  20. data/lib/fastpix_client/models/components/getallmediaresponse.rb +13 -29
  21. data/lib/fastpix_client/models/components/getcreatelivestreamresponsedto.rb +9 -20
  22. data/lib/fastpix_client/models/components/getmediaresponse.rb +13 -29
  23. data/lib/fastpix_client/models/components/live_media_clips.rb +9 -21
  24. data/lib/fastpix_client/models/components/media.rb +11 -26
  25. data/lib/fastpix_client/models/components/patchresponsedata.rb +9 -18
  26. data/lib/fastpix_client/models/components/pullvideoinput.rb +1 -1
  27. data/lib/fastpix_client/models/components/sourceaccessmedia.rb +11 -26
  28. data/lib/fastpix_client/models/components/update_media.rb +11 -26
  29. data/lib/fastpix_client/models/components/views.rb +52 -125
  30. data/lib/fastpix_client/models/components/watermarkinput.rb +1 -1
  31. data/lib/fastpix_client/models/components.rb +1 -0
  32. data/lib/fastpix_client/models/errors/empty_response_error.rb +15 -0
  33. data/lib/fastpix_client/models/errors.rb +1 -0
  34. data/lib/fastpix_client/models/operations/add_media_to_playlist_response.rb +1 -1
  35. data/lib/fastpix_client/models/operations/add_media_track_response.rb +1 -1
  36. data/lib/fastpix_client/models/operations/cancel_upload_response.rb +1 -1
  37. data/lib/fastpix_client/models/operations/change_media_order_in_playlist_response.rb +1 -1
  38. data/lib/fastpix_client/models/operations/complete_live_stream_response.rb +1 -1
  39. data/lib/fastpix_client/models/operations/create_a_playlist_response.rb +1 -1
  40. data/lib/fastpix_client/models/operations/create_media_playback_id_response.rb +1 -1
  41. data/lib/fastpix_client/models/operations/create_media_response.rb +1 -1
  42. data/lib/fastpix_client/models/operations/create_new_stream_response.rb +1 -1
  43. data/lib/fastpix_client/models/operations/create_playbackid_of_stream_response.rb +1 -1
  44. data/lib/fastpix_client/models/operations/create_signing_key_response.rb +1 -1
  45. data/lib/fastpix_client/models/operations/create_simulcast_of_stream_response.rb +1 -1
  46. data/lib/fastpix_client/models/operations/delete_a_playlist_response.rb +1 -1
  47. data/lib/fastpix_client/models/operations/delete_live_stream_response.rb +1 -1
  48. data/lib/fastpix_client/models/operations/delete_media_from_playlist_response.rb +1 -1
  49. data/lib/fastpix_client/models/operations/delete_media_playback_id_response.rb +1 -1
  50. data/lib/fastpix_client/models/operations/delete_media_response.rb +1 -1
  51. data/lib/fastpix_client/models/operations/delete_media_track_response.rb +1 -1
  52. data/lib/fastpix_client/models/operations/delete_playbackid_of_stream_response.rb +1 -1
  53. data/lib/fastpix_client/models/operations/delete_signing_key_response.rb +1 -1
  54. data/lib/fastpix_client/models/operations/delete_simulcast_of_stream_response.rb +1 -1
  55. data/lib/fastpix_client/models/operations/direct_upload_video_media_request.rb +1 -1
  56. data/lib/fastpix_client/models/operations/direct_upload_video_media_response.rb +1 -1
  57. data/lib/fastpix_client/models/operations/disable_live_stream_response.rb +1 -1
  58. data/lib/fastpix_client/models/operations/enable_live_stream_response.rb +1 -1
  59. data/lib/fastpix_client/models/operations/generate_subtitle_track_response.rb +1 -1
  60. data/lib/fastpix_client/models/operations/get_all_playlists_response.rb +1 -1
  61. data/lib/fastpix_client/models/operations/get_all_streams_response.rb +1 -1
  62. data/lib/fastpix_client/models/operations/get_live_stream_by_id_response.rb +1 -1
  63. data/lib/fastpix_client/models/operations/get_live_stream_playback_id_response.rb +1 -1
  64. data/lib/fastpix_client/models/operations/get_live_stream_viewer_count_by_id_response.rb +1 -1
  65. data/lib/fastpix_client/models/operations/get_media_clips_response.rb +1 -1
  66. data/lib/fastpix_client/models/operations/get_media_response.rb +1 -1
  67. data/lib/fastpix_client/models/operations/get_media_summary_response.rb +1 -1
  68. data/lib/fastpix_client/models/operations/get_playback_id_response.rb +1 -1
  69. data/lib/fastpix_client/models/operations/get_playlist_by_id_response.rb +1 -1
  70. data/lib/fastpix_client/models/operations/get_signing_key_by_id_response.rb +1 -1
  71. data/lib/fastpix_client/models/operations/get_specific_simulcast_of_stream_response.rb +1 -1
  72. data/lib/fastpix_client/models/operations/get_timeseries_data_response.rb +1 -1
  73. data/lib/fastpix_client/models/operations/get_video_view_details_response.rb +1 -1
  74. data/lib/fastpix_client/models/operations/getdrmconfiguration_response.rb +1 -1
  75. data/lib/fastpix_client/models/operations/getdrmconfigurationbyid_response.rb +1 -1
  76. data/lib/fastpix_client/models/operations/list_breakdown_values_response.rb +1 -1
  77. data/lib/fastpix_client/models/operations/list_by_top_content_response.rb +1 -1
  78. data/lib/fastpix_client/models/operations/list_comparison_values_response.rb +1 -1
  79. data/lib/fastpix_client/models/operations/list_dimensions_response.rb +1 -1
  80. data/lib/fastpix_client/models/operations/list_errors_response.rb +1 -1
  81. data/lib/fastpix_client/models/operations/list_filter_values_for_dimension_response.rb +1 -1
  82. data/lib/fastpix_client/models/operations/list_live_clips_response.rb +1 -1
  83. data/lib/fastpix_client/models/operations/list_media_response.rb +1 -1
  84. data/lib/fastpix_client/models/operations/list_overall_values_response.rb +1 -1
  85. data/lib/fastpix_client/models/operations/list_playback_ids_response.rb +1 -1
  86. data/lib/fastpix_client/models/operations/list_signing_keys_response.rb +1 -1
  87. data/lib/fastpix_client/models/operations/list_uploads_response.rb +1 -1
  88. data/lib/fastpix_client/models/operations/list_video_views_response.rb +1 -1
  89. data/lib/fastpix_client/models/operations/push_media_settings.rb +10 -21
  90. data/lib/fastpix_client/models/operations/retrievemediainputinfo_response.rb +1 -1
  91. data/lib/fastpix_client/models/operations/update_a_playlist_response.rb +1 -1
  92. data/lib/fastpix_client/models/operations/update_domain_restrictions_response.rb +1 -1
  93. data/lib/fastpix_client/models/operations/update_live_stream_response.rb +1 -1
  94. data/lib/fastpix_client/models/operations/update_media_chapters_response.rb +1 -1
  95. data/lib/fastpix_client/models/operations/update_media_moderation_response.rb +1 -1
  96. data/lib/fastpix_client/models/operations/update_media_named_entities_response.rb +1 -1
  97. data/lib/fastpix_client/models/operations/update_media_summary_response.rb +1 -1
  98. data/lib/fastpix_client/models/operations/update_media_track_response.rb +1 -1
  99. data/lib/fastpix_client/models/operations/update_specific_simulcast_of_stream_response.rb +1 -1
  100. data/lib/fastpix_client/models/operations/update_user_agent_restrictions_response.rb +1 -1
  101. data/lib/fastpix_client/models/operations/updated_media_response.rb +1 -1
  102. data/lib/fastpix_client/models/operations/updated_mp4support_response.rb +1 -1
  103. data/lib/fastpix_client/models/operations/updated_source_access_response.rb +1 -1
  104. data/lib/fastpix_client/playback.rb +123 -214
  105. data/lib/fastpix_client/playlist.rb +151 -297
  106. data/lib/fastpix_client/sdk_hooks/registration.rb +2 -2
  107. data/lib/fastpix_client/sdk_hooks/types.rb +4 -0
  108. data/lib/fastpix_client/sdkconfiguration.rb +4 -4
  109. data/lib/fastpix_client/signing_keys.rb +79 -123
  110. data/lib/fastpix_client/simulcast_stream.rb +101 -145
  111. data/lib/fastpix_client/start_live_stream.rb +54 -36
  112. data/lib/fastpix_client/utils/forms.rb +97 -101
  113. data/lib/fastpix_client/utils/headers.rb +44 -34
  114. data/lib/fastpix_client/utils/query_params.rb +39 -29
  115. data/lib/fastpix_client/utils/request_bodies.rb +4 -8
  116. data/lib/fastpix_client/utils/security.rb +30 -18
  117. data/lib/fastpix_client/utils/url.rb +83 -55
  118. data/lib/fastpix_client/utils/utils.rb +19 -37
  119. data/lib/fastpix_client/views.rb +71 -95
  120. data/lib/fastpixapi.rb +10 -10
  121. data/lib/openssl_patch.rb +24 -24
  122. metadata +20 -4
@@ -14,6 +14,58 @@ module FastpixClient
14
14
  extend T::Sig
15
15
  class SimulcastStream
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
+ SIMULCAST_PATH = '/live/streams/{streamId}/simulcast/{simulcastId}'
23
+ UNKNOWN_CONTENT_TYPE_ERROR = 'Unknown content type received'
24
+ USER_AGENT_HEADER = 'user-agent'
25
+
26
+ # Applies the SDK after-request hooks and ensures a usable response is present.
27
+ sig { params(http_response: T.nilable(Faraday::Response), error: T.nilable(StandardError), hook_ctx: SDKHooks::HookContext).returns(Faraday::Response) }
28
+ def apply_after_request_hooks(http_response, error, hook_ctx)
29
+ if http_response.nil? || Utils.error_status?(http_response.status)
30
+ http_response = @sdk_configuration.hooks.after_error(
31
+ error: error,
32
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
33
+ hook_ctx: hook_ctx
34
+ ),
35
+ response: http_response
36
+ )
37
+ else
38
+ http_response = @sdk_configuration.hooks.after_success(
39
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
40
+ hook_ctx: hook_ctx
41
+ ),
42
+ response: http_response
43
+ )
44
+ end
45
+
46
+ if http_response.nil?
47
+ raise error unless error.nil?
48
+ raise ::FastpixClient::Models::Errors::EmptyResponseError, 'no response'
49
+ end
50
+
51
+ http_response
52
+ end
53
+ private :apply_after_request_hooks
54
+
55
+ # Encodes the request body based on its serialized content type.
56
+ sig { params(req_content_type: T.nilable(String), data: T.untyped, form: T.untyped).returns(T.untyped) }
57
+ def encode_request_body(req_content_type, data, form)
58
+ raise ArgumentError, 'request body is required' if data.nil? && form.nil?
59
+
60
+ if form
61
+ Utils.encode_form(form)
62
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
63
+ URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
64
+ else
65
+ data
66
+ end
67
+ end
68
+ private :encode_request_body
17
69
 
18
70
  # Operations for simulcast stream management
19
71
 
@@ -47,12 +99,12 @@ module FastpixClient
47
99
  #
48
100
  # 1. Change to: When you call this endpoint, provide the parent `streamId` along with the simulcast target details (such as platform and credentials). The API returns a unique `simulcastId`, which you can use to manage the simulcast later.
49
101
  #
50
- # 2. To notify your application about the status of simulcast related events check for the <a href="https://docs.fastpix.io/docs/webhooks-collection#simulcast-target-events">webhooks for simulcast</a> target events.
102
+ # 2. To notify your application about the status of simulcast related events check for the <a href="https://fastpix.com/docs/webhooks/webhook-event-reference#simulcast-target-events">webhooks for simulcast</a> target events.
51
103
  #
52
104
  # #### Example
53
105
  # An event manager sets up a live stream for a virtual conference and wants to simulcast the stream on YouTube and Facebook Live. They first create the primary live stream in FastPix, ensuring it's in the idle state. Then, they use the API to create a simulcast target for YouTube.
54
106
  #
55
- # Related guide: <a href="https://docs.fastpix.io/docs/simulcast-to-3rd-party-platforms">Simulcast to 3rd party platforms</a>
107
+ # Related guide: <a href="https://fastpix.com/docs/edit-and-transform-live-stream/simulcast-to-multiple-platforms">Simulcast to 3rd party platforms</a>
56
108
  request = Models::Operations::CreateSimulcastOfStreamRequest.new(
57
109
  stream_id: stream_id,
58
110
  body: body
@@ -69,17 +121,9 @@ module FastpixClient
69
121
  headers = T.cast(headers, T::Hash[String, String])
70
122
  req_content_type, data, form = Utils.serialize_request_body(request, false, false, :body, :json)
71
123
  headers['content-type'] = req_content_type
72
- raise StandardError, 'request body is required' if data.nil? && form.nil?
73
-
74
- if form
75
- body = Utils.encode_form(form)
76
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
77
- body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
78
- else
79
- body = data
80
- end
81
- headers['Accept'] = 'application/json'
82
- headers['user-agent'] = @sdk_configuration.user_agent
124
+ body = encode_request_body(req_content_type, data, form)
125
+ headers['Accept'] = CONTENT_TYPE_JSON
126
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
83
127
 
84
128
  security = @sdk_configuration.security_source&.call
85
129
 
@@ -118,32 +162,12 @@ module FastpixClient
118
162
  rescue StandardError => e
119
163
  error = e
120
164
  ensure
121
- if http_response.nil? || Utils.error_status?(http_response.status)
122
- http_response = @sdk_configuration.hooks.after_error(
123
- error: error,
124
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
125
- hook_ctx: hook_ctx
126
- ),
127
- response: http_response
128
- )
129
- else
130
- http_response = @sdk_configuration.hooks.after_success(
131
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
132
- hook_ctx: hook_ctx
133
- ),
134
- response: http_response
135
- )
136
- end
137
-
138
- if http_response.nil?
139
- raise error if !error.nil?
140
- raise 'no response'
141
- end
165
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
142
166
  end
143
167
 
144
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
168
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
145
169
  if Utils.match_status_code(http_response.status, ['201'])
146
- if Utils.match_content_type(content_type, 'application/json')
170
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
147
171
  http_response = @sdk_configuration.hooks.after_success(
148
172
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
149
173
  hook_ctx: hook_ctx
@@ -161,14 +185,14 @@ module FastpixClient
161
185
 
162
186
  return response
163
187
  else
164
- 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'
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_ERROR
165
189
  end
166
190
  elsif Utils.match_status_code(http_response.status, ['4XX'])
167
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
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
168
192
  elsif Utils.match_status_code(http_response.status, ['5XX'])
169
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
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
170
194
  else
171
- if Utils.match_content_type(content_type, 'application/json')
195
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
172
196
  http_response = @sdk_configuration.hooks.after_success(
173
197
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
174
198
  hook_ctx: hook_ctx
@@ -186,7 +210,7 @@ module FastpixClient
186
210
 
187
211
  return response
188
212
  else
189
- 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'
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_ERROR
190
214
  end
191
215
  end
192
216
  end
@@ -197,7 +221,7 @@ module FastpixClient
197
221
  # delete_simulcast_of_stream - Delete a simulcast
198
222
  # Deletes a simulcast using its unique simulcastId, which you received during the simulcast creation process. Deleting a simulcast stops the broadcast to the associated platform, while the parent stream continues if it’s live. This action can’t be undone, and you must create a new simulcast to resume streaming to the same platform.
199
223
  #
200
- # Webhook event: <a href="https://docs.fastpix.io/docs/live-events#videolive_streamsimulcast_targetdeleted">video.live_stream.simulcast_target.deleted</a>
224
+ # Webhook event: <a href="https://fastpix.com/docs/live-stream-events/live-events#videolive_streamsimulcast_targetdeleted">video.live_stream.simulcast_target.deleted</a>
201
225
  #
202
226
  #
203
227
  # #### Example
@@ -211,13 +235,13 @@ module FastpixClient
211
235
  url = Utils.generate_url(
212
236
  Models::Operations::DeleteSimulcastOfStreamRequest,
213
237
  base_url,
214
- '/live/streams/{streamId}/simulcast/{simulcastId}',
238
+ SIMULCAST_PATH,
215
239
  request
216
240
  )
217
241
  headers = {}
218
242
  headers = T.cast(headers, T::Hash[String, String])
219
- headers['Accept'] = 'application/json'
220
- headers['user-agent'] = @sdk_configuration.user_agent
243
+ headers['Accept'] = CONTENT_TYPE_JSON
244
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
221
245
 
222
246
  security = @sdk_configuration.security_source&.call
223
247
 
@@ -255,32 +279,12 @@ module FastpixClient
255
279
  rescue StandardError => e
256
280
  error = e
257
281
  ensure
258
- if http_response.nil? || Utils.error_status?(http_response.status)
259
- http_response = @sdk_configuration.hooks.after_error(
260
- error: error,
261
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
262
- hook_ctx: hook_ctx
263
- ),
264
- response: http_response
265
- )
266
- else
267
- http_response = @sdk_configuration.hooks.after_success(
268
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
269
- hook_ctx: hook_ctx
270
- ),
271
- response: http_response
272
- )
273
- end
274
-
275
- if http_response.nil?
276
- raise error if !error.nil?
277
- raise 'no response'
278
- end
282
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
279
283
  end
280
284
 
281
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
285
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
282
286
  if Utils.match_status_code(http_response.status, ['200'])
283
- if Utils.match_content_type(content_type, 'application/json')
287
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
284
288
  http_response = @sdk_configuration.hooks.after_success(
285
289
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
286
290
  hook_ctx: hook_ctx
@@ -298,14 +302,14 @@ module FastpixClient
298
302
 
299
303
  return response
300
304
  else
301
- 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'
305
+ 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
302
306
  end
303
307
  elsif Utils.match_status_code(http_response.status, ['4XX'])
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'
308
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
305
309
  elsif Utils.match_status_code(http_response.status, ['5XX'])
306
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
310
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
307
311
  else
308
- if Utils.match_content_type(content_type, 'application/json')
312
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
309
313
  http_response = @sdk_configuration.hooks.after_success(
310
314
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
311
315
  hook_ctx: hook_ctx
@@ -323,7 +327,7 @@ module FastpixClient
323
327
 
324
328
  return response
325
329
  else
326
- 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'
330
+ 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
327
331
  end
328
332
  end
329
333
  end
@@ -345,13 +349,13 @@ module FastpixClient
345
349
  url = Utils.generate_url(
346
350
  Models::Operations::GetSpecificSimulcastOfStreamRequest,
347
351
  base_url,
348
- '/live/streams/{streamId}/simulcast/{simulcastId}',
352
+ SIMULCAST_PATH,
349
353
  request
350
354
  )
351
355
  headers = {}
352
356
  headers = T.cast(headers, T::Hash[String, String])
353
- headers['Accept'] = 'application/json'
354
- headers['user-agent'] = @sdk_configuration.user_agent
357
+ headers['Accept'] = CONTENT_TYPE_JSON
358
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
355
359
 
356
360
  security = @sdk_configuration.security_source&.call
357
361
 
@@ -389,32 +393,12 @@ module FastpixClient
389
393
  rescue StandardError => e
390
394
  error = e
391
395
  ensure
392
- if http_response.nil? || Utils.error_status?(http_response.status)
393
- http_response = @sdk_configuration.hooks.after_error(
394
- error: error,
395
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
396
- hook_ctx: hook_ctx
397
- ),
398
- response: http_response
399
- )
400
- else
401
- http_response = @sdk_configuration.hooks.after_success(
402
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
403
- hook_ctx: hook_ctx
404
- ),
405
- response: http_response
406
- )
407
- end
408
-
409
- if http_response.nil?
410
- raise error if !error.nil?
411
- raise 'no response'
412
- end
396
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
413
397
  end
414
398
 
415
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
399
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
416
400
  if Utils.match_status_code(http_response.status, ['200'])
417
- if Utils.match_content_type(content_type, 'application/json')
401
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
418
402
  http_response = @sdk_configuration.hooks.after_success(
419
403
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
420
404
  hook_ctx: hook_ctx
@@ -432,14 +416,14 @@ module FastpixClient
432
416
 
433
417
  return response
434
418
  else
435
- 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'
419
+ 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
436
420
  end
437
421
  elsif Utils.match_status_code(http_response.status, ['4XX'])
438
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
422
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
439
423
  elsif Utils.match_status_code(http_response.status, ['5XX'])
440
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
424
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
441
425
  else
442
- if Utils.match_content_type(content_type, 'application/json')
426
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
443
427
  http_response = @sdk_configuration.hooks.after_success(
444
428
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
445
429
  hook_ctx: hook_ctx
@@ -457,7 +441,7 @@ module FastpixClient
457
441
 
458
442
  return response
459
443
  else
460
- 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'
444
+ 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
461
445
  end
462
446
  end
463
447
  end
@@ -468,7 +452,7 @@ module FastpixClient
468
452
  # update_specific_simulcast_of_stream - Update a simulcast
469
453
  # Updates the status of a specific simulcast linked to a parent live stream. You can enable or disable the simulcast at any time while the parent stream is active or idle. After the live stream is disabled, the simulcast can no longer be modified.
470
454
  #
471
- # Webhook event: <a href="https://docs.fastpix.io/docs/live-events#videolive_streamsimulcast_targetupdated">video.live_stream.simulcast_target.updated</a>
455
+ # Webhook event: <a href="https://fastpix.com/docs/live-stream-events/live-events#videolive_streamsimulcast_targetupdated">video.live_stream.simulcast_target.updated</a>
472
456
  #
473
457
  # #### Example
474
458
  # When a `PATCH` request is made to this endpoint, the API updates the status of the simulcast. This can be useful for pausing or resuming a simulcast on a particular platform without stopping the parent live stream.
@@ -482,24 +466,16 @@ module FastpixClient
482
466
  url = Utils.generate_url(
483
467
  Models::Operations::UpdateSpecificSimulcastOfStreamRequest,
484
468
  base_url,
485
- '/live/streams/{streamId}/simulcast/{simulcastId}',
469
+ SIMULCAST_PATH,
486
470
  request
487
471
  )
488
472
  headers = {}
489
473
  headers = T.cast(headers, T::Hash[String, String])
490
474
  req_content_type, data, form = Utils.serialize_request_body(request, false, false, :body, :json)
491
475
  headers['content-type'] = req_content_type
492
- raise StandardError, 'request body is required' if data.nil? && form.nil?
493
-
494
- if form
495
- body = Utils.encode_form(form)
496
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
497
- body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
498
- else
499
- body = data
500
- end
501
- headers['Accept'] = 'application/json'
502
- headers['user-agent'] = @sdk_configuration.user_agent
476
+ body = encode_request_body(req_content_type, data, form)
477
+ headers['Accept'] = CONTENT_TYPE_JSON
478
+ headers[USER_AGENT_HEADER] = @sdk_configuration.user_agent
503
479
 
504
480
  security = @sdk_configuration.security_source&.call
505
481
 
@@ -538,32 +514,12 @@ module FastpixClient
538
514
  rescue StandardError => e
539
515
  error = e
540
516
  ensure
541
- if http_response.nil? || Utils.error_status?(http_response.status)
542
- http_response = @sdk_configuration.hooks.after_error(
543
- error: error,
544
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
545
- hook_ctx: hook_ctx
546
- ),
547
- response: http_response
548
- )
549
- else
550
- http_response = @sdk_configuration.hooks.after_success(
551
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
552
- hook_ctx: hook_ctx
553
- ),
554
- response: http_response
555
- )
556
- end
557
-
558
- if http_response.nil?
559
- raise error if !error.nil?
560
- raise 'no response'
561
- end
517
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
562
518
  end
563
519
 
564
- content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
520
+ content_type = http_response.headers.fetch(CONTENT_TYPE_HEADER, DEFAULT_CONTENT_TYPE)
565
521
  if Utils.match_status_code(http_response.status, ['200'])
566
- if Utils.match_content_type(content_type, 'application/json')
522
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
567
523
  http_response = @sdk_configuration.hooks.after_success(
568
524
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
569
525
  hook_ctx: hook_ctx
@@ -581,14 +537,14 @@ module FastpixClient
581
537
 
582
538
  return response
583
539
  else
584
- 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'
540
+ 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
585
541
  end
586
542
  elsif Utils.match_status_code(http_response.status, ['4XX'])
587
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
543
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
588
544
  elsif Utils.match_status_code(http_response.status, ['5XX'])
589
- raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
545
+ raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), API_ERROR_OCCURRED
590
546
  else
591
- if Utils.match_content_type(content_type, 'application/json')
547
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
592
548
  http_response = @sdk_configuration.hooks.after_success(
593
549
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
594
550
  hook_ctx: hook_ctx
@@ -606,7 +562,7 @@ module FastpixClient
606
562
 
607
563
  return response
608
564
  else
609
- 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'
565
+ 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
610
566
  end
611
567
  end
612
568
  end
@@ -14,6 +14,52 @@ module FastpixClient
14
14
  extend T::Sig
15
15
  class StartLiveStream
16
16
  extend T::Sig
17
+
18
+ CONTENT_TYPE_JSON = 'application/json'
19
+
20
+ # Applies the SDK after-request hooks and ensures a usable response is present.
21
+ sig { params(http_response: T.nilable(Faraday::Response), error: T.nilable(StandardError), hook_ctx: SDKHooks::HookContext).returns(Faraday::Response) }
22
+ def apply_after_request_hooks(http_response, error, hook_ctx)
23
+ if http_response.nil? || Utils.error_status?(http_response.status)
24
+ http_response = @sdk_configuration.hooks.after_error(
25
+ error: error,
26
+ hook_ctx: SDKHooks::AfterErrorHookContext.new(
27
+ hook_ctx: hook_ctx
28
+ ),
29
+ response: http_response
30
+ )
31
+ else
32
+ http_response = @sdk_configuration.hooks.after_success(
33
+ hook_ctx: SDKHooks::AfterSuccessHookContext.new(
34
+ hook_ctx: hook_ctx
35
+ ),
36
+ response: http_response
37
+ )
38
+ end
39
+
40
+ if http_response.nil?
41
+ raise error unless error.nil?
42
+ raise ::FastpixClient::Models::Errors::EmptyResponseError, 'no response'
43
+ end
44
+
45
+ http_response
46
+ end
47
+ private :apply_after_request_hooks
48
+
49
+ # Encodes the request body based on its serialized content type.
50
+ sig { params(req_content_type: T.nilable(String), data: T.untyped, form: T.untyped).returns(T.untyped) }
51
+ def encode_request_body(req_content_type, data, form)
52
+ raise ArgumentError, 'request body is required' if data.nil? && form.nil?
53
+
54
+ if form
55
+ Utils.encode_form(form)
56
+ elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
57
+ URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
58
+ else
59
+ data
60
+ end
61
+ end
62
+ private :encode_request_body
17
63
 
18
64
  # Operations for starting live streams
19
65
 
@@ -42,7 +88,7 @@ module FastpixClient
42
88
  sig { params(request: Models::Components::CreateLiveStreamRequest, timeout_ms: T.nilable(Integer)).returns(Models::Operations::CreateNewStreamResponse) }
43
89
  def create_new_stream(request:, timeout_ms: nil)
44
90
  # create_new_stream - Create a new stream
45
- # Creates a new <a href="https://docs.fastpix.io/docs/get-started-with-live-streaming">RTMPS</a> or <a href="https://docs.fastpix.io/docs/using-srt-to-live-stream">SRT</a> live stream in FastPix. When you create a stream, FastPix generates a unique `streamKey` and `srtSecret` that you can use with broadcasting software such as OBS to connect to FastPix RTMPS or SRT servers. Use SRT for live streaming in unstable network conditions, as it provides error correction and encryption for a more reliable and secure broadcast.
91
+ # Creates a new <a href="https://fastpix.com/docs/get-started/live-overview">RTMPS</a> or <a href="https://fastpix.com/docs/broadcast/live-stream-with-srt">SRT</a> live stream in FastPix. When you create a stream, FastPix generates a unique `streamKey` and `srtSecret` that you can use with broadcasting software such as OBS to connect to FastPix RTMPS or SRT servers. Use SRT for live streaming in unstable network conditions, as it provides error correction and encryption for a more reliable and secure broadcast.
46
92
  #
47
93
  # Leverage SRT for live streaming in environments with unstable networks, taking advantage of its error correction and encryption features for a resilient and secure broadcast.
48
94
  #
@@ -52,7 +98,7 @@ module FastpixClient
52
98
  #
53
99
  # 2. FastPix returns the stream details for both RTMPS and SRT configurations. These keys and IDs from the stream details are essential for connecting the broadcasting software to FastPix’s servers and transmitting the live stream to viewers.
54
100
  #
55
- # 3. After the live stream is created, FastPix sends a `POST` request to your specified webhook endpoint with the event <a href="https://docs.fastpix.io/docs/live-events#videolive_streamcreated">video.live_stream.created</a>.
101
+ # 3. After the live stream is created, FastPix sends a `POST` request to your specified webhook endpoint with the event <a href="https://fastpix.com/docs/live-stream-events/live-events#videolive_streamcreated">video.live_stream.created</a>.
56
102
  #
57
103
  #
58
104
  # **Example:**
@@ -61,7 +107,7 @@ module FastpixClient
61
107
  # Imagine a gaming platform that allows users to live stream gameplay directly from their dashboard. The API creates a new stream, provides the necessary stream key, and sets it to "private" so that only specific viewers can access it.
62
108
  #
63
109
  #
64
- # Related guide: <a href="https://docs.fastpix.io/docs/how-to-livestream">How to live stream</a>
110
+ # Related guide: <a href="https://fastpix.com/docs/get-started/live-quickstart">How to live stream</a>
65
111
  url, params = @sdk_configuration.get_server_details
66
112
  base_url = Utils.template_url(url, params)
67
113
  url = "#{base_url}/live/streams"
@@ -69,16 +115,8 @@ module FastpixClient
69
115
  headers = T.cast(headers, T::Hash[String, String])
70
116
  req_content_type, data, form = Utils.serialize_request_body(request, false, false, :request, :json)
71
117
  headers['content-type'] = req_content_type
72
- raise StandardError, 'request body is required' if data.nil? && form.nil?
73
-
74
- if form
75
- body = Utils.encode_form(form)
76
- elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
77
- body = URI.encode_www_form(T.cast(data, T::Hash[Symbol, Object]))
78
- else
79
- body = data
80
- end
81
- headers['Accept'] = 'application/json'
118
+ body = encode_request_body(req_content_type, data, form)
119
+ headers['Accept'] = CONTENT_TYPE_JSON
82
120
  headers['user-agent'] = @sdk_configuration.user_agent
83
121
 
84
122
  security = @sdk_configuration.security_source&.call
@@ -118,32 +156,12 @@ module FastpixClient
118
156
  rescue StandardError => e
119
157
  error = e
120
158
  ensure
121
- if http_response.nil? || Utils.error_status?(http_response.status)
122
- http_response = @sdk_configuration.hooks.after_error(
123
- error: error,
124
- hook_ctx: SDKHooks::AfterErrorHookContext.new(
125
- hook_ctx: hook_ctx
126
- ),
127
- response: http_response
128
- )
129
- else
130
- http_response = @sdk_configuration.hooks.after_success(
131
- hook_ctx: SDKHooks::AfterSuccessHookContext.new(
132
- hook_ctx: hook_ctx
133
- ),
134
- response: http_response
135
- )
136
- end
137
-
138
- if http_response.nil?
139
- raise error if !error.nil?
140
- raise 'no response'
141
- end
159
+ http_response = apply_after_request_hooks(http_response, error, hook_ctx)
142
160
  end
143
161
 
144
162
  content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
145
163
  if Utils.match_status_code(http_response.status, ['201'])
146
- if Utils.match_content_type(content_type, 'application/json')
164
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
147
165
  http_response = @sdk_configuration.hooks.after_success(
148
166
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
149
167
  hook_ctx: hook_ctx
@@ -168,7 +186,7 @@ module FastpixClient
168
186
  elsif Utils.match_status_code(http_response.status, ['5XX'])
169
187
  raise ::FastpixClient::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
170
188
  else
171
- if Utils.match_content_type(content_type, 'application/json')
189
+ if Utils.match_content_type(content_type, CONTENT_TYPE_JSON)
172
190
  http_response = @sdk_configuration.hooks.after_success(
173
191
  hook_ctx: SDKHooks::AfterSuccessHookContext.new(
174
192
  hook_ctx: hook_ctx