bandwidth-sdk 8.0.0 → 9.0.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.
- checksums.yaml +4 -4
- data/lib/bandwidth/api_helper.rb +19 -17
- data/lib/bandwidth/configuration.rb +7 -19
- data/lib/bandwidth/http/faraday_client.rb +1 -1
- data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +53 -42
- 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 +65 -32
- 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 +23 -6
- 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 +11 -0
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/controllers/base_controller.rb +3 -5
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/controllers/mfa_controller.rb +21 -16
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/exceptions/error_with_request_exception.rb +5 -2
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/exceptions/forbidden_request_exception.rb +4 -1
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/exceptions/unauthorized_request_exception.rb +4 -1
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/models/two_factor_code_request_schema.rb +27 -12
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/models/two_factor_messaging_response.rb +17 -2
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/models/two_factor_verify_code_response.rb +17 -2
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/models/two_factor_verify_request_schema.rb +29 -10
- data/lib/bandwidth/multi_factor_auth_lib/multi_factor_auth/models/two_factor_voice_response.rb +17 -2
- 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 +2 -2
- data/lib/bandwidth/utilities/file_wrapper.rb +1 -2
- data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +171 -150
- data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +3 -5
- data/lib/bandwidth/voice_lib/voice/exceptions/api_error_exception.rb +6 -3
- data/lib/bandwidth/voice_lib/voice/models/call_callback.rb +343 -0
- data/lib/bandwidth/voice_lib/voice/models/call_recording_metadata.rb +78 -37
- data/lib/bandwidth/voice_lib/voice/models/call_state.rb +94 -42
- data/lib/bandwidth/voice_lib/voice/models/conference_callback.rb +211 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_member_state.rb +35 -12
- data/lib/bandwidth/voice_lib/voice/models/conference_recording_metadata.rb +55 -24
- data/lib/bandwidth/voice_lib/voice/models/conference_state.rb +54 -17
- data/lib/bandwidth/voice_lib/voice/models/create_call_request.rb +173 -96
- data/lib/bandwidth/voice_lib/voice/models/create_call_response.rb +85 -41
- 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_request.rb +15 -2
- data/lib/bandwidth/voice_lib/voice/models/modify_call_request.rb +59 -19
- data/lib/bandwidth/voice_lib/voice/models/modify_conference_request.rb +55 -18
- data/lib/bandwidth/voice_lib/voice/models/transcribe_recording_request.rb +40 -12
- data/lib/bandwidth/voice_lib/voice/models/transcript.rb +20 -4
- data/lib/bandwidth/voice_lib/voice/models/transcription.rb +80 -0
- data/lib/bandwidth/voice_lib/voice/models/transcription_metadata.rb +26 -8
- data/lib/bandwidth/voice_lib/voice/models/transcription_response.rb +18 -1
- data/lib/bandwidth/voice_lib/voice.rb +7 -1
- data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +61 -50
- 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 +19 -18
- data/test/integration/test_integration.rb +75 -53
- metadata +9 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ee8c7426138e841e2fea1dbff5d5e3c79372a5cd30c20fe6f2b271104d9101d6
|
|
4
|
+
data.tar.gz: d6463c59e3d52f560968494124e4563a61d7f2aa0b2b0f04f23e92f65f97247a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 255385a80dbc57bccc6dab0f124b9588481eb8075dadce183677b9ca5c7f7d62a65512b876d076d51f051a7de96ca920948e70c4d9b4c1be01cbda03b37f8898
|
|
7
|
+
data.tar.gz: 755608aac58ac160de2711c5c3e8b0e57426a023f32c80dc047a2d3c7ee3d345eeb3188dfdfdaeec315690dac6cb377253799119a816a5ae3d34f3135686e24c
|
data/lib/bandwidth/api_helper.rb
CHANGED
|
@@ -13,13 +13,14 @@ module Bandwidth
|
|
|
13
13
|
def self.serialize_array(key, array, formatting: 'indexed')
|
|
14
14
|
tuples = []
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
case formatting
|
|
17
|
+
when 'unindexed'
|
|
17
18
|
tuples += array.map { |element| ["#{key}[]", element] }
|
|
18
|
-
|
|
19
|
+
when 'indexed'
|
|
19
20
|
tuples += array.map.with_index do |element, index|
|
|
20
21
|
["#{key}[#{index}]", element]
|
|
21
22
|
end
|
|
22
|
-
|
|
23
|
+
when 'plain'
|
|
23
24
|
tuples += array.map { |element| [key, element] }
|
|
24
25
|
else
|
|
25
26
|
raise ArgumentError, 'Invalid format provided.'
|
|
@@ -60,7 +61,7 @@ module Bandwidth
|
|
|
60
61
|
end
|
|
61
62
|
|
|
62
63
|
# Find the template parameter and replace it with its value.
|
|
63
|
-
query_builder = query_builder.gsub(
|
|
64
|
+
query_builder = query_builder.gsub("{#{key}}", replace_value)
|
|
64
65
|
end
|
|
65
66
|
query_builder
|
|
66
67
|
end
|
|
@@ -85,15 +86,16 @@ module Bandwidth
|
|
|
85
86
|
unless value.nil?
|
|
86
87
|
if value.instance_of? Array
|
|
87
88
|
value.compact!
|
|
88
|
-
query_builder +=
|
|
89
|
+
query_builder += case array_serialization
|
|
90
|
+
when 'csv'
|
|
89
91
|
"#{seperator}#{key}=#{value.map do |element|
|
|
90
92
|
CGI.escape(element.to_s)
|
|
91
93
|
end.join(',')}"
|
|
92
|
-
|
|
94
|
+
when 'psv'
|
|
93
95
|
"#{seperator}#{key}=#{value.map do |element|
|
|
94
96
|
CGI.escape(element.to_s)
|
|
95
97
|
end.join('|')}"
|
|
96
|
-
|
|
98
|
+
when 'tsv'
|
|
97
99
|
"#{seperator}#{key}=#{value.map do |element|
|
|
98
100
|
CGI.escape(element.to_s)
|
|
99
101
|
end.join("\t")}"
|
|
@@ -119,7 +121,7 @@ module Bandwidth
|
|
|
119
121
|
raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
|
|
120
122
|
|
|
121
123
|
# Ensure that the urls are absolute.
|
|
122
|
-
matches = url.match(%r{^(https
|
|
124
|
+
matches = url.match(%r{^(https?://[^/]+)})
|
|
123
125
|
raise ArgumentError, 'Invalid Url format.' if matches.nil?
|
|
124
126
|
|
|
125
127
|
# Get the http protocol match.
|
|
@@ -130,7 +132,7 @@ module Bandwidth
|
|
|
130
132
|
|
|
131
133
|
# Remove redundant forward slashes.
|
|
132
134
|
query = url[protocol.length...(!index.nil? ? index : url.length)]
|
|
133
|
-
query.gsub!(%r{
|
|
135
|
+
query.gsub!(%r{//+}, '/')
|
|
134
136
|
|
|
135
137
|
# Get the parameters.
|
|
136
138
|
parameters = !index.nil? ? url[url.index('?')...url.length] : ''
|
|
@@ -142,7 +144,7 @@ module Bandwidth
|
|
|
142
144
|
# Parses JSON string.
|
|
143
145
|
# @param [String] A JSON string.
|
|
144
146
|
def self.json_deserialize(json)
|
|
145
|
-
|
|
147
|
+
JSON.parse(json)
|
|
146
148
|
rescue StandardError
|
|
147
149
|
raise TypeError, 'Server responded with invalid JSON.'
|
|
148
150
|
end
|
|
@@ -171,6 +173,7 @@ module Bandwidth
|
|
|
171
173
|
a.each do |key, value_a|
|
|
172
174
|
b.each do |k, value_b|
|
|
173
175
|
next unless key == k
|
|
176
|
+
|
|
174
177
|
x[k] = []
|
|
175
178
|
if value_a.instance_of? Array
|
|
176
179
|
value_a.each do |v|
|
|
@@ -215,13 +218,12 @@ module Bandwidth
|
|
|
215
218
|
elsif obj.instance_of? Array
|
|
216
219
|
if formatting == 'indexed'
|
|
217
220
|
obj.each_with_index do |value, index|
|
|
218
|
-
retval.merge!(APIHelper.form_encode(value, instance_name
|
|
219
|
-
index.to_s + ']'))
|
|
221
|
+
retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{index}]"))
|
|
220
222
|
end
|
|
221
223
|
elsif serializable_types.map { |x| obj[0].is_a? x }.any?
|
|
222
224
|
obj.each do |value|
|
|
223
225
|
abc = if formatting == 'unindexed'
|
|
224
|
-
APIHelper.form_encode(value, instance_name
|
|
226
|
+
APIHelper.form_encode(value, "#{instance_name}[]",
|
|
225
227
|
formatting: formatting)
|
|
226
228
|
else
|
|
227
229
|
APIHelper.form_encode(value, instance_name,
|
|
@@ -231,14 +233,14 @@ module Bandwidth
|
|
|
231
233
|
end
|
|
232
234
|
else
|
|
233
235
|
obj.each_with_index do |value, index|
|
|
234
|
-
retval.merge!(APIHelper.form_encode(value, instance_name
|
|
235
|
-
|
|
236
|
+
retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{index}]",
|
|
237
|
+
formatting: formatting))
|
|
236
238
|
end
|
|
237
239
|
end
|
|
238
240
|
elsif obj.instance_of? Hash
|
|
239
241
|
obj.each do |key, value|
|
|
240
|
-
retval.merge!(APIHelper.form_encode(value, instance_name
|
|
241
|
-
|
|
242
|
+
retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{key}]",
|
|
243
|
+
formatting: formatting))
|
|
242
244
|
end
|
|
243
245
|
elsif obj.instance_of? File
|
|
244
246
|
retval[instance_name] = UploadIO.new(
|
|
@@ -28,25 +28,13 @@ module Bandwidth
|
|
|
28
28
|
# are configured in this class.
|
|
29
29
|
class Configuration
|
|
30
30
|
# The attribute readers for properties.
|
|
31
|
-
attr_reader :http_client
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
attr_reader :environment
|
|
39
|
-
attr_reader :base_url
|
|
40
|
-
attr_reader :messaging_basic_auth_user_name
|
|
41
|
-
attr_reader :messaging_basic_auth_password
|
|
42
|
-
attr_reader :multi_factor_auth_basic_auth_user_name
|
|
43
|
-
attr_reader :multi_factor_auth_basic_auth_password
|
|
44
|
-
attr_reader :phone_number_lookup_basic_auth_user_name
|
|
45
|
-
attr_reader :phone_number_lookup_basic_auth_password
|
|
46
|
-
attr_reader :voice_basic_auth_user_name
|
|
47
|
-
attr_reader :voice_basic_auth_password
|
|
48
|
-
attr_reader :web_rtc_basic_auth_user_name
|
|
49
|
-
attr_reader :web_rtc_basic_auth_password
|
|
31
|
+
attr_reader :http_client, :timeout, :max_retries, :retry_interval, :backoff_factor,
|
|
32
|
+
:retry_statuses, :retry_methods, :environment, :base_url,
|
|
33
|
+
:messaging_basic_auth_user_name, :messaging_basic_auth_password,
|
|
34
|
+
:multi_factor_auth_basic_auth_user_name, :multi_factor_auth_basic_auth_password,
|
|
35
|
+
:phone_number_lookup_basic_auth_user_name, :phone_number_lookup_basic_auth_password,
|
|
36
|
+
:voice_basic_auth_user_name, :voice_basic_auth_password,
|
|
37
|
+
:web_rtc_basic_auth_user_name, :web_rtc_basic_auth_password
|
|
50
38
|
|
|
51
39
|
class << self
|
|
52
40
|
attr_reader :environments
|
|
@@ -27,7 +27,7 @@ module Bandwidth
|
|
|
27
27
|
methods: retry_methods
|
|
28
28
|
faraday.adapter Faraday.default_adapter
|
|
29
29
|
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
|
30
|
-
faraday.options[:timeout] = timeout if timeout
|
|
30
|
+
faraday.options[:timeout] = timeout if timeout.positive?
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -11,7 +11,7 @@ module Messaging
|
|
|
11
11
|
super(config, http_call_back: http_call_back)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
#
|
|
14
|
+
# Gets a list of your media files. No query parameters are supported.
|
|
15
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.
|
|
@@ -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,7 +84,7 @@ module Messaging
|
|
|
83
84
|
)
|
|
84
85
|
end
|
|
85
86
|
|
|
86
|
-
#
|
|
87
|
+
# Downloads a media file you previously uploaded.
|
|
87
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
|
|
@@ -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,7 +148,8 @@ module Messaging
|
|
|
146
148
|
)
|
|
147
149
|
end
|
|
148
150
|
|
|
149
|
-
#
|
|
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.
|
|
150
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
|
|
@@ -197,32 +200,33 @@ module Messaging
|
|
|
197
200
|
_response = execute_request(_request)
|
|
198
201
|
|
|
199
202
|
# Validate response against endpoint and global error codes.
|
|
200
|
-
|
|
203
|
+
case _response.status_code
|
|
204
|
+
when 400
|
|
201
205
|
raise MessagingException.new(
|
|
202
206
|
'400 Request is malformed or invalid',
|
|
203
207
|
_response
|
|
204
208
|
)
|
|
205
|
-
|
|
209
|
+
when 401
|
|
206
210
|
raise MessagingException.new(
|
|
207
211
|
'401 The specified user does not have access to the account',
|
|
208
212
|
_response
|
|
209
213
|
)
|
|
210
|
-
|
|
214
|
+
when 403
|
|
211
215
|
raise MessagingException.new(
|
|
212
216
|
'403 The user does not have access to this API',
|
|
213
217
|
_response
|
|
214
218
|
)
|
|
215
|
-
|
|
219
|
+
when 404
|
|
216
220
|
raise MessagingException.new(
|
|
217
221
|
'404 Path not found',
|
|
218
222
|
_response
|
|
219
223
|
)
|
|
220
|
-
|
|
224
|
+
when 415
|
|
221
225
|
raise MessagingException.new(
|
|
222
226
|
'415 The content-type of the request is incorrect',
|
|
223
227
|
_response
|
|
224
228
|
)
|
|
225
|
-
|
|
229
|
+
when 429
|
|
226
230
|
raise MessagingException.new(
|
|
227
231
|
'429 The rate limit has been reached',
|
|
228
232
|
_response
|
|
@@ -234,7 +238,10 @@ module Messaging
|
|
|
234
238
|
ApiResponse.new(_response)
|
|
235
239
|
end
|
|
236
240
|
|
|
237
|
-
#
|
|
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.
|
|
238
245
|
# @param [String] account_id Required parameter: User's account ID
|
|
239
246
|
# @param [String] media_id Required parameter: The media ID to delete
|
|
240
247
|
# @return [void] response from the API call
|
|
@@ -258,32 +265,33 @@ module Messaging
|
|
|
258
265
|
_response = execute_request(_request)
|
|
259
266
|
|
|
260
267
|
# Validate response against endpoint and global error codes.
|
|
261
|
-
|
|
268
|
+
case _response.status_code
|
|
269
|
+
when 400
|
|
262
270
|
raise MessagingException.new(
|
|
263
271
|
'400 Request is malformed or invalid',
|
|
264
272
|
_response
|
|
265
273
|
)
|
|
266
|
-
|
|
274
|
+
when 401
|
|
267
275
|
raise MessagingException.new(
|
|
268
276
|
'401 The specified user does not have access to the account',
|
|
269
277
|
_response
|
|
270
278
|
)
|
|
271
|
-
|
|
279
|
+
when 403
|
|
272
280
|
raise MessagingException.new(
|
|
273
281
|
'403 The user does not have access to this API',
|
|
274
282
|
_response
|
|
275
283
|
)
|
|
276
|
-
|
|
284
|
+
when 404
|
|
277
285
|
raise MessagingException.new(
|
|
278
286
|
'404 Path not found',
|
|
279
287
|
_response
|
|
280
288
|
)
|
|
281
|
-
|
|
289
|
+
when 415
|
|
282
290
|
raise MessagingException.new(
|
|
283
291
|
'415 The content-type of the request is incorrect',
|
|
284
292
|
_response
|
|
285
293
|
)
|
|
286
|
-
|
|
294
|
+
when 429
|
|
287
295
|
raise MessagingException.new(
|
|
288
296
|
'429 The rate limit has been reached',
|
|
289
297
|
_response
|
|
@@ -295,7 +303,7 @@ module Messaging
|
|
|
295
303
|
ApiResponse.new(_response)
|
|
296
304
|
end
|
|
297
305
|
|
|
298
|
-
#
|
|
306
|
+
# Gets a list of messages based on query parameters.
|
|
299
307
|
# @param [String] account_id Required parameter: User's account ID
|
|
300
308
|
# @param [String] message_id Optional parameter: The ID of the message to
|
|
301
309
|
# search for. Special characters need to be encoded using URL encoding
|
|
@@ -365,32 +373,33 @@ module Messaging
|
|
|
365
373
|
_response = execute_request(_request)
|
|
366
374
|
|
|
367
375
|
# Validate response against endpoint and global error codes.
|
|
368
|
-
|
|
376
|
+
case _response.status_code
|
|
377
|
+
when 400
|
|
369
378
|
raise MessagingException.new(
|
|
370
379
|
'400 Request is malformed or invalid',
|
|
371
380
|
_response
|
|
372
381
|
)
|
|
373
|
-
|
|
382
|
+
when 401
|
|
374
383
|
raise MessagingException.new(
|
|
375
384
|
'401 The specified user does not have access to the account',
|
|
376
385
|
_response
|
|
377
386
|
)
|
|
378
|
-
|
|
387
|
+
when 403
|
|
379
388
|
raise MessagingException.new(
|
|
380
389
|
'403 The user does not have access to this API',
|
|
381
390
|
_response
|
|
382
391
|
)
|
|
383
|
-
|
|
392
|
+
when 404
|
|
384
393
|
raise MessagingException.new(
|
|
385
394
|
'404 Path not found',
|
|
386
395
|
_response
|
|
387
396
|
)
|
|
388
|
-
|
|
397
|
+
when 415
|
|
389
398
|
raise MessagingException.new(
|
|
390
399
|
'415 The content-type of the request is incorrect',
|
|
391
400
|
_response
|
|
392
401
|
)
|
|
393
|
-
|
|
402
|
+
when 429
|
|
394
403
|
raise MessagingException.new(
|
|
395
404
|
'429 The rate limit has been reached',
|
|
396
405
|
_response
|
|
@@ -405,7 +414,8 @@ module Messaging
|
|
|
405
414
|
)
|
|
406
415
|
end
|
|
407
416
|
|
|
408
|
-
#
|
|
417
|
+
# Endpoint for sending text messages and picture messages using V2
|
|
418
|
+
# messaging.
|
|
409
419
|
# @param [String] account_id Required parameter: User's account ID
|
|
410
420
|
# @param [MessageRequest] body Required parameter: Example:
|
|
411
421
|
# @return [BandwidthMessage] response from the API call
|
|
@@ -436,32 +446,33 @@ module Messaging
|
|
|
436
446
|
_response = execute_request(_request)
|
|
437
447
|
|
|
438
448
|
# Validate response against endpoint and global error codes.
|
|
439
|
-
|
|
449
|
+
case _response.status_code
|
|
450
|
+
when 400
|
|
440
451
|
raise MessagingException.new(
|
|
441
452
|
'400 Request is malformed or invalid',
|
|
442
453
|
_response
|
|
443
454
|
)
|
|
444
|
-
|
|
455
|
+
when 401
|
|
445
456
|
raise MessagingException.new(
|
|
446
457
|
'401 The specified user does not have access to the account',
|
|
447
458
|
_response
|
|
448
459
|
)
|
|
449
|
-
|
|
460
|
+
when 403
|
|
450
461
|
raise MessagingException.new(
|
|
451
462
|
'403 The user does not have access to this API',
|
|
452
463
|
_response
|
|
453
464
|
)
|
|
454
|
-
|
|
465
|
+
when 404
|
|
455
466
|
raise MessagingException.new(
|
|
456
467
|
'404 Path not found',
|
|
457
468
|
_response
|
|
458
469
|
)
|
|
459
|
-
|
|
470
|
+
when 415
|
|
460
471
|
raise MessagingException.new(
|
|
461
472
|
'415 The content-type of the request is incorrect',
|
|
462
473
|
_response
|
|
463
474
|
)
|
|
464
|
-
|
|
475
|
+
when 429
|
|
465
476
|
raise MessagingException.new(
|
|
466
477
|
'429 The rate limit has been reached',
|
|
467
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.
|