bandwidth-sdk 6.2.0 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bandwidth/api_helper.rb +19 -29
- data/lib/bandwidth/client.rb +8 -8
- data/lib/bandwidth/configuration.rb +20 -32
- data/lib/bandwidth/http/auth/{two_factor_auth_basic_auth.rb → multi_factor_auth_basic_auth.rb} +3 -3
- data/lib/bandwidth/http/faraday_client.rb +1 -1
- data/lib/bandwidth/messaging_lib/messaging/client.rb +14 -5
- data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +78 -71
- data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +3 -5
- data/lib/bandwidth/messaging_lib/messaging/exceptions/messaging_exception.rb +5 -2
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_callback_message.rb +31 -11
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +54 -25
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +102 -24
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_messages_list.rb +23 -4
- data/lib/bandwidth/messaging_lib/messaging/models/deferred_result.rb +20 -4
- data/lib/bandwidth/messaging_lib/messaging/models/media.rb +27 -80
- data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +32 -14
- data/lib/bandwidth/messaging_lib/messaging/models/page_info.rb +28 -8
- data/lib/bandwidth/messaging_lib/messaging/models/tag.rb +20 -4
- data/lib/bandwidth/models/base_model.rb +30 -8
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/client.rb +15 -6
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/controllers/base_controller.rb +3 -5
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/controllers/mfa_controller.rb +28 -23
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/exceptions/error_with_request_exception.rb +5 -2
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/exceptions/forbidden_request_exception.rb +4 -1
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/exceptions/unauthorized_request_exception.rb +4 -1
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_code_request_schema.rb +27 -12
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_messaging_response.rb +17 -2
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_verify_code_response.rb +17 -2
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_verify_request_schema.rb +29 -10
- data/lib/bandwidth/{two_factor_auth_lib/two_factor_auth → multi_factor_auth_lib/multi_factor_auth}/models/two_factor_voice_response.rb +17 -2
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth.rb +23 -0
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/controllers/api_controller.rb +212 -210
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/controllers/base_controller.rb +3 -5
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/exceptions/accounts_tnlookup400_error_exception.rb +4 -1
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_request.rb +17 -2
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_response.rb +20 -4
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/order_status.rb +28 -7
- data/lib/bandwidth/phone_number_lookup_lib/phone_number_lookup/models/result.rb +43 -18
- data/lib/bandwidth/utilities/date_time_helper.rb +156 -0
- data/lib/bandwidth/utilities/file_wrapper.rb +1 -2
- data/lib/bandwidth/voice_lib/voice/client.rb +14 -5
- data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +418 -379
- data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +3 -5
- data/lib/bandwidth/voice_lib/voice/exceptions/{api_error_response_exception.rb → api_error_exception.rb} +8 -5
- data/lib/bandwidth/voice_lib/voice/models/call_callback.rb +343 -0
- data/lib/bandwidth/voice_lib/voice/models/call_recording_metadata.rb +250 -0
- data/lib/bandwidth/voice_lib/voice/models/call_state.rb +284 -0
- data/lib/bandwidth/voice_lib/voice/models/callback_method_enum.rb +2 -20
- data/lib/bandwidth/voice_lib/voice/models/conference_callback.rb +211 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_event_method_enum.rb +2 -20
- data/lib/bandwidth/voice_lib/voice/models/{conference_member_detail.rb → conference_member_state.rb} +43 -20
- data/lib/bandwidth/voice_lib/voice/models/conference_recording_metadata.rb +173 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_state.rb +153 -0
- data/lib/bandwidth/voice_lib/voice/models/create_call_request.rb +301 -0
- data/lib/bandwidth/voice_lib/voice/models/create_call_response.rb +256 -0
- data/lib/bandwidth/voice_lib/voice/models/diversion.rb +80 -0
- data/lib/bandwidth/voice_lib/voice/models/fallback_method_enum.rb +17 -0
- data/lib/bandwidth/voice_lib/voice/models/machine_detection_configuration.rb +218 -0
- data/lib/bandwidth/voice_lib/voice/models/mode_enum.rb +20 -0
- data/lib/bandwidth/voice_lib/voice/models/{modify_call_recording_state.rb → modify_call_recording_request.rb} +19 -6
- data/lib/bandwidth/voice_lib/voice/models/modify_call_request.rb +156 -0
- data/lib/bandwidth/voice_lib/voice/models/modify_conference_request.rb +144 -0
- data/lib/bandwidth/voice_lib/voice/models/state1_enum.rb +7 -4
- data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +4 -7
- data/lib/bandwidth/voice_lib/voice/models/transcribe_recording_request.rb +108 -0
- data/lib/bandwidth/voice_lib/voice/models/transcript.rb +20 -4
- data/lib/bandwidth/voice_lib/voice/models/transcription.rb +35 -17
- data/lib/bandwidth/voice_lib/voice/models/transcription_metadata.rb +89 -0
- data/lib/bandwidth/voice_lib/voice/models/transcription_response.rb +18 -1
- data/lib/bandwidth/voice_lib/voice.rb +20 -18
- data/lib/bandwidth/web_rtc_lib/utils/web_rtc_transfer.rb +7 -2
- data/lib/bandwidth/web_rtc_lib/web_rtc/client.rb +4 -4
- data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +75 -64
- data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/base_controller.rb +3 -5
- data/lib/bandwidth/web_rtc_lib/web_rtc/exceptions/error_exception.rb +5 -2
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/accounts_participants_response.rb +20 -5
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant.rb +37 -14
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant_subscription.rb +15 -2
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/session.rb +20 -4
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/subscriptions.rb +20 -3
- data/lib/bandwidth.rb +20 -18
- data/test/integration/test_integration.rb +92 -57
- metadata +35 -31
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb +0 -22
- data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +0 -207
- data/lib/bandwidth/voice_lib/voice/models/api_call_state_response.rb +0 -164
- data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +0 -248
- data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +0 -116
- data/lib/bandwidth/voice_lib/voice/models/api_modify_conference_request.rb +0 -107
- data/lib/bandwidth/voice_lib/voice/models/api_transcribe_recording_request.rb +0 -80
- data/lib/bandwidth/voice_lib/voice/models/conference_detail.rb +0 -108
- data/lib/bandwidth/voice_lib/voice/models/conference_recording_metadata_response.rb +0 -126
- data/lib/bandwidth/voice_lib/voice/models/disconnect_cause_enum.rb +0 -47
- data/lib/bandwidth/voice_lib/voice/models/recording_metadata_response.rb +0 -190
- data/lib/bandwidth/voice_lib/voice/models/state2_enum.rb +0 -20
- data/lib/bandwidth/voice_lib/voice/models/status1_enum.rb +0 -29
- data/lib/bandwidth/voice_lib/voice/models/status3_enum.rb +0 -32
@@ -11,19 +11,19 @@ module Messaging
|
|
11
11
|
super(config, http_call_back: http_call_back)
|
12
12
|
end
|
13
13
|
|
14
|
-
#
|
15
|
-
# @param [String]
|
14
|
+
# Gets a list of your media files. No query parameters are supported.
|
15
|
+
# @param [String] account_id Required parameter: User's account ID
|
16
16
|
# @param [String] continuation_token Optional parameter: Continuation token
|
17
17
|
# used to retrieve subsequent media.
|
18
18
|
# @return [List of Media] response from the API call
|
19
|
-
def list_media(
|
19
|
+
def list_media(account_id,
|
20
20
|
continuation_token: nil)
|
21
21
|
# Prepare query url.
|
22
22
|
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
23
|
-
_query_builder << '/users/{
|
23
|
+
_query_builder << '/users/{accountId}/media'
|
24
24
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
25
25
|
_query_builder,
|
26
|
-
'
|
26
|
+
'accountId' => { 'value' => account_id, 'encode' => false }
|
27
27
|
)
|
28
28
|
_query_url = APIHelper.clean_url _query_builder
|
29
29
|
|
@@ -42,32 +42,33 @@ module Messaging
|
|
42
42
|
_response = execute_request(_request)
|
43
43
|
|
44
44
|
# Validate response against endpoint and global error codes.
|
45
|
-
|
45
|
+
case _response.status_code
|
46
|
+
when 400
|
46
47
|
raise MessagingException.new(
|
47
48
|
'400 Request is malformed or invalid',
|
48
49
|
_response
|
49
50
|
)
|
50
|
-
|
51
|
+
when 401
|
51
52
|
raise MessagingException.new(
|
52
53
|
'401 The specified user does not have access to the account',
|
53
54
|
_response
|
54
55
|
)
|
55
|
-
|
56
|
+
when 403
|
56
57
|
raise MessagingException.new(
|
57
58
|
'403 The user does not have access to this API',
|
58
59
|
_response
|
59
60
|
)
|
60
|
-
|
61
|
+
when 404
|
61
62
|
raise MessagingException.new(
|
62
63
|
'404 Path not found',
|
63
64
|
_response
|
64
65
|
)
|
65
|
-
|
66
|
+
when 415
|
66
67
|
raise MessagingException.new(
|
67
68
|
'415 The content-type of the request is incorrect',
|
68
69
|
_response
|
69
70
|
)
|
70
|
-
|
71
|
+
when 429
|
71
72
|
raise MessagingException.new(
|
72
73
|
'429 The rate limit has been reached',
|
73
74
|
_response
|
@@ -83,18 +84,18 @@ module Messaging
|
|
83
84
|
)
|
84
85
|
end
|
85
86
|
|
86
|
-
#
|
87
|
-
# @param [String]
|
87
|
+
# Downloads a media file you previously uploaded.
|
88
|
+
# @param [String] account_id Required parameter: User's account ID
|
88
89
|
# @param [String] media_id Required parameter: Media ID to retrieve
|
89
90
|
# @return [Binary] response from the API call
|
90
|
-
def get_media(
|
91
|
+
def get_media(account_id,
|
91
92
|
media_id)
|
92
93
|
# Prepare query url.
|
93
94
|
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
94
|
-
_query_builder << '/users/{
|
95
|
+
_query_builder << '/users/{accountId}/media/{mediaId}'
|
95
96
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
96
97
|
_query_builder,
|
97
|
-
'
|
98
|
+
'accountId' => { 'value' => account_id, 'encode' => false },
|
98
99
|
'mediaId' => { 'value' => media_id, 'encode' => false }
|
99
100
|
)
|
100
101
|
_query_url = APIHelper.clean_url _query_builder
|
@@ -107,32 +108,33 @@ module Messaging
|
|
107
108
|
_response = execute_request(_request, binary: true)
|
108
109
|
|
109
110
|
# Validate response against endpoint and global error codes.
|
110
|
-
|
111
|
+
case _response.status_code
|
112
|
+
when 400
|
111
113
|
raise MessagingException.new(
|
112
114
|
'400 Request is malformed or invalid',
|
113
115
|
_response
|
114
116
|
)
|
115
|
-
|
117
|
+
when 401
|
116
118
|
raise MessagingException.new(
|
117
119
|
'401 The specified user does not have access to the account',
|
118
120
|
_response
|
119
121
|
)
|
120
|
-
|
122
|
+
when 403
|
121
123
|
raise MessagingException.new(
|
122
124
|
'403 The user does not have access to this API',
|
123
125
|
_response
|
124
126
|
)
|
125
|
-
|
127
|
+
when 404
|
126
128
|
raise MessagingException.new(
|
127
129
|
'404 Path not found',
|
128
130
|
_response
|
129
131
|
)
|
130
|
-
|
132
|
+
when 415
|
131
133
|
raise MessagingException.new(
|
132
134
|
'415 The content-type of the request is incorrect',
|
133
135
|
_response
|
134
136
|
)
|
135
|
-
|
137
|
+
when 429
|
136
138
|
raise MessagingException.new(
|
137
139
|
'429 The rate limit has been reached',
|
138
140
|
_response
|
@@ -146,12 +148,11 @@ module Messaging
|
|
146
148
|
)
|
147
149
|
end
|
148
150
|
|
149
|
-
#
|
150
|
-
#
|
151
|
+
# Uploads a file the normal HTTP way. You may add headers to the request in
|
152
|
+
# order to provide some control to your media-file.
|
153
|
+
# @param [String] account_id Required parameter: User's account ID
|
151
154
|
# @param [String] media_id Required parameter: The user supplied custom
|
152
155
|
# media ID
|
153
|
-
# @param [Long] content_length Required parameter: The size of the
|
154
|
-
# entity-body
|
155
156
|
# @param [File | UploadIO] body Required parameter: Example:
|
156
157
|
# @param [String] content_type Optional parameter: The media type of the
|
157
158
|
# entity-body
|
@@ -159,18 +160,17 @@ module Messaging
|
|
159
160
|
# used to specify directives that MUST be obeyed by all caching mechanisms
|
160
161
|
# along the request/response chain.
|
161
162
|
# @return [void] response from the API call
|
162
|
-
def upload_media(
|
163
|
+
def upload_media(account_id,
|
163
164
|
media_id,
|
164
|
-
content_length,
|
165
165
|
body,
|
166
166
|
content_type: 'application/octet-stream',
|
167
167
|
cache_control: nil)
|
168
168
|
# Prepare query url.
|
169
169
|
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
170
|
-
_query_builder << '/users/{
|
170
|
+
_query_builder << '/users/{accountId}/media/{mediaId}'
|
171
171
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
172
172
|
_query_builder,
|
173
|
-
'
|
173
|
+
'accountId' => { 'value' => account_id, 'encode' => false },
|
174
174
|
'mediaId' => { 'value' => media_id, 'encode' => false }
|
175
175
|
)
|
176
176
|
_query_url = APIHelper.clean_url _query_builder
|
@@ -187,7 +187,6 @@ module Messaging
|
|
187
187
|
_headers = {
|
188
188
|
'content-type' => body_content_type,
|
189
189
|
'content-length' => body_wrapper.size.to_s,
|
190
|
-
'Content-Length' => content_length,
|
191
190
|
'Cache-Control' => cache_control
|
192
191
|
}
|
193
192
|
|
@@ -201,32 +200,33 @@ module Messaging
|
|
201
200
|
_response = execute_request(_request)
|
202
201
|
|
203
202
|
# Validate response against endpoint and global error codes.
|
204
|
-
|
203
|
+
case _response.status_code
|
204
|
+
when 400
|
205
205
|
raise MessagingException.new(
|
206
206
|
'400 Request is malformed or invalid',
|
207
207
|
_response
|
208
208
|
)
|
209
|
-
|
209
|
+
when 401
|
210
210
|
raise MessagingException.new(
|
211
211
|
'401 The specified user does not have access to the account',
|
212
212
|
_response
|
213
213
|
)
|
214
|
-
|
214
|
+
when 403
|
215
215
|
raise MessagingException.new(
|
216
216
|
'403 The user does not have access to this API',
|
217
217
|
_response
|
218
218
|
)
|
219
|
-
|
219
|
+
when 404
|
220
220
|
raise MessagingException.new(
|
221
221
|
'404 Path not found',
|
222
222
|
_response
|
223
223
|
)
|
224
|
-
|
224
|
+
when 415
|
225
225
|
raise MessagingException.new(
|
226
226
|
'415 The content-type of the request is incorrect',
|
227
227
|
_response
|
228
228
|
)
|
229
|
-
|
229
|
+
when 429
|
230
230
|
raise MessagingException.new(
|
231
231
|
'429 The rate limit has been reached',
|
232
232
|
_response
|
@@ -238,18 +238,21 @@ module Messaging
|
|
238
238
|
ApiResponse.new(_response)
|
239
239
|
end
|
240
240
|
|
241
|
-
#
|
242
|
-
#
|
241
|
+
# Deletes a media file from Bandwidth API server. Make sure you don't have
|
242
|
+
# any application scripts still using the media before you delete. If you
|
243
|
+
# accidentally delete a media file, you can immediately upload a new file
|
244
|
+
# with the same name.
|
245
|
+
# @param [String] account_id Required parameter: User's account ID
|
243
246
|
# @param [String] media_id Required parameter: The media ID to delete
|
244
247
|
# @return [void] response from the API call
|
245
|
-
def delete_media(
|
248
|
+
def delete_media(account_id,
|
246
249
|
media_id)
|
247
250
|
# Prepare query url.
|
248
251
|
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
249
|
-
_query_builder << '/users/{
|
252
|
+
_query_builder << '/users/{accountId}/media/{mediaId}'
|
250
253
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
251
254
|
_query_builder,
|
252
|
-
'
|
255
|
+
'accountId' => { 'value' => account_id, 'encode' => false },
|
253
256
|
'mediaId' => { 'value' => media_id, 'encode' => false }
|
254
257
|
)
|
255
258
|
_query_url = APIHelper.clean_url _query_builder
|
@@ -262,32 +265,33 @@ module Messaging
|
|
262
265
|
_response = execute_request(_request)
|
263
266
|
|
264
267
|
# Validate response against endpoint and global error codes.
|
265
|
-
|
268
|
+
case _response.status_code
|
269
|
+
when 400
|
266
270
|
raise MessagingException.new(
|
267
271
|
'400 Request is malformed or invalid',
|
268
272
|
_response
|
269
273
|
)
|
270
|
-
|
274
|
+
when 401
|
271
275
|
raise MessagingException.new(
|
272
276
|
'401 The specified user does not have access to the account',
|
273
277
|
_response
|
274
278
|
)
|
275
|
-
|
279
|
+
when 403
|
276
280
|
raise MessagingException.new(
|
277
281
|
'403 The user does not have access to this API',
|
278
282
|
_response
|
279
283
|
)
|
280
|
-
|
284
|
+
when 404
|
281
285
|
raise MessagingException.new(
|
282
286
|
'404 Path not found',
|
283
287
|
_response
|
284
288
|
)
|
285
|
-
|
289
|
+
when 415
|
286
290
|
raise MessagingException.new(
|
287
291
|
'415 The content-type of the request is incorrect',
|
288
292
|
_response
|
289
293
|
)
|
290
|
-
|
294
|
+
when 429
|
291
295
|
raise MessagingException.new(
|
292
296
|
'429 The rate limit has been reached',
|
293
297
|
_response
|
@@ -299,8 +303,8 @@ module Messaging
|
|
299
303
|
ApiResponse.new(_response)
|
300
304
|
end
|
301
305
|
|
302
|
-
#
|
303
|
-
# @param [String]
|
306
|
+
# Gets a list of messages based on query parameters.
|
307
|
+
# @param [String] account_id Required parameter: User's account ID
|
304
308
|
# @param [String] message_id Optional parameter: The ID of the message to
|
305
309
|
# search for. Special characters need to be encoded using URL encoding
|
306
310
|
# @param [String] source_tn Optional parameter: The phone number that sent
|
@@ -309,7 +313,7 @@ module Messaging
|
|
309
313
|
# received the message
|
310
314
|
# @param [String] message_status Optional parameter: The status of the
|
311
315
|
# message. One of RECEIVED, QUEUED, SENDING, SENT, FAILED, DELIVERED,
|
312
|
-
#
|
316
|
+
# ACCEPTED, UNDELIVERED
|
313
317
|
# @param [Integer] error_code Optional parameter: The error code of the
|
314
318
|
# message
|
315
319
|
# @param [String] from_date_time Optional parameter: The start of the date
|
@@ -324,7 +328,7 @@ module Messaging
|
|
324
328
|
# in search result. Default 100. The sum of limit and after cannot be more
|
325
329
|
# than 10000
|
326
330
|
# @return [BandwidthMessagesList] response from the API call
|
327
|
-
def get_messages(
|
331
|
+
def get_messages(account_id,
|
328
332
|
message_id: nil,
|
329
333
|
source_tn: nil,
|
330
334
|
destination_tn: nil,
|
@@ -336,10 +340,10 @@ module Messaging
|
|
336
340
|
limit: nil)
|
337
341
|
# Prepare query url.
|
338
342
|
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
339
|
-
_query_builder << '/users/{
|
343
|
+
_query_builder << '/users/{accountId}/messages'
|
340
344
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
341
345
|
_query_builder,
|
342
|
-
'
|
346
|
+
'accountId' => { 'value' => account_id, 'encode' => false }
|
343
347
|
)
|
344
348
|
_query_builder = APIHelper.append_url_with_query_parameters(
|
345
349
|
_query_builder,
|
@@ -369,32 +373,33 @@ module Messaging
|
|
369
373
|
_response = execute_request(_request)
|
370
374
|
|
371
375
|
# Validate response against endpoint and global error codes.
|
372
|
-
|
376
|
+
case _response.status_code
|
377
|
+
when 400
|
373
378
|
raise MessagingException.new(
|
374
379
|
'400 Request is malformed or invalid',
|
375
380
|
_response
|
376
381
|
)
|
377
|
-
|
382
|
+
when 401
|
378
383
|
raise MessagingException.new(
|
379
384
|
'401 The specified user does not have access to the account',
|
380
385
|
_response
|
381
386
|
)
|
382
|
-
|
387
|
+
when 403
|
383
388
|
raise MessagingException.new(
|
384
389
|
'403 The user does not have access to this API',
|
385
390
|
_response
|
386
391
|
)
|
387
|
-
|
392
|
+
when 404
|
388
393
|
raise MessagingException.new(
|
389
394
|
'404 Path not found',
|
390
395
|
_response
|
391
396
|
)
|
392
|
-
|
397
|
+
when 415
|
393
398
|
raise MessagingException.new(
|
394
399
|
'415 The content-type of the request is incorrect',
|
395
400
|
_response
|
396
401
|
)
|
397
|
-
|
402
|
+
when 429
|
398
403
|
raise MessagingException.new(
|
399
404
|
'429 The rate limit has been reached',
|
400
405
|
_response
|
@@ -409,18 +414,19 @@ module Messaging
|
|
409
414
|
)
|
410
415
|
end
|
411
416
|
|
412
|
-
#
|
413
|
-
#
|
417
|
+
# Endpoint for sending text messages and picture messages using V2
|
418
|
+
# messaging.
|
419
|
+
# @param [String] account_id Required parameter: User's account ID
|
414
420
|
# @param [MessageRequest] body Required parameter: Example:
|
415
421
|
# @return [BandwidthMessage] response from the API call
|
416
|
-
def create_message(
|
422
|
+
def create_message(account_id,
|
417
423
|
body)
|
418
424
|
# Prepare query url.
|
419
425
|
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
420
|
-
_query_builder << '/users/{
|
426
|
+
_query_builder << '/users/{accountId}/messages'
|
421
427
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
422
428
|
_query_builder,
|
423
|
-
'
|
429
|
+
'accountId' => { 'value' => account_id, 'encode' => false }
|
424
430
|
)
|
425
431
|
_query_url = APIHelper.clean_url _query_builder
|
426
432
|
|
@@ -440,32 +446,33 @@ module Messaging
|
|
440
446
|
_response = execute_request(_request)
|
441
447
|
|
442
448
|
# Validate response against endpoint and global error codes.
|
443
|
-
|
449
|
+
case _response.status_code
|
450
|
+
when 400
|
444
451
|
raise MessagingException.new(
|
445
452
|
'400 Request is malformed or invalid',
|
446
453
|
_response
|
447
454
|
)
|
448
|
-
|
455
|
+
when 401
|
449
456
|
raise MessagingException.new(
|
450
457
|
'401 The specified user does not have access to the account',
|
451
458
|
_response
|
452
459
|
)
|
453
|
-
|
460
|
+
when 403
|
454
461
|
raise MessagingException.new(
|
455
462
|
'403 The user does not have access to this API',
|
456
463
|
_response
|
457
464
|
)
|
458
|
-
|
465
|
+
when 404
|
459
466
|
raise MessagingException.new(
|
460
467
|
'404 Path not found',
|
461
468
|
_response
|
462
469
|
)
|
463
|
-
|
470
|
+
when 415
|
464
471
|
raise MessagingException.new(
|
465
472
|
'415 The content-type of the request is incorrect',
|
466
473
|
_response
|
467
474
|
)
|
468
|
-
|
475
|
+
when 429
|
469
476
|
raise MessagingException.new(
|
470
477
|
'429 The rate limit has been reached',
|
471
478
|
_response
|
@@ -19,14 +19,12 @@ module Bandwidth
|
|
19
19
|
|
20
20
|
def validate_parameters(args)
|
21
21
|
args.each do |_name, value|
|
22
|
-
if value.nil?
|
23
|
-
raise ArgumentError, "Required parameter #{_name} cannot be nil."
|
24
|
-
end
|
22
|
+
raise ArgumentError, "Required parameter #{_name} cannot be nil." if value.nil?
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
26
|
def execute_request(request, binary: false)
|
29
|
-
@http_call_back
|
27
|
+
@http_call_back&.on_before_request(request)
|
30
28
|
|
31
29
|
APIHelper.clean_hash(request.headers)
|
32
30
|
request.headers.merge!(@global_headers)
|
@@ -36,7 +34,7 @@ module Bandwidth
|
|
36
34
|
else
|
37
35
|
config.http_client.execute_as_string(request)
|
38
36
|
end
|
39
|
-
@http_call_back
|
37
|
+
@http_call_back&.on_after_response(response)
|
40
38
|
|
41
39
|
response
|
42
40
|
end
|
@@ -6,6 +6,9 @@
|
|
6
6
|
module Bandwidth
|
7
7
|
# MessagingException class.
|
8
8
|
class MessagingException < APIException
|
9
|
+
SKIP = Object.new
|
10
|
+
private_constant :SKIP
|
11
|
+
|
9
12
|
# TODO: Write general description for this method
|
10
13
|
# @return [String]
|
11
14
|
attr_accessor :type
|
@@ -27,8 +30,8 @@ module Bandwidth
|
|
27
30
|
# @param [Hash] The deserialized response sent by the server in the
|
28
31
|
# response body.
|
29
32
|
def unbox(hash)
|
30
|
-
@type = hash['type']
|
31
|
-
@description = hash['description']
|
33
|
+
@type = hash.key?('type') ? hash['type'] : SKIP
|
34
|
+
@description = hash.key?('description') ? hash['description'] : SKIP
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -6,6 +6,9 @@
|
|
6
6
|
module Bandwidth
|
7
7
|
# BandwidthCallbackMessage Model.
|
8
8
|
class BandwidthCallbackMessage < BaseModel
|
9
|
+
SKIP = Object.new
|
10
|
+
private_constant :SKIP
|
11
|
+
|
9
12
|
# TODO: Write general description for this method
|
10
13
|
# @return [String]
|
11
14
|
attr_accessor :time
|
@@ -42,18 +45,35 @@ module Bandwidth
|
|
42
45
|
@_hash
|
43
46
|
end
|
44
47
|
|
48
|
+
# An array for optional fields
|
49
|
+
def optionals
|
50
|
+
%w[
|
51
|
+
time
|
52
|
+
type
|
53
|
+
to
|
54
|
+
error_code
|
55
|
+
description
|
56
|
+
message
|
57
|
+
]
|
58
|
+
end
|
59
|
+
|
60
|
+
# An array for nullable fields
|
61
|
+
def nullables
|
62
|
+
[]
|
63
|
+
end
|
64
|
+
|
45
65
|
def initialize(time = nil,
|
46
66
|
type = nil,
|
47
67
|
to = nil,
|
48
68
|
error_code = nil,
|
49
69
|
description = nil,
|
50
70
|
message = nil)
|
51
|
-
@time = time
|
52
|
-
@type = type
|
53
|
-
@to = to
|
54
|
-
@error_code = error_code
|
55
|
-
@description = description
|
56
|
-
@message = message
|
71
|
+
@time = time unless time == SKIP
|
72
|
+
@type = type unless type == SKIP
|
73
|
+
@to = to unless to == SKIP
|
74
|
+
@error_code = error_code unless error_code == SKIP
|
75
|
+
@description = description unless description == SKIP
|
76
|
+
@message = message unless message == SKIP
|
57
77
|
end
|
58
78
|
|
59
79
|
# Creates an instance of the object from a hash.
|
@@ -61,11 +81,11 @@ module Bandwidth
|
|
61
81
|
return nil unless hash
|
62
82
|
|
63
83
|
# Extract variables from the hash.
|
64
|
-
time = hash['time']
|
65
|
-
type = hash['type']
|
66
|
-
to = hash['to']
|
67
|
-
error_code = hash['errorCode']
|
68
|
-
description = hash['description']
|
84
|
+
time = hash.key?('time') ? hash['time'] : SKIP
|
85
|
+
type = hash.key?('type') ? hash['type'] : SKIP
|
86
|
+
to = hash.key?('to') ? hash['to'] : SKIP
|
87
|
+
error_code = hash.key?('errorCode') ? hash['errorCode'] : SKIP
|
88
|
+
description = hash.key?('description') ? hash['description'] : SKIP
|
69
89
|
message = BandwidthMessage.from_hash(hash['message']) if hash['message']
|
70
90
|
|
71
91
|
# Create object from extracted values.
|
@@ -6,6 +6,9 @@
|
|
6
6
|
module Bandwidth
|
7
7
|
# BandwidthMessage Model.
|
8
8
|
class BandwidthMessage < BaseModel
|
9
|
+
SKIP = Object.new
|
10
|
+
private_constant :SKIP
|
11
|
+
|
9
12
|
# The id of the message
|
10
13
|
# @return [String]
|
11
14
|
attr_accessor :id
|
@@ -39,7 +42,10 @@ module Bandwidth
|
|
39
42
|
# @return [String]
|
40
43
|
attr_accessor :from
|
41
44
|
|
42
|
-
# The list of media URLs sent in the message
|
45
|
+
# The list of media URLs sent in the message. Including a `filename` field
|
46
|
+
# in the `Content-Disposition` header of the media linked with a URL will
|
47
|
+
# set the displayed file name. This is a best practice to ensure that your
|
48
|
+
# media has a readable file name.
|
43
49
|
# @return [List of String]
|
44
50
|
attr_accessor :media
|
45
51
|
|
@@ -73,6 +79,29 @@ module Bandwidth
|
|
73
79
|
@_hash
|
74
80
|
end
|
75
81
|
|
82
|
+
# An array for optional fields
|
83
|
+
def optionals
|
84
|
+
%w[
|
85
|
+
id
|
86
|
+
owner
|
87
|
+
application_id
|
88
|
+
time
|
89
|
+
segment_count
|
90
|
+
direction
|
91
|
+
to
|
92
|
+
from
|
93
|
+
media
|
94
|
+
text
|
95
|
+
tag
|
96
|
+
priority
|
97
|
+
]
|
98
|
+
end
|
99
|
+
|
100
|
+
# An array for nullable fields
|
101
|
+
def nullables
|
102
|
+
[]
|
103
|
+
end
|
104
|
+
|
76
105
|
def initialize(id = nil,
|
77
106
|
owner = nil,
|
78
107
|
application_id = nil,
|
@@ -85,18 +114,18 @@ module Bandwidth
|
|
85
114
|
text = nil,
|
86
115
|
tag = nil,
|
87
116
|
priority = nil)
|
88
|
-
@id = id
|
89
|
-
@owner = owner
|
90
|
-
@application_id = application_id
|
91
|
-
@time = time
|
92
|
-
@segment_count = segment_count
|
93
|
-
@direction = direction
|
94
|
-
@to = to
|
95
|
-
@from = from
|
96
|
-
@media = media
|
97
|
-
@text = text
|
98
|
-
@tag = tag
|
99
|
-
@priority = priority
|
117
|
+
@id = id unless id == SKIP
|
118
|
+
@owner = owner unless owner == SKIP
|
119
|
+
@application_id = application_id unless application_id == SKIP
|
120
|
+
@time = time unless time == SKIP
|
121
|
+
@segment_count = segment_count unless segment_count == SKIP
|
122
|
+
@direction = direction unless direction == SKIP
|
123
|
+
@to = to unless to == SKIP
|
124
|
+
@from = from unless from == SKIP
|
125
|
+
@media = media unless media == SKIP
|
126
|
+
@text = text unless text == SKIP
|
127
|
+
@tag = tag unless tag == SKIP
|
128
|
+
@priority = priority unless priority == SKIP
|
100
129
|
end
|
101
130
|
|
102
131
|
# Creates an instance of the object from a hash.
|
@@ -104,18 +133,18 @@ module Bandwidth
|
|
104
133
|
return nil unless hash
|
105
134
|
|
106
135
|
# Extract variables from the hash.
|
107
|
-
id = hash['id']
|
108
|
-
owner = hash['owner']
|
109
|
-
application_id = hash['applicationId']
|
110
|
-
time = hash['time']
|
111
|
-
segment_count = hash['segmentCount']
|
112
|
-
direction = hash['direction']
|
113
|
-
to = hash['to']
|
114
|
-
from = hash['from']
|
115
|
-
media = hash['media']
|
116
|
-
text = hash['text']
|
117
|
-
tag = hash['tag']
|
118
|
-
priority = hash['priority']
|
136
|
+
id = hash.key?('id') ? hash['id'] : SKIP
|
137
|
+
owner = hash.key?('owner') ? hash['owner'] : SKIP
|
138
|
+
application_id = hash.key?('applicationId') ? hash['applicationId'] : SKIP
|
139
|
+
time = hash.key?('time') ? hash['time'] : SKIP
|
140
|
+
segment_count = hash.key?('segmentCount') ? hash['segmentCount'] : SKIP
|
141
|
+
direction = hash.key?('direction') ? hash['direction'] : SKIP
|
142
|
+
to = hash.key?('to') ? hash['to'] : SKIP
|
143
|
+
from = hash.key?('from') ? hash['from'] : SKIP
|
144
|
+
media = hash.key?('media') ? hash['media'] : SKIP
|
145
|
+
text = hash.key?('text') ? hash['text'] : SKIP
|
146
|
+
tag = hash.key?('tag') ? hash['tag'] : SKIP
|
147
|
+
priority = hash.key?('priority') ? hash['priority'] : SKIP
|
119
148
|
|
120
149
|
# Create object from extracted values.
|
121
150
|
BandwidthMessage.new(id,
|