bandwidth-sdk 2.2.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +85 -70
  3. data/lib/bandwidth.rb +5 -1
  4. data/lib/bandwidth/client.rb +9 -0
  5. data/lib/bandwidth/configuration.rb +22 -4
  6. data/lib/bandwidth/http/auth/two_factor_auth_basic_auth.rb +22 -0
  7. data/lib/bandwidth/http/faraday_client.rb +2 -6
  8. data/lib/bandwidth/messaging_lib/messaging.rb +1 -3
  9. data/lib/bandwidth/messaging_lib/messaging/client.rb +4 -0
  10. data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +45 -88
  11. data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +1 -1
  12. data/lib/bandwidth/messaging_lib/messaging/exceptions/{generic_client_exception.rb → messaging_exception.rb} +2 -14
  13. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb +19 -0
  14. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/client.rb +44 -0
  15. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb +129 -0
  16. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/base_controller.rb +49 -0
  17. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_code_request_schema.rb +62 -0
  18. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_messaging_response.rb +35 -0
  19. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_code_response.rb +35 -0
  20. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_request_schema.rb +71 -0
  21. data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_voice_response.rb +35 -0
  22. data/lib/bandwidth/utilities/file_wrapper.rb +17 -0
  23. data/lib/bandwidth/voice_lib/bxml/verbs/phone_number.rb +2 -0
  24. data/lib/bandwidth/voice_lib/bxml/verbs/record.rb +2 -1
  25. data/lib/bandwidth/voice_lib/bxml/verbs/send_dtmf.rb +4 -1
  26. data/lib/bandwidth/voice_lib/voice/client.rb +4 -0
  27. data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +1 -1
  28. metadata +30 -7
  29. data/lib/bandwidth/messaging_lib/messaging/exceptions/path_client_exception.rb +0 -49
  30. data/lib/bandwidth/messaging_lib/messaging/models/field_error.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37ac6cedf8f46960bdc51af5b2c1cb7084f303ba4b757373538186ca932997ba
4
- data.tar.gz: 1bac73b1c867feec6a21b3b985bbe15b3a163c3319538313453928e39a66806a
3
+ metadata.gz: d0a28919bebd82a316cecaedd2e6abdea2c60bd092021e6a8128577d3f6e2c07
4
+ data.tar.gz: 1ecfc47dbe9ee1ea5a50654a86c25ed712fe685e65ee7dc9401818a4b2fea530
5
5
  SHA512:
6
- metadata.gz: 7883069c08c868dcddd095be404121878adacd67dce7adbab68cc3e2af858d7534f2bd16410b64786a496372f0d1f81b6ffe456ea0b4c6434b4594cb997b0fb3
7
- data.tar.gz: f32337f52e22bad320f06fa789cfcd8618a4973fea80155ac626cef225c9c063cc2d27c7927354e14ed4f50b6185d139c303b0690d325f6d8dcb4c9514fbb484
6
+ metadata.gz: 4d77b5a15e04975c3815cc9b39adaaf5828a3ebb71064a57e5dcea8209f36516ec7ff5cce85c987586aa52eb0f25410ba8f864336023d8a52c877c059b26115e
7
+ data.tar.gz: b3f26d82dbcf9b7f16551e972d18a11c66759a745547978ca4165c19a23dfb36edf6d2d85f7905db33dc576cf536d8221cffa398382bc447fd0b51c08c29ef21
data/README.md CHANGED
@@ -1,70 +1,85 @@
1
- # Getting Started with bandwidth
2
-
3
- Bandwidth's set of APIs
4
-
5
- ## Install the Package
6
-
7
- Install the gem from the command line:
8
-
9
- ```ruby
10
- gem install bandwidth-sdk -v 2.2.0
11
- ```
12
-
13
- Or add the gem to your Gemfile and run `bundle`:
14
-
15
- ```ruby
16
- gem 'bandwidth-sdk', '2.2.0'
17
- ```
18
-
19
- For additional gem details, see the [RubyGems page for the bandwidth-sdk gem](https://rubygems.org/gems/bandwidth-sdk/versions/2.2.0).
20
-
21
- ## Initialize the API Client
22
-
23
- The following parameters are configurable for the API Client.
24
-
25
- | Parameter | Type | Description |
26
- | --- | --- | --- |
27
- | `messaging_basic_auth_user_name` | `String` | The username to use with basic authentication |
28
- | `messaging_basic_auth_password` | `String` | The password to use with basic authentication |
29
- | `voice_basic_auth_user_name` | `String` | The username to use with basic authentication |
30
- | `voice_basic_auth_password` | `String` | The password to use with basic authentication |
31
- | `environment` | Environment | The API environment. <br> **Default: `Environment.PRODUCTION`** |
32
- | `timeout` | `Float` | The value to use for connection timeout. <br> **Default: 60** |
33
- | `max_retries` | `Integer` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
34
- | `retry_interval` | `Float` | Pause in seconds between retries. <br> **Default: 1** |
35
- | `backoff_factor` | `Float` | The amount to multiply each successive retry's interval amount by in order to provide backoff. <br> **Default: 1** |
36
-
37
- The API client can be initialized as following.
38
-
39
- ```ruby
40
- client = Bandwidth::Client.new(
41
- messaging_basic_auth_user_name: 'MessagingBasicAuthUserName',
42
- messaging_basic_auth_password: 'MessagingBasicAuthPassword',
43
- voice_basic_auth_user_name: 'VoiceBasicAuthUserName',
44
- voice_basic_auth_password: 'VoiceBasicAuthPassword',
45
- environment: Environment::PRODUCTION,
46
- )
47
- ```
48
-
49
- API calls return an `ApiResponse` object that includes the following fields:
50
-
51
- | Field | Description |
52
- | --- | --- |
53
- | `status_code` | Status code of the HTTP response |
54
- | `reason_phrase` | Reason phrase of the HTTP response |
55
- | `headers` | Headers of the HTTP response as a Hash |
56
- | `raw_body` | The body of the HTTP response as a String |
57
- | `request` | HTTP request info |
58
- | `errors` | Errors, if they exist |
59
- | `data` | The deserialized body of the HTTP response |
60
-
61
- ## Authorization
62
-
63
- This API does not require authentication.
64
-
65
- ## API Reference
66
-
67
- ### List of APIs
68
-
69
- *
70
-
1
+ # Bandwidth Ruby SDK
2
+
3
+ Bandwidth's API docs can be found at https://dev.bandwidth.com
4
+
5
+ Ruby specific docs can be found at https://dev.bandwidth.com/sdks/ruby.html
6
+
7
+ ## Download & Install
8
+
9
+ ```
10
+ gem install bandwidth-sdk
11
+ ```
12
+
13
+ ## Initialize Bandwidth Client
14
+
15
+ ```ruby
16
+ require 'bandwidth'
17
+
18
+ include Bandwidth
19
+ include Bandwidth::Voice
20
+ include Bandwidth::Messaging
21
+
22
+ bandwidth_client = Bandwidth::Client.new(
23
+ voice_basic_auth_user_name: 'username',
24
+ voice_basic_auth_password: 'password',
25
+ messaging_basic_auth_user_name: 'token',
26
+ messaging_basic_auth_password: 'secret',
27
+ )
28
+ ```
29
+
30
+ ## Create Phone Call
31
+
32
+ ```ruby
33
+ voice_client = bandwidth_client.voice_client.client
34
+
35
+ account_id = '1'
36
+ body = ApiCreateCallRequest.new
37
+ body.from = '+16666666666'
38
+ body.to = '+17777777777'
39
+ body.answer_url = 'https://test.com'
40
+ body.application_id = '3-d-4-b-5'
41
+
42
+ begin
43
+ response = voice_client.create_call(account_id,:body => body)
44
+ puts response.data.call_id #c-d45a41e5-bcb12581-b18e-4bdc-9874-6r3235dfweao
45
+ puts response.status_code #201
46
+ rescue Bandwidth::ErrorResponseException => e
47
+ puts e.description #Invalid to: must be an E164 telephone number
48
+ puts e.response_code #400
49
+ end
50
+ ```
51
+
52
+ ## Generate BXML
53
+
54
+ ```ruby
55
+ response = Bandwidth::Voice::Response.new()
56
+ hangup = Bandwidth::Voice::Hangup.new()
57
+
58
+ response.push(hangup)
59
+ puts response.to_bxml()
60
+ ```
61
+
62
+ ## Send Text Message
63
+
64
+ ```ruby
65
+ messaging_client = bandwidth_client.messaging_client.client
66
+
67
+ account_id = '1'
68
+ body = MessageRequest.new
69
+ body.application_id = '1-2-3'
70
+ body.to = ['+17777777777']
71
+ body.from = '+18888888888'
72
+ body.text = 'Hello from Bandwidth'
73
+
74
+ begin
75
+ response = messaging_client.create_message(account_id, :body => body)
76
+ puts response.data.id #1570740275373xbn7mbhsfewasdr
77
+ puts response.status_code #202
78
+ rescue Bandwidth::GenericClientException => e
79
+ puts e.description #Access is denied
80
+ puts e.response_code #403
81
+ rescue Bandwidth::PathClientException => e
82
+ puts e.message #Your request could not be accepted.
83
+ puts e.response_code #400
84
+ end
85
+ ```
@@ -12,6 +12,9 @@ require 'logging'
12
12
  require_relative 'bandwidth/api_helper.rb'
13
13
  require_relative 'bandwidth/client.rb'
14
14
 
15
+ # Utilities
16
+ require_relative 'bandwidth/utilities/file_wrapper.rb'
17
+
15
18
  # Http
16
19
  require_relative 'bandwidth/http/api_response.rb'
17
20
  require_relative 'bandwidth/http/http_call_back.rb'
@@ -32,8 +35,9 @@ require_relative 'bandwidth/configuration.rb'
32
35
  # Namespaces
33
36
  require_relative 'bandwidth/messaging_lib/messaging'
34
37
  require_relative 'bandwidth/http/auth/messaging_basic_auth.rb'
38
+ require_relative 'bandwidth/two_factor_auth_lib/two_factor_auth'
39
+ require_relative 'bandwidth/http/auth/two_factor_auth_basic_auth.rb'
35
40
  require_relative 'bandwidth/voice_lib/voice'
36
41
  require_relative 'bandwidth/http/auth/voice_basic_auth.rb'
37
42
 
38
-
39
43
  # Controllers
@@ -12,6 +12,11 @@ module Bandwidth
12
12
  def messaging_client
13
13
  @messaging_client ||= Messaging::Client.new(config: config)
14
14
  end
15
+ # Access to two_factor_auth_client controller.
16
+ # @return [TwoFactorAuth::Client] Returns the client instance.
17
+ def two_factor_auth_client
18
+ @two_factor_auth_client ||= TwoFactorAuth::Client.new(config: config)
19
+ end
15
20
  # Access to voice_client controller.
16
21
  # @return [Voice::Client] Returns the client instance.
17
22
  def voice_client
@@ -22,6 +27,8 @@ module Bandwidth
22
27
  backoff_factor: 1, environment: Environment::PRODUCTION,
23
28
  messaging_basic_auth_user_name: 'TODO: Replace',
24
29
  messaging_basic_auth_password: 'TODO: Replace',
30
+ two_factor_auth_basic_auth_user_name: 'TODO: Replace',
31
+ two_factor_auth_basic_auth_password: 'TODO: Replace',
25
32
  voice_basic_auth_user_name: 'TODO: Replace',
26
33
  voice_basic_auth_password: 'TODO: Replace', config: nil)
27
34
  @config = if config.nil?
@@ -31,6 +38,8 @@ module Bandwidth
31
38
  environment: environment,
32
39
  messaging_basic_auth_user_name: messaging_basic_auth_user_name,
33
40
  messaging_basic_auth_password: messaging_basic_auth_password,
41
+ two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
42
+ two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
34
43
  voice_basic_auth_user_name: voice_basic_auth_user_name,
35
44
  voice_basic_auth_password: voice_basic_auth_password)
36
45
  else
@@ -16,6 +16,7 @@ module Bandwidth
16
16
  SERVER = [
17
17
  DEFAULT = 'default'.freeze,
18
18
  MESSAGINGDEFAULT = 'MessagingDefault'.freeze,
19
+ TWOFACTORAUTHDEFAULT = 'TwoFactorAuthDefault'.freeze,
19
20
  VOICEDEFAULT = 'VoiceDefault'.freeze
20
21
  ].freeze
21
22
  end
@@ -32,6 +33,8 @@ module Bandwidth
32
33
  attr_reader :environment
33
34
  attr_reader :messaging_basic_auth_user_name
34
35
  attr_reader :messaging_basic_auth_password
36
+ attr_reader :two_factor_auth_basic_auth_user_name
37
+ attr_reader :two_factor_auth_basic_auth_password
35
38
  attr_reader :voice_basic_auth_user_name
36
39
  attr_reader :voice_basic_auth_password
37
40
 
@@ -43,6 +46,8 @@ module Bandwidth
43
46
  backoff_factor: 1, environment: Environment::PRODUCTION,
44
47
  messaging_basic_auth_user_name: 'TODO: Replace',
45
48
  messaging_basic_auth_password: 'TODO: Replace',
49
+ two_factor_auth_basic_auth_user_name: 'TODO: Replace',
50
+ two_factor_auth_basic_auth_password: 'TODO: Replace',
46
51
  voice_basic_auth_user_name: 'TODO: Replace',
47
52
  voice_basic_auth_password: 'TODO: Replace')
48
53
  # The value to use for connection timeout
@@ -59,7 +64,7 @@ module Bandwidth
59
64
  @backoff_factor = backoff_factor
60
65
 
61
66
  # Current API environment
62
- @environment = environment
67
+ @environment = String(environment)
63
68
 
64
69
  # The username to use with basic authentication
65
70
  @messaging_basic_auth_user_name = messaging_basic_auth_user_name
@@ -67,6 +72,12 @@ module Bandwidth
67
72
  # The password to use with basic authentication
68
73
  @messaging_basic_auth_password = messaging_basic_auth_password
69
74
 
75
+ # The username to use with basic authentication
76
+ @two_factor_auth_basic_auth_user_name = two_factor_auth_basic_auth_user_name
77
+
78
+ # The password to use with basic authentication
79
+ @two_factor_auth_basic_auth_password = two_factor_auth_basic_auth_password
80
+
70
81
  # The username to use with basic authentication
71
82
  @voice_basic_auth_user_name = voice_basic_auth_user_name
72
83
 
@@ -81,6 +92,8 @@ module Bandwidth
81
92
  backoff_factor: nil, environment: nil,
82
93
  messaging_basic_auth_user_name: nil,
83
94
  messaging_basic_auth_password: nil,
95
+ two_factor_auth_basic_auth_user_name: nil,
96
+ two_factor_auth_basic_auth_password: nil,
84
97
  voice_basic_auth_user_name: nil,
85
98
  voice_basic_auth_password: nil)
86
99
  timeout ||= self.timeout
@@ -90,6 +103,8 @@ module Bandwidth
90
103
  environment ||= self.environment
91
104
  messaging_basic_auth_user_name ||= self.messaging_basic_auth_user_name
92
105
  messaging_basic_auth_password ||= self.messaging_basic_auth_password
106
+ two_factor_auth_basic_auth_user_name ||= self.two_factor_auth_basic_auth_user_name
107
+ two_factor_auth_basic_auth_password ||= self.two_factor_auth_basic_auth_password
93
108
  voice_basic_auth_user_name ||= self.voice_basic_auth_user_name
94
109
  voice_basic_auth_password ||= self.voice_basic_auth_password
95
110
 
@@ -99,6 +114,8 @@ module Bandwidth
99
114
  environment: environment,
100
115
  messaging_basic_auth_user_name: messaging_basic_auth_user_name,
101
116
  messaging_basic_auth_password: messaging_basic_auth_password,
117
+ two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
118
+ two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
102
119
  voice_basic_auth_user_name: voice_basic_auth_user_name,
103
120
  voice_basic_auth_password: voice_basic_auth_password
104
121
  )
@@ -111,20 +128,21 @@ module Bandwidth
111
128
  end
112
129
 
113
130
  # All the environments the SDK can run in.
114
- @environments = {
131
+ ENVIRONMENTS = {
115
132
  Environment::PRODUCTION => {
116
133
  Server::DEFAULT => 'api.bandwidth.com',
117
134
  Server::MESSAGINGDEFAULT => 'https://messaging.bandwidth.com/api/v2',
135
+ Server::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1/',
118
136
  Server::VOICEDEFAULT => 'https://voice.bandwidth.com'
119
137
  }
120
- }
138
+ }.freeze
121
139
 
122
140
  # Generates the appropriate base URI for the environment and the server.
123
141
  # @param [Configuration::Server] The server enum for which the base URI is
124
142
  # required.
125
143
  # @return [String] The base URI.
126
144
  def get_base_uri(server = Server::DEFAULT)
127
- self.class.environments[environment][server].clone
145
+ ENVIRONMENTS[environment][server].clone
128
146
  end
129
147
  end
130
148
  end
@@ -0,0 +1,22 @@
1
+ # bandwidth
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require 'base64'
7
+
8
+ module Bandwidth
9
+ # Utility class for basic authorization.
10
+ class TwoFactorAuthBasicAuth
11
+ # Add basic authentication to the request.
12
+ # @param [HttpRequest] The HttpRequest object to which authentication will
13
+ # be added.
14
+ def self.apply(config, http_request)
15
+ username = config.two_factor_auth_basic_auth_user_name
16
+ password = config.two_factor_auth_basic_auth_password
17
+ value = Base64.strict_encode64("#{username}:#{password}")
18
+ header_value = "Basic #{value}"
19
+ http_request.headers['Authorization'] = header_value
20
+ end
21
+ end
22
+ end
@@ -34,9 +34,7 @@ module Bandwidth
34
34
  http_request.query_url
35
35
  ) do |request|
36
36
  request.headers = http_request.headers
37
- unless http_request.parameters.empty?
38
- request.body = http_request.parameters
39
- end
37
+ request.body = http_request.parameters
40
38
  end
41
39
  convert_response(response, http_request)
42
40
  end
@@ -48,9 +46,7 @@ module Bandwidth
48
46
  http_request.query_url
49
47
  ) do |request|
50
48
  request.headers = http_request.headers
51
- unless http_request.parameters.empty?
52
- request.body = http_request.parameters
53
- end
49
+ request.body = http_request.parameters
54
50
  end
55
51
  convert_response(response, http_request)
56
52
  end
@@ -7,7 +7,6 @@
7
7
  require_relative 'messaging/client.rb'
8
8
 
9
9
  # Models
10
- require_relative 'messaging/models/field_error.rb'
11
10
  require_relative 'messaging/models/media.rb'
12
11
  require_relative 'messaging/models/tag.rb'
13
12
  require_relative 'messaging/models/deferred_result.rb'
@@ -16,8 +15,7 @@ require_relative 'messaging/models/bandwidth_message.rb'
16
15
  require_relative 'messaging/models/message_request.rb'
17
16
 
18
17
  # Exceptions
19
- require_relative 'messaging/exceptions/generic_client_exception.rb'
20
- require_relative 'messaging/exceptions/path_client_exception.rb'
18
+ require_relative 'messaging/exceptions/messaging_exception.rb'
21
19
  # Controllers
22
20
  require_relative 'messaging/controllers/base_controller.rb'
23
21
  require_relative 'messaging/controllers/api_controller.rb'
@@ -19,6 +19,8 @@ module Bandwidth
19
19
  backoff_factor: 1, environment: Environment::PRODUCTION,
20
20
  messaging_basic_auth_user_name: 'TODO: Replace',
21
21
  messaging_basic_auth_password: 'TODO: Replace',
22
+ two_factor_auth_basic_auth_user_name: 'TODO: Replace',
23
+ two_factor_auth_basic_auth_password: 'TODO: Replace',
22
24
  voice_basic_auth_user_name: 'TODO: Replace',
23
25
  voice_basic_auth_password: 'TODO: Replace', config: nil)
24
26
  @config = if config.nil?
@@ -29,6 +31,8 @@ module Bandwidth
29
31
  environment: environment,
30
32
  messaging_basic_auth_user_name: messaging_basic_auth_user_name,
31
33
  messaging_basic_auth_password: messaging_basic_auth_password,
34
+ two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
35
+ two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
32
36
  voice_basic_auth_user_name: voice_basic_auth_user_name,
33
37
  voice_basic_auth_password: voice_basic_auth_password)
34
38
  else
@@ -11,59 +11,6 @@ module Messaging
11
11
  super(config, http_call_back: http_call_back)
12
12
  end
13
13
 
14
- # getMessage
15
- # @return [void] response from the API call
16
- def get_message
17
- # Prepare query url.
18
- _query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
19
- _query_builder << '/ping'
20
- _query_url = APIHelper.clean_url _query_builder
21
-
22
- # Prepare and execute HttpRequest.
23
- _request = config.http_client.get(
24
- _query_url
25
- )
26
- MessagingBasicAuth.apply(config, _request)
27
- _response = execute_request(_request)
28
-
29
- # Validate response against endpoint and global error codes.
30
- if _response.status_code == 400
31
- raise GenericClientException.new(
32
- '400 Request is malformed or invalid',
33
- _response
34
- )
35
- elsif _response.status_code == 401
36
- raise PathClientException.new(
37
- '401 The specified user does not have access to the account',
38
- _response
39
- )
40
- elsif _response.status_code == 403
41
- raise PathClientException.new(
42
- '403 The user does not have access to this API',
43
- _response
44
- )
45
- elsif _response.status_code == 404
46
- raise PathClientException.new(
47
- '404 Path not found',
48
- _response
49
- )
50
- elsif _response.status_code == 415
51
- raise GenericClientException.new(
52
- '415 The content-type of the request is incorrect',
53
- _response
54
- )
55
- elsif _response.status_code == 429
56
- raise GenericClientException.new(
57
- '429 The rate limit has been reached',
58
- _response
59
- )
60
- end
61
- validate_response(_response)
62
-
63
- # Return appropriate response type.
64
- ApiResponse.new(_response)
65
- end
66
-
67
14
  # listMedia
68
15
  # @param [String] user_id Required parameter: Example:
69
16
  # @param [String] continuation_token Optional parameter: Example:
@@ -95,32 +42,32 @@ module Messaging
95
42
 
96
43
  # Validate response against endpoint and global error codes.
97
44
  if _response.status_code == 400
98
- raise GenericClientException.new(
45
+ raise MessagingException.new(
99
46
  '400 Request is malformed or invalid',
100
47
  _response
101
48
  )
102
49
  elsif _response.status_code == 401
103
- raise PathClientException.new(
50
+ raise MessagingException.new(
104
51
  '401 The specified user does not have access to the account',
105
52
  _response
106
53
  )
107
54
  elsif _response.status_code == 403
108
- raise PathClientException.new(
55
+ raise MessagingException.new(
109
56
  '403 The user does not have access to this API',
110
57
  _response
111
58
  )
112
59
  elsif _response.status_code == 404
113
- raise PathClientException.new(
60
+ raise MessagingException.new(
114
61
  '404 Path not found',
115
62
  _response
116
63
  )
117
64
  elsif _response.status_code == 415
118
- raise GenericClientException.new(
65
+ raise MessagingException.new(
119
66
  '415 The content-type of the request is incorrect',
120
67
  _response
121
68
  )
122
69
  elsif _response.status_code == 429
123
- raise GenericClientException.new(
70
+ raise MessagingException.new(
124
71
  '429 The rate limit has been reached',
125
72
  _response
126
73
  )
@@ -158,32 +105,32 @@ module Messaging
158
105
 
159
106
  # Validate response against endpoint and global error codes.
160
107
  if _response.status_code == 400
161
- raise GenericClientException.new(
108
+ raise MessagingException.new(
162
109
  '400 Request is malformed or invalid',
163
110
  _response
164
111
  )
165
112
  elsif _response.status_code == 401
166
- raise PathClientException.new(
113
+ raise MessagingException.new(
167
114
  '401 The specified user does not have access to the account',
168
115
  _response
169
116
  )
170
117
  elsif _response.status_code == 403
171
- raise PathClientException.new(
118
+ raise MessagingException.new(
172
119
  '403 The user does not have access to this API',
173
120
  _response
174
121
  )
175
122
  elsif _response.status_code == 404
176
- raise PathClientException.new(
123
+ raise MessagingException.new(
177
124
  '404 Path not found',
178
125
  _response
179
126
  )
180
127
  elsif _response.status_code == 415
181
- raise GenericClientException.new(
128
+ raise MessagingException.new(
182
129
  '415 The content-type of the request is incorrect',
183
130
  _response
184
131
  )
185
132
  elsif _response.status_code == 429
186
- raise GenericClientException.new(
133
+ raise MessagingException.new(
187
134
  '429 The rate limit has been reached',
188
135
  _response
189
136
  )
@@ -198,15 +145,16 @@ module Messaging
198
145
  # @param [String] user_id Required parameter: Example:
199
146
  # @param [String] media_id Required parameter: Example:
200
147
  # @param [Long] content_length Required parameter: Example:
201
- # @param [String] body Required parameter: Example:
202
- # @param [String] content_type Optional parameter: Example:
148
+ # @param [File | UploadIO] body Required parameter: Example:
149
+ # @param [String] content_type Optional parameter:
150
+ # Example:application/octet-stream
203
151
  # @param [String] cache_control Optional parameter: Example:
204
152
  # @return [void] response from the API call
205
153
  def upload_media(user_id,
206
154
  media_id,
207
155
  content_length,
208
156
  body,
209
- content_type: nil,
157
+ content_type: 'application/octet-stream',
210
158
  cache_control: nil)
211
159
  # Prepare query url.
212
160
  _query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
@@ -218,10 +166,19 @@ module Messaging
218
166
  )
219
167
  _query_url = APIHelper.clean_url _query_builder
220
168
 
169
+ if body.is_a? FileWrapper
170
+ body_wrapper = body.file
171
+ body_content_type = body.content_type
172
+ else
173
+ body_wrapper = body
174
+ body_content_type = content_type
175
+ end
176
+
221
177
  # Prepare headers.
222
178
  _headers = {
179
+ 'content-type' => body_content_type,
180
+ 'content-length' => body_wrapper.size.to_s,
223
181
  'Content-Length' => content_length,
224
- 'Content-Type' => content_type,
225
182
  'Cache-Control' => cache_control
226
183
  }
227
184
 
@@ -229,39 +186,39 @@ module Messaging
229
186
  _request = config.http_client.put(
230
187
  _query_url,
231
188
  headers: _headers,
232
- parameters: body
189
+ parameters: body_wrapper
233
190
  )
234
191
  MessagingBasicAuth.apply(config, _request)
235
192
  _response = execute_request(_request)
236
193
 
237
194
  # Validate response against endpoint and global error codes.
238
195
  if _response.status_code == 400
239
- raise GenericClientException.new(
196
+ raise MessagingException.new(
240
197
  '400 Request is malformed or invalid',
241
198
  _response
242
199
  )
243
200
  elsif _response.status_code == 401
244
- raise PathClientException.new(
201
+ raise MessagingException.new(
245
202
  '401 The specified user does not have access to the account',
246
203
  _response
247
204
  )
248
205
  elsif _response.status_code == 403
249
- raise PathClientException.new(
206
+ raise MessagingException.new(
250
207
  '403 The user does not have access to this API',
251
208
  _response
252
209
  )
253
210
  elsif _response.status_code == 404
254
- raise PathClientException.new(
211
+ raise MessagingException.new(
255
212
  '404 Path not found',
256
213
  _response
257
214
  )
258
215
  elsif _response.status_code == 415
259
- raise GenericClientException.new(
216
+ raise MessagingException.new(
260
217
  '415 The content-type of the request is incorrect',
261
218
  _response
262
219
  )
263
220
  elsif _response.status_code == 429
264
- raise GenericClientException.new(
221
+ raise MessagingException.new(
265
222
  '429 The rate limit has been reached',
266
223
  _response
267
224
  )
@@ -297,32 +254,32 @@ module Messaging
297
254
 
298
255
  # Validate response against endpoint and global error codes.
299
256
  if _response.status_code == 400
300
- raise GenericClientException.new(
257
+ raise MessagingException.new(
301
258
  '400 Request is malformed or invalid',
302
259
  _response
303
260
  )
304
261
  elsif _response.status_code == 401
305
- raise PathClientException.new(
262
+ raise MessagingException.new(
306
263
  '401 The specified user does not have access to the account',
307
264
  _response
308
265
  )
309
266
  elsif _response.status_code == 403
310
- raise PathClientException.new(
267
+ raise MessagingException.new(
311
268
  '403 The user does not have access to this API',
312
269
  _response
313
270
  )
314
271
  elsif _response.status_code == 404
315
- raise PathClientException.new(
272
+ raise MessagingException.new(
316
273
  '404 Path not found',
317
274
  _response
318
275
  )
319
276
  elsif _response.status_code == 415
320
- raise GenericClientException.new(
277
+ raise MessagingException.new(
321
278
  '415 The content-type of the request is incorrect',
322
279
  _response
323
280
  )
324
281
  elsif _response.status_code == 429
325
- raise GenericClientException.new(
282
+ raise MessagingException.new(
326
283
  '429 The rate limit has been reached',
327
284
  _response
328
285
  )
@@ -365,32 +322,32 @@ module Messaging
365
322
 
366
323
  # Validate response against endpoint and global error codes.
367
324
  if _response.status_code == 400
368
- raise GenericClientException.new(
325
+ raise MessagingException.new(
369
326
  '400 Request is malformed or invalid',
370
327
  _response
371
328
  )
372
329
  elsif _response.status_code == 401
373
- raise PathClientException.new(
330
+ raise MessagingException.new(
374
331
  '401 The specified user does not have access to the account',
375
332
  _response
376
333
  )
377
334
  elsif _response.status_code == 403
378
- raise PathClientException.new(
335
+ raise MessagingException.new(
379
336
  '403 The user does not have access to this API',
380
337
  _response
381
338
  )
382
339
  elsif _response.status_code == 404
383
- raise PathClientException.new(
340
+ raise MessagingException.new(
384
341
  '404 Path not found',
385
342
  _response
386
343
  )
387
344
  elsif _response.status_code == 415
388
- raise GenericClientException.new(
345
+ raise MessagingException.new(
389
346
  '415 The content-type of the request is incorrect',
390
347
  _response
391
348
  )
392
349
  elsif _response.status_code == 429
393
- raise GenericClientException.new(
350
+ raise MessagingException.new(
394
351
  '429 The rate limit has been reached',
395
352
  _response
396
353
  )