bandwidth-sdk 3.13.1 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +1 -1
  4. data/lib/bandwidth/configuration.rb +1 -1
  5. data/lib/bandwidth/http/api_response.rb +2 -0
  6. data/lib/bandwidth/http/faraday_client.rb +9 -2
  7. data/lib/bandwidth/messaging_lib/messaging.rb +4 -0
  8. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +138 -23
  9. data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +1 -1
  10. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +23 -13
  11. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +125 -0
  12. data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_messages_list.rb +60 -0
  13. data/lib/bandwidth/messaging_lib/messaging/models/media.rb +4 -4
  14. data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +21 -8
  15. data/lib/bandwidth/messaging_lib/messaging/models/page_info.rb +62 -0
  16. data/lib/bandwidth/messaging_lib/messaging/models/priority_enum.rb +19 -0
  17. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb +4 -2
  18. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/client.rb +4 -4
  19. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/base_controller.rb +1 -1
  20. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/{api_controller.rb → mfa_controller.rb} +65 -14
  21. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/error_with_request_exception.rb +34 -0
  22. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/{invalid_request_exception.rb → forbidden_request_exception.rb} +5 -5
  23. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/unauthorized_request_exception.rb +29 -0
  24. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_request_schema.rb +0 -19
  25. data/lib/bandwidth/voice_lib/voice.rb +1 -1
  26. data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +51 -52
  27. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +1 -1
  28. data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +77 -17
  29. data/lib/bandwidth/voice_lib/voice/models/{call_engine_modify_conference_request.rb → api_modify_conference_request.rb} +14 -14
  30. data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +3 -3
  31. data/lib/bandwidth/web_rtc_lib/web_rtc.rb +1 -0
  32. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +24 -24
  33. data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/base_controller.rb +1 -1
  34. data/lib/bandwidth/web_rtc_lib/web_rtc/models/device_api_version_enum.rb +17 -0
  35. data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant.rb +11 -2
  36. data/test/integration/test_integration.rb +570 -0
  37. metadata +49 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a79b2f744a1044c7312833760914829637f9c7d21aa8b670102d83b2e810f8b
4
- data.tar.gz: e12d0c3e1d70547f90a1bdbad47e76425823b85bc8d5f838ca15e2e9d3dfe1d8
3
+ metadata.gz: 26c4cadeb77f88938cc4adac87254af331797646e475f2985dbe93078c128058
4
+ data.tar.gz: 26e318c93cff54b0d8d47f36dabd4bfcfa66ec33ecd2eaa8a3d6013216f5a635
5
5
  SHA512:
6
- metadata.gz: 71871be37311133b4c09b4b157d800cf94e622399907625fab8dc6ebff41aaed8b6c1dc8f931c819d2e9172e8998842fa3cbbd5d48982685bac0b72f64205b62
7
- data.tar.gz: 6236ac41293f9e5f5453b9db12e50ff1c07eb632d61af71d8929b568f36c13ddd1205cd775fe717cc2668b8ff16dae76f91a2295bdf78fe06c1567b58c03266e
6
+ metadata.gz: 05ed430d18e6bdfffa1400a86d2a92d841d3340aa9bf838a9647c534354585992bd273978008a5161b51bd6b2616d06cf4fbb4ae638f5631d2999459817d6cf4
7
+ data.tar.gz: 5595927b80c12008edb1d1527ac407ca97f431a1dff0acc6984ec2dcfcb9b1e11573af76a4ec40b894ff8b17033f0e226f742ea0505a353d370ad0407f36ff8e
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
data/README.md CHANGED
@@ -72,7 +72,7 @@ body.from = '+18888888888'
72
72
  body.text = 'Hello from Bandwidth'
73
73
 
74
74
  begin
75
- response = messaging_client.create_message(account_id, :body => body)
75
+ response = messaging_client.create_message(account_id, body)
76
76
  puts response.data.id #1570740275373xbn7mbhsfewasdr
77
77
  puts response.status_code #202
78
78
  rescue Bandwidth::GenericClientException => e
@@ -156,7 +156,7 @@ module Bandwidth
156
156
  Environment::PRODUCTION => {
157
157
  Server::DEFAULT => 'api.bandwidth.com',
158
158
  Server::MESSAGINGDEFAULT => 'https://messaging.bandwidth.com/api/v2',
159
- Server::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1/',
159
+ Server::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1',
160
160
  Server::VOICEDEFAULT => 'https://voice.bandwidth.com',
161
161
  Server::WEBRTCDEFAULT => 'https://api.webrtc.bandwidth.com/v1'
162
162
  },
@@ -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,12 +7,16 @@
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'
13
16
  require_relative 'messaging/models/bandwidth_callback_message.rb'
14
17
  require_relative 'messaging/models/bandwidth_message.rb'
15
18
  require_relative 'messaging/models/message_request.rb'
19
+ require_relative 'messaging/models/priority_enum.rb'
16
20
 
17
21
  # Exceptions
18
22
  require_relative 'messaging/exceptions/messaging_exception.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,50 +6,55 @@
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
 
54
+ # The priority specified by the user
55
+ # @return [String]
56
+ attr_accessor :priority
57
+
53
58
  # A mapping from model property names to API property names.
54
59
  def self.names
55
60
  @_hash = {} if @_hash.nil?
@@ -64,6 +69,7 @@ module Bandwidth
64
69
  @_hash['media'] = 'media'
65
70
  @_hash['text'] = 'text'
66
71
  @_hash['tag'] = 'tag'
72
+ @_hash['priority'] = 'priority'
67
73
  @_hash
68
74
  end
69
75
 
@@ -77,7 +83,8 @@ module Bandwidth
77
83
  from = nil,
78
84
  media = nil,
79
85
  text = nil,
80
- tag = nil)
86
+ tag = nil,
87
+ priority = nil)
81
88
  @id = id
82
89
  @owner = owner
83
90
  @application_id = application_id
@@ -89,6 +96,7 @@ module Bandwidth
89
96
  @media = media
90
97
  @text = text
91
98
  @tag = tag
99
+ @priority = priority
92
100
  end
93
101
 
94
102
  # Creates an instance of the object from a hash.
@@ -107,6 +115,7 @@ module Bandwidth
107
115
  media = hash['media']
108
116
  text = hash['text']
109
117
  tag = hash['tag']
118
+ priority = hash['priority']
110
119
 
111
120
  # Create object from extracted values.
112
121
  BandwidthMessage.new(id,
@@ -119,7 +128,8 @@ module Bandwidth
119
128
  from,
120
129
  media,
121
130
  text,
122
- tag)
131
+ tag,
132
+ priority)
123
133
  end
124
134
  end
125
135
  end