bandwidth-sdk 2.1.1 → 3.7.0

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +85 -70
  3. data/lib/bandwidth.rb +7 -1
  4. data/lib/bandwidth/client.rb +20 -2
  5. data/lib/bandwidth/configuration.rb +45 -9
  6. data/lib/bandwidth/http/auth/two_factor_auth_basic_auth.rb +22 -0
  7. data/lib/bandwidth/http/auth/web_rtc_basic_auth.rb +22 -0
  8. data/lib/bandwidth/http/faraday_client.rb +2 -6
  9. data/lib/bandwidth/messaging_lib/messaging.rb +1 -3
  10. data/lib/bandwidth/messaging_lib/messaging/client.rb +11 -2
  11. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +45 -88
  12. data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +1 -1
  13. data/lib/bandwidth/messaging_lib/messaging/exceptions/{generic_client_exception.rb → messaging_exception.rb} +2 -14
  14. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb +20 -0
  15. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/client.rb +49 -0
  16. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb +153 -0
  17. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/base_controller.rb +49 -0
  18. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/invalid_request_exception.rb +29 -0
  19. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_code_request_schema.rb +88 -0
  20. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_messaging_response.rb +35 -0
  21. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_code_response.rb +35 -0
  22. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_request_schema.rb +94 -0
  23. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_voice_response.rb +35 -0
  24. data/lib/bandwidth/utilities/file_wrapper.rb +17 -0
  25. data/lib/bandwidth/voice_lib/bxml/verbs/bridge.rb +22 -0
  26. data/lib/bandwidth/voice_lib/bxml/verbs/conference.rb +28 -0
  27. data/lib/bandwidth/voice_lib/bxml/verbs/gather.rb +8 -0
  28. data/lib/bandwidth/voice_lib/bxml/verbs/phone_number.rb +2 -0
  29. data/lib/bandwidth/voice_lib/bxml/verbs/record.rb +5 -1
  30. data/lib/bandwidth/voice_lib/bxml/verbs/send_dtmf.rb +4 -1
  31. data/lib/bandwidth/voice_lib/bxml/verbs/start_recording.rb +4 -1
  32. data/lib/bandwidth/voice_lib/voice.rb +13 -4
  33. data/lib/bandwidth/voice_lib/voice/client.rb +11 -2
  34. data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +629 -112
  35. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +1 -1
  36. data/lib/bandwidth/voice_lib/voice/exceptions/{error_response_exception.rb → api_error_response_exception.rb} +3 -3
  37. data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +11 -2
  38. data/lib/bandwidth/voice_lib/voice/models/api_call_state_response.rb +164 -0
  39. data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +20 -2
  40. data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +1 -1
  41. data/lib/bandwidth/voice_lib/voice/models/api_transcribe_recording_request.rb +71 -0
  42. data/lib/bandwidth/voice_lib/voice/models/call_engine_modify_conference_request.rb +35 -0
  43. data/lib/bandwidth/voice_lib/voice/models/callback_method_enum.rb +35 -0
  44. data/lib/bandwidth/voice_lib/voice/models/disconnect_cause_enum.rb +47 -0
  45. data/lib/bandwidth/voice_lib/voice/models/modify_call_recording_state.rb +1 -1
  46. data/lib/bandwidth/voice_lib/voice/models/recording_metadata_response.rb +35 -25
  47. data/lib/bandwidth/voice_lib/voice/models/state1_enum.rb +4 -7
  48. data/lib/bandwidth/voice_lib/voice/models/state2_enum.rb +20 -0
  49. data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +7 -4
  50. data/lib/bandwidth/voice_lib/voice/models/status1_enum.rb +26 -0
  51. data/lib/bandwidth/voice_lib/voice/models/status2_enum.rb +32 -0
  52. data/lib/bandwidth/voice_lib/voice/models/status_enum.rb +17 -0
  53. data/lib/bandwidth/{messaging_lib/messaging/models/field_error.rb → voice_lib/voice/models/transcript.rb} +15 -15
  54. data/lib/bandwidth/voice_lib/voice/models/transcription.rb +62 -0
  55. data/lib/bandwidth/voice_lib/voice/models/transcription_response.rb +42 -0
  56. data/lib/bandwidth/web_rtc_lib/web_rtc.rb +21 -0
  57. data/lib/bandwidth/web_rtc_lib/web_rtc/client.rb +49 -0
  58. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +682 -0
  59. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/base_controller.rb +49 -0
  60. data/lib/bandwidth/{messaging_lib/messaging/exceptions/path_client_exception.rb → web_rtc_lib/web_rtc/exceptions/error_exception.rb} +4 -19
  61. data/lib/bandwidth/web_rtc_lib/web_rtc/models/accounts_participants_response.rb +47 -0
  62. data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant.rb +83 -0
  63. data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant_subscription.rb +35 -0
  64. data/lib/bandwidth/web_rtc_lib/web_rtc/models/publish_permission_enum.rb +17 -0
  65. data/lib/bandwidth/web_rtc_lib/web_rtc/models/session.rb +44 -0
  66. data/lib/bandwidth/web_rtc_lib/web_rtc/models/subscriptions.rb +54 -0
  67. metadata +58 -11
  68. data/lib/bandwidth/voice_lib/voice/models/api_get_account_recordings_metadata_request.rb +0 -65
  69. data/lib/bandwidth/voice_lib/voice/models/transcription_status_enum.rb +0 -20
  70. data/lib/bandwidth/voice_lib/voice/models/type_enum.rb +0 -32
@@ -0,0 +1,42 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # TranscriptionResponse Model.
8
+ class TranscriptionResponse < BaseModel
9
+ # TODO: Write general description for this method
10
+ # @return [List of Transcript]
11
+ attr_accessor :transcripts
12
+
13
+ # A mapping from model property names to API property names.
14
+ def self.names
15
+ @_hash = {} if @_hash.nil?
16
+ @_hash['transcripts'] = 'transcripts'
17
+ @_hash
18
+ end
19
+
20
+ def initialize(transcripts = nil)
21
+ @transcripts = transcripts
22
+ end
23
+
24
+ # Creates an instance of the object from a hash.
25
+ def self.from_hash(hash)
26
+ return nil unless hash
27
+
28
+ # Extract variables from the hash.
29
+ # Parameter is an array, so we need to iterate through it
30
+ transcripts = nil
31
+ unless hash['transcripts'].nil?
32
+ transcripts = []
33
+ hash['transcripts'].each do |structure|
34
+ transcripts << (Transcript.from_hash(structure) if structure)
35
+ end
36
+ end
37
+
38
+ # Create object from extracted values.
39
+ TranscriptionResponse.new(transcripts)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+
7
+ require_relative 'web_rtc/client.rb'
8
+
9
+ # Models
10
+ require_relative 'web_rtc/models/session.rb'
11
+ require_relative 'web_rtc/models/participant.rb'
12
+ require_relative 'web_rtc/models/subscriptions.rb'
13
+ require_relative 'web_rtc/models/participant_subscription.rb'
14
+ require_relative 'web_rtc/models/accounts_participants_response.rb'
15
+ require_relative 'web_rtc/models/publish_permission_enum.rb'
16
+
17
+ # Exceptions
18
+ require_relative 'web_rtc/exceptions/error_exception.rb'
19
+ # Controllers
20
+ require_relative 'web_rtc/controllers/base_controller.rb'
21
+ require_relative 'web_rtc/controllers/api_controller.rb'
@@ -0,0 +1,49 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ module WebRtc
8
+ # bandwidth client class.
9
+ class Client
10
+ attr_reader :config
11
+
12
+ # Access to client controller.
13
+ # @return [APIController] Returns the controller instance.
14
+ def client
15
+ @client ||= APIController.new config
16
+ end
17
+
18
+ def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
19
+ backoff_factor: 1, environment: Environment::PRODUCTION,
20
+ messaging_basic_auth_user_name: 'TODO: Replace',
21
+ messaging_basic_auth_password: 'TODO: Replace',
22
+ two_factor_auth_basic_auth_user_name: 'TODO: Replace',
23
+ two_factor_auth_basic_auth_password: 'TODO: Replace',
24
+ voice_basic_auth_user_name: 'TODO: Replace',
25
+ voice_basic_auth_password: 'TODO: Replace',
26
+ web_rtc_basic_auth_user_name: 'TODO: Replace',
27
+ web_rtc_basic_auth_password: 'TODO: Replace',
28
+ config: nil)
29
+ @config = if config.nil?
30
+ Configuration.new(timeout: timeout,
31
+ max_retries: max_retries,
32
+ retry_interval: retry_interval,
33
+ backoff_factor: backoff_factor,
34
+ environment: environment,
35
+ messaging_basic_auth_user_name: messaging_basic_auth_user_name,
36
+ messaging_basic_auth_password: messaging_basic_auth_password,
37
+ two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
38
+ two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
39
+ voice_basic_auth_user_name: voice_basic_auth_user_name,
40
+ voice_basic_auth_password: voice_basic_auth_password,
41
+ web_rtc_basic_auth_user_name: web_rtc_basic_auth_user_name,
42
+ web_rtc_basic_auth_password: web_rtc_basic_auth_password)
43
+ else
44
+ config
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,682 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ module WebRtc
8
+ # APIController
9
+ class APIController < BaseController
10
+ def initialize(config, http_call_back: nil)
11
+ super(config, http_call_back: http_call_back)
12
+ end
13
+
14
+ # Create a new participant under this account
15
+ # Participants are idempotent, so relevant parameters must be set in this
16
+ # function if desired
17
+ # @param [String] account_id Required parameter: Account ID
18
+ # @param [Participant] body Optional parameter: Participant parameters
19
+ # @return [AccountsParticipantsResponse] response from the API call
20
+ def create_participant(account_id,
21
+ body: nil)
22
+ # Prepare query url.
23
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
24
+ _query_builder << '/accounts/{accountId}/participants'
25
+ _query_builder = APIHelper.append_url_with_template_parameters(
26
+ _query_builder,
27
+ 'accountId' => account_id
28
+ )
29
+ _query_url = APIHelper.clean_url _query_builder
30
+
31
+ # Prepare headers.
32
+ _headers = {
33
+ 'accept' => 'application/json',
34
+ 'content-type' => 'application/json; charset=utf-8'
35
+ }
36
+
37
+ # Prepare and execute HttpRequest.
38
+ _request = config.http_client.post(
39
+ _query_url,
40
+ headers: _headers,
41
+ parameters: body.to_json
42
+ )
43
+ WebRtcBasicAuth.apply(config, _request)
44
+ _response = execute_request(_request)
45
+
46
+ # Validate response against endpoint and global error codes.
47
+ if _response.status_code == 400
48
+ raise APIException.new(
49
+ 'Bad Request',
50
+ _response
51
+ )
52
+ elsif _response.status_code == 401
53
+ raise APIException.new(
54
+ 'Unauthorized',
55
+ _response
56
+ )
57
+ elsif _response.status_code == 403
58
+ raise APIException.new(
59
+ 'Access Denied',
60
+ _response
61
+ )
62
+ end
63
+ unless _response.status_code.between?(200, 208)
64
+ raise ErrorException.new(
65
+ 'Unexpected Error',
66
+ _response
67
+ )
68
+ end
69
+ validate_response(_response)
70
+
71
+ # Return appropriate response type.
72
+ decoded = APIHelper.json_deserialize(_response.raw_body)
73
+ ApiResponse.new(_response,
74
+ data: AccountsParticipantsResponse.from_hash(decoded))
75
+ end
76
+
77
+ # Get participant by ID
78
+ # @param [String] account_id Required parameter: Account ID
79
+ # @param [String] participant_id Required parameter: Participant ID
80
+ # @return [Participant] response from the API call
81
+ def get_participant(account_id,
82
+ participant_id)
83
+ # Prepare query url.
84
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
85
+ _query_builder << '/accounts/{accountId}/participants/{participantId}'
86
+ _query_builder = APIHelper.append_url_with_template_parameters(
87
+ _query_builder,
88
+ 'accountId' => account_id,
89
+ 'participantId' => participant_id
90
+ )
91
+ _query_url = APIHelper.clean_url _query_builder
92
+
93
+ # Prepare headers.
94
+ _headers = {
95
+ 'accept' => 'application/json'
96
+ }
97
+
98
+ # Prepare and execute HttpRequest.
99
+ _request = config.http_client.get(
100
+ _query_url,
101
+ headers: _headers
102
+ )
103
+ WebRtcBasicAuth.apply(config, _request)
104
+ _response = execute_request(_request)
105
+
106
+ # Validate response against endpoint and global error codes.
107
+ if _response.status_code == 401
108
+ raise APIException.new(
109
+ 'Unauthorized',
110
+ _response
111
+ )
112
+ elsif _response.status_code == 403
113
+ raise APIException.new(
114
+ 'Access Denied',
115
+ _response
116
+ )
117
+ elsif _response.status_code == 404
118
+ raise APIException.new(
119
+ 'Not Found',
120
+ _response
121
+ )
122
+ end
123
+ unless _response.status_code.between?(200, 208)
124
+ raise ErrorException.new(
125
+ 'Unexpected Error',
126
+ _response
127
+ )
128
+ end
129
+ validate_response(_response)
130
+
131
+ # Return appropriate response type.
132
+ decoded = APIHelper.json_deserialize(_response.raw_body)
133
+ ApiResponse.new(_response, data: Participant.from_hash(decoded))
134
+ end
135
+
136
+ # Delete participant by ID
137
+ # @param [String] account_id Required parameter: Account ID
138
+ # @param [String] participant_id Required parameter: Example:
139
+ # @return [void] response from the API call
140
+ def delete_participant(account_id,
141
+ participant_id)
142
+ # Prepare query url.
143
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
144
+ _query_builder << '/accounts/{accountId}/participants/{participantId}'
145
+ _query_builder = APIHelper.append_url_with_template_parameters(
146
+ _query_builder,
147
+ 'accountId' => account_id,
148
+ 'participantId' => participant_id
149
+ )
150
+ _query_url = APIHelper.clean_url _query_builder
151
+
152
+ # Prepare and execute HttpRequest.
153
+ _request = config.http_client.delete(
154
+ _query_url
155
+ )
156
+ WebRtcBasicAuth.apply(config, _request)
157
+ _response = execute_request(_request)
158
+
159
+ # Validate response against endpoint and global error codes.
160
+ if _response.status_code == 401
161
+ raise APIException.new(
162
+ 'Unauthorized',
163
+ _response
164
+ )
165
+ elsif _response.status_code == 403
166
+ raise APIException.new(
167
+ 'Access Denied',
168
+ _response
169
+ )
170
+ elsif _response.status_code == 404
171
+ raise APIException.new(
172
+ 'Not Found',
173
+ _response
174
+ )
175
+ end
176
+ unless _response.status_code.between?(200, 208)
177
+ raise ErrorException.new(
178
+ 'Unexpected Error',
179
+ _response
180
+ )
181
+ end
182
+ validate_response(_response)
183
+
184
+ # Return appropriate response type.
185
+ ApiResponse.new(_response)
186
+ end
187
+
188
+ # Create a new session
189
+ # Sessions are idempotent, so relevant parameters must be set in this
190
+ # function if desired
191
+ # @param [String] account_id Required parameter: Account ID
192
+ # @param [Session] body Optional parameter: Session parameters
193
+ # @return [Session] response from the API call
194
+ def create_session(account_id,
195
+ body: nil)
196
+ # Prepare query url.
197
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
198
+ _query_builder << '/accounts/{accountId}/sessions'
199
+ _query_builder = APIHelper.append_url_with_template_parameters(
200
+ _query_builder,
201
+ 'accountId' => account_id
202
+ )
203
+ _query_url = APIHelper.clean_url _query_builder
204
+
205
+ # Prepare headers.
206
+ _headers = {
207
+ 'accept' => 'application/json',
208
+ 'content-type' => 'application/json; charset=utf-8'
209
+ }
210
+
211
+ # Prepare and execute HttpRequest.
212
+ _request = config.http_client.post(
213
+ _query_url,
214
+ headers: _headers,
215
+ parameters: body.to_json
216
+ )
217
+ WebRtcBasicAuth.apply(config, _request)
218
+ _response = execute_request(_request)
219
+
220
+ # Validate response against endpoint and global error codes.
221
+ if _response.status_code == 400
222
+ raise APIException.new(
223
+ 'Bad Request',
224
+ _response
225
+ )
226
+ elsif _response.status_code == 401
227
+ raise APIException.new(
228
+ 'Unauthorized',
229
+ _response
230
+ )
231
+ elsif _response.status_code == 403
232
+ raise APIException.new(
233
+ 'Access Denied',
234
+ _response
235
+ )
236
+ end
237
+ unless _response.status_code.between?(200, 208)
238
+ raise ErrorException.new(
239
+ 'Unexpected Error',
240
+ _response
241
+ )
242
+ end
243
+ validate_response(_response)
244
+
245
+ # Return appropriate response type.
246
+ decoded = APIHelper.json_deserialize(_response.raw_body)
247
+ ApiResponse.new(_response, data: Session.from_hash(decoded))
248
+ end
249
+
250
+ # Get session by ID
251
+ # @param [String] account_id Required parameter: Account ID
252
+ # @param [String] session_id Required parameter: Session ID
253
+ # @return [Session] response from the API call
254
+ def get_session(account_id,
255
+ session_id)
256
+ # Prepare query url.
257
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
258
+ _query_builder << '/accounts/{accountId}/sessions/{sessionId}'
259
+ _query_builder = APIHelper.append_url_with_template_parameters(
260
+ _query_builder,
261
+ 'accountId' => account_id,
262
+ 'sessionId' => session_id
263
+ )
264
+ _query_url = APIHelper.clean_url _query_builder
265
+
266
+ # Prepare headers.
267
+ _headers = {
268
+ 'accept' => 'application/json'
269
+ }
270
+
271
+ # Prepare and execute HttpRequest.
272
+ _request = config.http_client.get(
273
+ _query_url,
274
+ headers: _headers
275
+ )
276
+ WebRtcBasicAuth.apply(config, _request)
277
+ _response = execute_request(_request)
278
+
279
+ # Validate response against endpoint and global error codes.
280
+ if _response.status_code == 401
281
+ raise APIException.new(
282
+ 'Unauthorized',
283
+ _response
284
+ )
285
+ elsif _response.status_code == 403
286
+ raise APIException.new(
287
+ 'Access Denied',
288
+ _response
289
+ )
290
+ elsif _response.status_code == 404
291
+ raise APIException.new(
292
+ 'Not Found',
293
+ _response
294
+ )
295
+ end
296
+ unless _response.status_code.between?(200, 208)
297
+ raise ErrorException.new(
298
+ 'Unexpected Error',
299
+ _response
300
+ )
301
+ end
302
+ validate_response(_response)
303
+
304
+ # Return appropriate response type.
305
+ decoded = APIHelper.json_deserialize(_response.raw_body)
306
+ ApiResponse.new(_response, data: Session.from_hash(decoded))
307
+ end
308
+
309
+ # Delete session by ID
310
+ # @param [String] account_id Required parameter: Account ID
311
+ # @param [String] session_id Required parameter: Session ID
312
+ # @return [void] response from the API call
313
+ def delete_session(account_id,
314
+ session_id)
315
+ # Prepare query url.
316
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
317
+ _query_builder << '/accounts/{accountId}/sessions/{sessionId}'
318
+ _query_builder = APIHelper.append_url_with_template_parameters(
319
+ _query_builder,
320
+ 'accountId' => account_id,
321
+ 'sessionId' => session_id
322
+ )
323
+ _query_url = APIHelper.clean_url _query_builder
324
+
325
+ # Prepare and execute HttpRequest.
326
+ _request = config.http_client.delete(
327
+ _query_url
328
+ )
329
+ WebRtcBasicAuth.apply(config, _request)
330
+ _response = execute_request(_request)
331
+
332
+ # Validate response against endpoint and global error codes.
333
+ if _response.status_code == 401
334
+ raise APIException.new(
335
+ 'Unauthorized',
336
+ _response
337
+ )
338
+ elsif _response.status_code == 403
339
+ raise APIException.new(
340
+ 'Access Denied',
341
+ _response
342
+ )
343
+ elsif _response.status_code == 404
344
+ raise APIException.new(
345
+ 'Not Found',
346
+ _response
347
+ )
348
+ end
349
+ unless _response.status_code.between?(200, 208)
350
+ raise ErrorException.new(
351
+ 'Unexpected Error',
352
+ _response
353
+ )
354
+ end
355
+ validate_response(_response)
356
+
357
+ # Return appropriate response type.
358
+ ApiResponse.new(_response)
359
+ end
360
+
361
+ # List participants in a session
362
+ # @param [String] account_id Required parameter: Account ID
363
+ # @param [String] session_id Required parameter: Session ID
364
+ # @return [List of Participant] response from the API call
365
+ def list_session_participants(account_id,
366
+ session_id)
367
+ # Prepare query url.
368
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
369
+ _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants'
370
+ _query_builder = APIHelper.append_url_with_template_parameters(
371
+ _query_builder,
372
+ 'accountId' => account_id,
373
+ 'sessionId' => session_id
374
+ )
375
+ _query_url = APIHelper.clean_url _query_builder
376
+
377
+ # Prepare headers.
378
+ _headers = {
379
+ 'accept' => 'application/json'
380
+ }
381
+
382
+ # Prepare and execute HttpRequest.
383
+ _request = config.http_client.get(
384
+ _query_url,
385
+ headers: _headers
386
+ )
387
+ WebRtcBasicAuth.apply(config, _request)
388
+ _response = execute_request(_request)
389
+
390
+ # Validate response against endpoint and global error codes.
391
+ if _response.status_code == 401
392
+ raise APIException.new(
393
+ 'Unauthorized',
394
+ _response
395
+ )
396
+ elsif _response.status_code == 403
397
+ raise APIException.new(
398
+ 'Access Denied',
399
+ _response
400
+ )
401
+ elsif _response.status_code == 404
402
+ raise APIException.new(
403
+ 'Not Found',
404
+ _response
405
+ )
406
+ end
407
+ unless _response.status_code.between?(200, 208)
408
+ raise ErrorException.new(
409
+ 'Unexpected Error',
410
+ _response
411
+ )
412
+ end
413
+ validate_response(_response)
414
+
415
+ # Return appropriate response type.
416
+ decoded = APIHelper.json_deserialize(_response.raw_body)
417
+ ApiResponse.new(
418
+ _response,
419
+ data: decoded.map { |element| Participant.from_hash(element) }
420
+ )
421
+ end
422
+
423
+ # Add a participant to a session
424
+ # Subscriptions can optionally be provided as part of this call
425
+ # @param [String] account_id Required parameter: Account ID
426
+ # @param [String] session_id Required parameter: Session ID
427
+ # @param [String] participant_id Required parameter: Participant ID
428
+ # @param [Subscriptions] body Optional parameter: Subscriptions the
429
+ # participant should be created with
430
+ # @return [void] response from the API call
431
+ def add_participant_to_session(account_id,
432
+ session_id,
433
+ participant_id,
434
+ body: nil)
435
+ # Prepare query url.
436
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
437
+ _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}'
438
+ _query_builder = APIHelper.append_url_with_template_parameters(
439
+ _query_builder,
440
+ 'accountId' => account_id,
441
+ 'sessionId' => session_id,
442
+ 'participantId' => participant_id
443
+ )
444
+ _query_url = APIHelper.clean_url _query_builder
445
+
446
+ # Prepare headers.
447
+ _headers = {
448
+ 'content-type' => 'application/json; charset=utf-8'
449
+ }
450
+
451
+ # Prepare and execute HttpRequest.
452
+ _request = config.http_client.put(
453
+ _query_url,
454
+ headers: _headers,
455
+ parameters: body.to_json
456
+ )
457
+ WebRtcBasicAuth.apply(config, _request)
458
+ _response = execute_request(_request)
459
+
460
+ # Validate response against endpoint and global error codes.
461
+ if _response.status_code == 401
462
+ raise APIException.new(
463
+ 'Unauthorized',
464
+ _response
465
+ )
466
+ elsif _response.status_code == 403
467
+ raise APIException.new(
468
+ 'Access Denied',
469
+ _response
470
+ )
471
+ elsif _response.status_code == 404
472
+ raise APIException.new(
473
+ 'Not Found',
474
+ _response
475
+ )
476
+ end
477
+ unless _response.status_code.between?(200, 208)
478
+ raise ErrorException.new(
479
+ 'Unexpected Error',
480
+ _response
481
+ )
482
+ end
483
+ validate_response(_response)
484
+
485
+ # Return appropriate response type.
486
+ ApiResponse.new(_response)
487
+ end
488
+
489
+ # Remove a participant from a session
490
+ # This will automatically remove any subscriptions the participant has
491
+ # associated with this session
492
+ # @param [String] account_id Required parameter: Account ID
493
+ # @param [String] participant_id Required parameter: Participant ID
494
+ # @param [String] session_id Required parameter: Session ID
495
+ # @return [void] response from the API call
496
+ def remove_participant_from_session(account_id,
497
+ participant_id,
498
+ session_id)
499
+ # Prepare query url.
500
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
501
+ _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}'
502
+ _query_builder = APIHelper.append_url_with_template_parameters(
503
+ _query_builder,
504
+ 'accountId' => account_id,
505
+ 'participantId' => participant_id,
506
+ 'sessionId' => session_id
507
+ )
508
+ _query_url = APIHelper.clean_url _query_builder
509
+
510
+ # Prepare and execute HttpRequest.
511
+ _request = config.http_client.delete(
512
+ _query_url
513
+ )
514
+ WebRtcBasicAuth.apply(config, _request)
515
+ _response = execute_request(_request)
516
+
517
+ # Validate response against endpoint and global error codes.
518
+ if _response.status_code == 401
519
+ raise APIException.new(
520
+ 'Unauthorized',
521
+ _response
522
+ )
523
+ elsif _response.status_code == 403
524
+ raise APIException.new(
525
+ 'Access Denied',
526
+ _response
527
+ )
528
+ elsif _response.status_code == 404
529
+ raise APIException.new(
530
+ 'Not Found',
531
+ _response
532
+ )
533
+ end
534
+ unless _response.status_code.between?(200, 208)
535
+ raise ErrorException.new(
536
+ 'Unexpected Error',
537
+ _response
538
+ )
539
+ end
540
+ validate_response(_response)
541
+
542
+ # Return appropriate response type.
543
+ ApiResponse.new(_response)
544
+ end
545
+
546
+ # Get a participant's subscriptions
547
+ # @param [String] account_id Required parameter: Account ID
548
+ # @param [String] participant_id Required parameter: Participant ID
549
+ # @param [String] session_id Required parameter: Session ID
550
+ # @return [Subscriptions] response from the API call
551
+ def get_participant_subscriptions(account_id,
552
+ participant_id,
553
+ session_id)
554
+ # Prepare query url.
555
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
556
+ _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions'
557
+ _query_builder = APIHelper.append_url_with_template_parameters(
558
+ _query_builder,
559
+ 'accountId' => account_id,
560
+ 'participantId' => participant_id,
561
+ 'sessionId' => session_id
562
+ )
563
+ _query_url = APIHelper.clean_url _query_builder
564
+
565
+ # Prepare headers.
566
+ _headers = {
567
+ 'accept' => 'application/json'
568
+ }
569
+
570
+ # Prepare and execute HttpRequest.
571
+ _request = config.http_client.get(
572
+ _query_url,
573
+ headers: _headers
574
+ )
575
+ WebRtcBasicAuth.apply(config, _request)
576
+ _response = execute_request(_request)
577
+
578
+ # Validate response against endpoint and global error codes.
579
+ if _response.status_code == 401
580
+ raise APIException.new(
581
+ 'Unauthorized',
582
+ _response
583
+ )
584
+ elsif _response.status_code == 403
585
+ raise APIException.new(
586
+ 'Access Denied',
587
+ _response
588
+ )
589
+ elsif _response.status_code == 404
590
+ raise APIException.new(
591
+ 'Not Found',
592
+ _response
593
+ )
594
+ end
595
+ unless _response.status_code.between?(200, 208)
596
+ raise ErrorException.new(
597
+ 'Unexpected Error',
598
+ _response
599
+ )
600
+ end
601
+ validate_response(_response)
602
+
603
+ # Return appropriate response type.
604
+ decoded = APIHelper.json_deserialize(_response.raw_body)
605
+ ApiResponse.new(_response, data: Subscriptions.from_hash(decoded))
606
+ end
607
+
608
+ # Update a participant's subscriptions
609
+ # This is a full update that will replace the participant's subscriptions.
610
+ # First call `getParticipantSubscriptions` if you need the current
611
+ # subscriptions. Call this function with no `Subscriptions` object to remove
612
+ # all subscriptions
613
+ # @param [String] account_id Required parameter: Account ID
614
+ # @param [String] participant_id Required parameter: Participant ID
615
+ # @param [String] session_id Required parameter: Session ID
616
+ # @param [Subscriptions] body Optional parameter: Initial state
617
+ # @return [void] response from the API call
618
+ def update_participant_subscriptions(account_id,
619
+ participant_id,
620
+ session_id,
621
+ body: nil)
622
+ # Prepare query url.
623
+ _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
624
+ _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions'
625
+ _query_builder = APIHelper.append_url_with_template_parameters(
626
+ _query_builder,
627
+ 'accountId' => account_id,
628
+ 'participantId' => participant_id,
629
+ 'sessionId' => session_id
630
+ )
631
+ _query_url = APIHelper.clean_url _query_builder
632
+
633
+ # Prepare headers.
634
+ _headers = {
635
+ 'content-type' => 'application/json; charset=utf-8'
636
+ }
637
+
638
+ # Prepare and execute HttpRequest.
639
+ _request = config.http_client.put(
640
+ _query_url,
641
+ headers: _headers,
642
+ parameters: body.to_json
643
+ )
644
+ WebRtcBasicAuth.apply(config, _request)
645
+ _response = execute_request(_request)
646
+
647
+ # Validate response against endpoint and global error codes.
648
+ if _response.status_code == 400
649
+ raise APIException.new(
650
+ 'Bad Request',
651
+ _response
652
+ )
653
+ elsif _response.status_code == 401
654
+ raise APIException.new(
655
+ 'Unauthorized',
656
+ _response
657
+ )
658
+ elsif _response.status_code == 403
659
+ raise APIException.new(
660
+ 'Access Denied',
661
+ _response
662
+ )
663
+ elsif _response.status_code == 404
664
+ raise APIException.new(
665
+ 'Not Found',
666
+ _response
667
+ )
668
+ end
669
+ unless _response.status_code.between?(200, 208)
670
+ raise ErrorException.new(
671
+ 'Unexpected Error',
672
+ _response
673
+ )
674
+ end
675
+ validate_response(_response)
676
+
677
+ # Return appropriate response type.
678
+ ApiResponse.new(_response)
679
+ end
680
+ end
681
+ end
682
+ end