bandwidth-sdk 3.12.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/lib/bandwidth/http/api_response.rb +2 -0
  4. data/lib/bandwidth/http/faraday_client.rb +9 -2
  5. data/lib/bandwidth/messaging_lib/messaging.rb +3 -0
  6. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +138 -23
  7. data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +1 -1
  8. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +12 -11
  9. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +125 -0
  10. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_messages_list.rb +60 -0
  11. data/lib/bandwidth/messaging_lib/messaging/models/media.rb +4 -4
  12. data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +8 -6
  13. data/lib/bandwidth/messaging_lib/messaging/models/page_info.rb +62 -0
  14. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb +3 -3
  15. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/base_controller.rb +1 -1
  16. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_request_schema.rb +0 -19
  17. data/lib/bandwidth/voice_lib/bxml/verbs/sip_uri.rb +25 -0
  18. data/lib/bandwidth/voice_lib/bxml/verbs/tag.rb +13 -0
  19. data/lib/bandwidth/voice_lib/bxml/verbs/transfer.rb +9 -2
  20. data/lib/bandwidth/voice_lib/voice.rb +1 -1
  21. data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +51 -52
  22. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +1 -1
  23. data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +77 -17
  24. data/lib/bandwidth/voice_lib/voice/models/{call_engine_modify_conference_request.rb → api_modify_conference_request.rb} +14 -14
  25. data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +3 -3
  26. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +24 -24
  27. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/base_controller.rb +1 -1
  28. data/test/controllers/controller_test_base.rb +21 -0
  29. data/test/http_response_catcher.rb +19 -0
  30. data/test/test_helper.rb +94 -0
  31. metadata +47 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 957c708a64fbff873ec8eabc221cd4832deaf4d68ac4d29c1200104ddf1a9320
4
- data.tar.gz: dff8ddef5916e696798d712f257be3f9ef471ec2fadc42567ffa248b119e9e3d
3
+ metadata.gz: bc4d4b047d53e1e8c3f34b37696455d916a753aa3566dad6d6fb666fc2b3fa61
4
+ data.tar.gz: b5cdf37c09788e890f36ef3c78ccf41f0ba18a69291f1424be7f798f207881f9
5
5
  SHA512:
6
- metadata.gz: ef6d3e69a46cf27463b1bc72cea88a0a2e4dd78558758ca6c72eceedd99c48c5c304e08914cecd8e3f5919bb617d501930dc81d8fc28aeba47148ecf0a214f7f
7
- data.tar.gz: 487a7c3d36817d419e482ac89d98927803789b03b3be3148eeeb246f7fbfdae1da74bf500918b4eac1f8a7c7cce890290be1da843ca632c9ee26719d232e6b12
6
+ metadata.gz: 59761140cdddf9f6cda37d7aeeaeff6341a5c0bcc357cf577ae29e8fff0a6cf347f1070536f99db3b2f3f6baae3c2b93edbefb2e94468036c57ffd7a65c279b0
7
+ data.tar.gz: bdf68653a8640403d2bc5402c9f5af06055079640ab9229b16ac12cf48290ccffbe2ac38e40c11c3e6b518b1ebaad05344779249d0f79c940d32c3a57b36f5ed
data/LICENSE CHANGED
@@ -3,7 +3,7 @@ License:
3
3
  The MIT License (MIT)
4
4
  http://opensource.org/licenses/MIT
5
5
 
6
- Copyright (c) 2014 - 2016 APIMATIC Limited
6
+ Copyright (c) 2014 - 2020 APIMATIC Limited
7
7
 
8
8
  Permission is hereby granted, free of charge, to any person obtaining a copy
9
9
  of this software and associated documentation files (the "Software"), to deal
@@ -25,10 +25,12 @@ module Bandwidth
25
25
  @errors = errors
26
26
  end
27
27
 
28
+ # returns true if status_code is between 200-300
28
29
  def success?
29
30
  status_code >= 200 && status_code < 300
30
31
  end
31
32
 
33
+ # returns true if status_code is between 400-600
32
34
  def error?
33
35
  status_code >= 400 && status_code < 600
34
36
  end
@@ -15,6 +15,7 @@ module Bandwidth
15
15
  @connection = Faraday.new do |faraday|
16
16
  faraday.use Faraday::HttpCache, serializer: Marshal if cache
17
17
  faraday.use FaradayMiddleware::FollowRedirects
18
+ faraday.use :gzip
18
19
  faraday.request :multipart
19
20
  faraday.request :url_encoded
20
21
  faraday.ssl[:ca_file] = Certifi.where
@@ -34,7 +35,10 @@ module Bandwidth
34
35
  http_request.query_url
35
36
  ) do |request|
36
37
  request.headers = http_request.headers
37
- request.body = http_request.parameters
38
+ unless http_request.http_method == HttpMethodEnum::GET &&
39
+ http_request.parameters.empty?
40
+ request.body = http_request.parameters
41
+ end
38
42
  end
39
43
  convert_response(response, http_request)
40
44
  end
@@ -46,7 +50,10 @@ module Bandwidth
46
50
  http_request.query_url
47
51
  ) do |request|
48
52
  request.headers = http_request.headers
49
- request.body = http_request.parameters
53
+ unless http_request.http_method == HttpMethodEnum::GET &&
54
+ http_request.parameters.empty?
55
+ request.body = http_request.parameters
56
+ end
50
57
  end
51
58
  convert_response(response, http_request)
52
59
  end
@@ -7,6 +7,9 @@
7
7
  require_relative 'messaging/client.rb'
8
8
 
9
9
  # Models
10
+ require_relative 'messaging/models/bandwidth_messages_list.rb'
11
+ require_relative 'messaging/models/bandwidth_message_item.rb'
12
+ require_relative 'messaging/models/page_info.rb'
10
13
  require_relative 'messaging/models/media.rb'
11
14
  require_relative 'messaging/models/tag.rb'
12
15
  require_relative 'messaging/models/deferred_result.rb'
@@ -12,8 +12,9 @@ module Messaging
12
12
  end
13
13
 
14
14
  # listMedia
15
- # @param [String] user_id Required parameter: Example:
16
- # @param [String] continuation_token Optional parameter: Example:
15
+ # @param [String] user_id Required parameter: User's account ID
16
+ # @param [String] continuation_token Optional parameter: Continuation token
17
+ # used to retrieve subsequent media.
17
18
  # @return [List of Media] response from the API call
18
19
  def list_media(user_id,
19
20
  continuation_token: nil)
@@ -22,7 +23,7 @@ module Messaging
22
23
  _query_builder << '/users/{userId}/media'
23
24
  _query_builder = APIHelper.append_url_with_template_parameters(
24
25
  _query_builder,
25
- 'userId' => { 'value' => user_id, 'encode' => true }
26
+ 'userId' => { 'value' => user_id, 'encode' => false }
26
27
  )
27
28
  _query_url = APIHelper.clean_url _query_builder
28
29
 
@@ -83,8 +84,8 @@ module Messaging
83
84
  end
84
85
 
85
86
  # getMedia
86
- # @param [String] user_id Required parameter: Example:
87
- # @param [String] media_id Required parameter: Example:
87
+ # @param [String] user_id Required parameter: User's account ID
88
+ # @param [String] media_id Required parameter: Media ID to retrieve
88
89
  # @return [Binary] response from the API call
89
90
  def get_media(user_id,
90
91
  media_id)
@@ -93,8 +94,8 @@ module Messaging
93
94
  _query_builder << '/users/{userId}/media/{mediaId}'
94
95
  _query_builder = APIHelper.append_url_with_template_parameters(
95
96
  _query_builder,
96
- 'userId' => { 'value' => user_id, 'encode' => true },
97
- 'mediaId' => { 'value' => media_id, 'encode' => true }
97
+ 'userId' => { 'value' => user_id, 'encode' => false },
98
+ 'mediaId' => { 'value' => media_id, 'encode' => false }
98
99
  )
99
100
  _query_url = APIHelper.clean_url _query_builder
100
101
 
@@ -146,13 +147,17 @@ module Messaging
146
147
  end
147
148
 
148
149
  # uploadMedia
149
- # @param [String] user_id Required parameter: Example:
150
- # @param [String] media_id Required parameter: Example:
151
- # @param [Long] content_length Required parameter: Example:
150
+ # @param [String] user_id Required parameter: User's account ID
151
+ # @param [String] media_id Required parameter: The user supplied custom
152
+ # media ID
153
+ # @param [Long] content_length Required parameter: The size of the
154
+ # entity-body
152
155
  # @param [File | UploadIO] body Required parameter: Example:
153
- # @param [String] content_type Optional parameter:
154
- # Example:application/octet-stream
155
- # @param [String] cache_control Optional parameter: Example:
156
+ # @param [String] content_type Optional parameter: The media type of the
157
+ # entity-body
158
+ # @param [String] cache_control Optional parameter: General-header field is
159
+ # used to specify directives that MUST be obeyed by all caching mechanisms
160
+ # along the request/response chain.
156
161
  # @return [void] response from the API call
157
162
  def upload_media(user_id,
158
163
  media_id,
@@ -165,8 +170,8 @@ module Messaging
165
170
  _query_builder << '/users/{userId}/media/{mediaId}'
166
171
  _query_builder = APIHelper.append_url_with_template_parameters(
167
172
  _query_builder,
168
- 'userId' => { 'value' => user_id, 'encode' => true },
169
- 'mediaId' => { 'value' => media_id, 'encode' => true }
173
+ 'userId' => { 'value' => user_id, 'encode' => false },
174
+ 'mediaId' => { 'value' => media_id, 'encode' => false }
170
175
  )
171
176
  _query_url = APIHelper.clean_url _query_builder
172
177
 
@@ -234,8 +239,8 @@ module Messaging
234
239
  end
235
240
 
236
241
  # deleteMedia
237
- # @param [String] user_id Required parameter: Example:
238
- # @param [String] media_id Required parameter: Example:
242
+ # @param [String] user_id Required parameter: User's account ID
243
+ # @param [String] media_id Required parameter: The media ID to delete
239
244
  # @return [void] response from the API call
240
245
  def delete_media(user_id,
241
246
  media_id)
@@ -244,8 +249,8 @@ module Messaging
244
249
  _query_builder << '/users/{userId}/media/{mediaId}'
245
250
  _query_builder = APIHelper.append_url_with_template_parameters(
246
251
  _query_builder,
247
- 'userId' => { 'value' => user_id, 'encode' => true },
248
- 'mediaId' => { 'value' => media_id, 'encode' => true }
252
+ 'userId' => { 'value' => user_id, 'encode' => false },
253
+ 'mediaId' => { 'value' => media_id, 'encode' => false }
249
254
  )
250
255
  _query_url = APIHelper.clean_url _query_builder
251
256
 
@@ -294,18 +299,128 @@ module Messaging
294
299
  ApiResponse.new(_response)
295
300
  end
296
301
 
302
+ # getMessages
303
+ # @param [String] user_id Required parameter: User's account ID
304
+ # @param [String] message_id Optional parameter: The ID of the message to
305
+ # search for. Special characters need to be encoded using URL encoding
306
+ # @param [String] source_tn Optional parameter: The phone number that sent
307
+ # the message
308
+ # @param [String] destination_tn Optional parameter: The phone number that
309
+ # received the message
310
+ # @param [String] message_status Optional parameter: The status of the
311
+ # message. One of RECEIVED, QUEUED, SENDING, SENT, FAILED, DELIVERED,
312
+ # DLR_EXPIRED
313
+ # @param [Integer] error_code Optional parameter: The error code of the
314
+ # message
315
+ # @param [String] from_date_time Optional parameter: The start of the date
316
+ # range to search in ISO 8601 format. Uses the message receive time. The
317
+ # date range to search in is currently 14 days.
318
+ # @param [String] to_date_time Optional parameter: The end of the date range
319
+ # to search in ISO 8601 format. Uses the message receive time. The date
320
+ # range to search in is currently 14 days.
321
+ # @param [String] page_token Optional parameter: A base64 encoded value used
322
+ # for pagination of results
323
+ # @param [Integer] limit Optional parameter: The maximum records requested
324
+ # in search result. Default 100. The sum of limit and after cannot be more
325
+ # than 10000
326
+ # @return [BandwidthMessagesList] response from the API call
327
+ def get_messages(user_id,
328
+ message_id: nil,
329
+ source_tn: nil,
330
+ destination_tn: nil,
331
+ message_status: nil,
332
+ error_code: nil,
333
+ from_date_time: nil,
334
+ to_date_time: nil,
335
+ page_token: nil,
336
+ limit: nil)
337
+ # Prepare query url.
338
+ _query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
339
+ _query_builder << '/users/{userId}/messages'
340
+ _query_builder = APIHelper.append_url_with_template_parameters(
341
+ _query_builder,
342
+ 'userId' => { 'value' => user_id, 'encode' => false }
343
+ )
344
+ _query_builder = APIHelper.append_url_with_query_parameters(
345
+ _query_builder,
346
+ 'messageId' => message_id,
347
+ 'sourceTn' => source_tn,
348
+ 'destinationTn' => destination_tn,
349
+ 'messageStatus' => message_status,
350
+ 'errorCode' => error_code,
351
+ 'fromDateTime' => from_date_time,
352
+ 'toDateTime' => to_date_time,
353
+ 'pageToken' => page_token,
354
+ 'limit' => limit
355
+ )
356
+ _query_url = APIHelper.clean_url _query_builder
357
+
358
+ # Prepare headers.
359
+ _headers = {
360
+ 'accept' => 'application/json'
361
+ }
362
+
363
+ # Prepare and execute HttpRequest.
364
+ _request = config.http_client.get(
365
+ _query_url,
366
+ headers: _headers
367
+ )
368
+ MessagingBasicAuth.apply(config, _request)
369
+ _response = execute_request(_request)
370
+
371
+ # Validate response against endpoint and global error codes.
372
+ if _response.status_code == 400
373
+ raise MessagingException.new(
374
+ '400 Request is malformed or invalid',
375
+ _response
376
+ )
377
+ elsif _response.status_code == 401
378
+ raise MessagingException.new(
379
+ '401 The specified user does not have access to the account',
380
+ _response
381
+ )
382
+ elsif _response.status_code == 403
383
+ raise MessagingException.new(
384
+ '403 The user does not have access to this API',
385
+ _response
386
+ )
387
+ elsif _response.status_code == 404
388
+ raise MessagingException.new(
389
+ '404 Path not found',
390
+ _response
391
+ )
392
+ elsif _response.status_code == 415
393
+ raise MessagingException.new(
394
+ '415 The content-type of the request is incorrect',
395
+ _response
396
+ )
397
+ elsif _response.status_code == 429
398
+ raise MessagingException.new(
399
+ '429 The rate limit has been reached',
400
+ _response
401
+ )
402
+ end
403
+ validate_response(_response)
404
+
405
+ # Return appropriate response type.
406
+ decoded = APIHelper.json_deserialize(_response.raw_body)
407
+ ApiResponse.new(
408
+ _response, data: BandwidthMessagesList.from_hash(decoded)
409
+ )
410
+ end
411
+
297
412
  # createMessage
298
- # @param [String] user_id Required parameter: Example:
299
- # @param [MessageRequest] body Optional parameter: Example:
413
+ # @param [String] user_id Required parameter: User's account ID
414
+ # @param [MessageRequest] body Required parameter: Example:
300
415
  # @return [BandwidthMessage] response from the API call
301
416
  def create_message(user_id,
302
- body: nil)
417
+ body)
303
418
  # Prepare query url.
304
419
  _query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
305
420
  _query_builder << '/users/{userId}/messages'
306
421
  _query_builder = APIHelper.append_url_with_template_parameters(
307
422
  _query_builder,
308
- 'userId' => { 'value' => user_id, 'encode' => true }
423
+ 'userId' => { 'value' => user_id, 'encode' => false }
309
424
  )
310
425
  _query_url = APIHelper.clean_url _query_builder
311
426
 
@@ -13,7 +13,7 @@ module Bandwidth
13
13
  @http_call_back = http_call_back
14
14
 
15
15
  @global_headers = {
16
- 'user-agent' => 'ruby-sdk-refs/tags/ruby3.12.1'
16
+ 'user-agent' => 'ruby-sdk'
17
17
  }
18
18
  end
19
19
 
@@ -6,47 +6,48 @@
6
6
  module Bandwidth
7
7
  # BandwidthMessage Model.
8
8
  class BandwidthMessage < BaseModel
9
- # TODO: Write general description for this method
9
+ # The id of the message
10
10
  # @return [String]
11
11
  attr_accessor :id
12
12
 
13
- # TODO: Write general description for this method
13
+ # The Bandwidth phone number associated with the message
14
14
  # @return [String]
15
15
  attr_accessor :owner
16
16
 
17
- # TODO: Write general description for this method
17
+ # The application ID associated with the message
18
18
  # @return [String]
19
19
  attr_accessor :application_id
20
20
 
21
- # TODO: Write general description for this method
21
+ # The datetime stamp of the message in ISO 8601
22
22
  # @return [String]
23
23
  attr_accessor :time
24
24
 
25
- # TODO: Write general description for this method
25
+ # The number of segments the original message from the user is broken into
26
+ # before sending over to carrier networks
26
27
  # @return [Integer]
27
28
  attr_accessor :segment_count
28
29
 
29
- # TODO: Write general description for this method
30
+ # The direction of the message relative to Bandwidth. Can be in or out
30
31
  # @return [String]
31
32
  attr_accessor :direction
32
33
 
33
- # TODO: Write general description for this method
34
+ # The phone number recipients of the message
34
35
  # @return [List of String]
35
36
  attr_accessor :to
36
37
 
37
- # TODO: Write general description for this method
38
+ # The phone number the message was sent from
38
39
  # @return [String]
39
40
  attr_accessor :from
40
41
 
41
- # TODO: Write general description for this method
42
+ # The list of media URLs sent in the message
42
43
  # @return [List of String]
43
44
  attr_accessor :media
44
45
 
45
- # TODO: Write general description for this method
46
+ # The contents of the message
46
47
  # @return [String]
47
48
  attr_accessor :text
48
49
 
49
- # TODO: Write general description for this method
50
+ # The custom string set by the user
50
51
  # @return [String]
51
52
  attr_accessor :tag
52
53
 
@@ -0,0 +1,125 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Bandwidth
7
+ # BandwidthMessageItem Model.
8
+ class BandwidthMessageItem < BaseModel
9
+ # The message id
10
+ # @return [String]
11
+ attr_accessor :message_id
12
+
13
+ # The account id of the message
14
+ # @return [String]
15
+ attr_accessor :account_id
16
+
17
+ # The source phone number of the message
18
+ # @return [String]
19
+ attr_accessor :source_tn
20
+
21
+ # The recipient phone number of the message
22
+ # @return [String]
23
+ attr_accessor :destination_tn
24
+
25
+ # The status of the message
26
+ # @return [String]
27
+ attr_accessor :message_status
28
+
29
+ # The direction of the message relative to Bandwidth. INBOUND or OUTBOUND
30
+ # @return [String]
31
+ attr_accessor :message_direction
32
+
33
+ # The type of message. sms or mms
34
+ # @return [String]
35
+ attr_accessor :message_type
36
+
37
+ # The number of segments the message was sent as
38
+ # @return [Integer]
39
+ attr_accessor :segment_count
40
+
41
+ # The numeric error code of the message
42
+ # @return [Integer]
43
+ attr_accessor :error_code
44
+
45
+ # The ISO 8601 datetime of the message
46
+ # @return [String]
47
+ attr_accessor :receive_time
48
+
49
+ # The name of the carrier. Not currently supported for MMS, coming soon
50
+ # @return [String]
51
+ attr_accessor :carrier_name
52
+
53
+ # A mapping from model property names to API property names.
54
+ def self.names
55
+ @_hash = {} if @_hash.nil?
56
+ @_hash['message_id'] = 'messageId'
57
+ @_hash['account_id'] = 'accountId'
58
+ @_hash['source_tn'] = 'sourceTn'
59
+ @_hash['destination_tn'] = 'destinationTn'
60
+ @_hash['message_status'] = 'messageStatus'
61
+ @_hash['message_direction'] = 'messageDirection'
62
+ @_hash['message_type'] = 'messageType'
63
+ @_hash['segment_count'] = 'segmentCount'
64
+ @_hash['error_code'] = 'errorCode'
65
+ @_hash['receive_time'] = 'receiveTime'
66
+ @_hash['carrier_name'] = 'carrierName'
67
+ @_hash
68
+ end
69
+
70
+ def initialize(message_id = nil,
71
+ account_id = nil,
72
+ source_tn = nil,
73
+ destination_tn = nil,
74
+ message_status = nil,
75
+ message_direction = nil,
76
+ message_type = nil,
77
+ segment_count = nil,
78
+ error_code = nil,
79
+ receive_time = nil,
80
+ carrier_name = nil)
81
+ @message_id = message_id
82
+ @account_id = account_id
83
+ @source_tn = source_tn
84
+ @destination_tn = destination_tn
85
+ @message_status = message_status
86
+ @message_direction = message_direction
87
+ @message_type = message_type
88
+ @segment_count = segment_count
89
+ @error_code = error_code
90
+ @receive_time = receive_time
91
+ @carrier_name = carrier_name
92
+ end
93
+
94
+ # Creates an instance of the object from a hash.
95
+ def self.from_hash(hash)
96
+ return nil unless hash
97
+
98
+ # Extract variables from the hash.
99
+ message_id = hash['messageId']
100
+ account_id = hash['accountId']
101
+ source_tn = hash['sourceTn']
102
+ destination_tn = hash['destinationTn']
103
+ message_status = hash['messageStatus']
104
+ message_direction = hash['messageDirection']
105
+ message_type = hash['messageType']
106
+ segment_count = hash['segmentCount']
107
+ error_code = hash['errorCode']
108
+ receive_time = hash['receiveTime']
109
+ carrier_name = hash['carrierName']
110
+
111
+ # Create object from extracted values.
112
+ BandwidthMessageItem.new(message_id,
113
+ account_id,
114
+ source_tn,
115
+ destination_tn,
116
+ message_status,
117
+ message_direction,
118
+ message_type,
119
+ segment_count,
120
+ error_code,
121
+ receive_time,
122
+ carrier_name)
123
+ end
124
+ end
125
+ end