bandwidth-sdk 0.1.0 → 1.0.0.pre
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 +5 -5
- data/LICENSE +27 -27
- data/README.md +115 -1
- data/lib/bandwidth.rb +39 -37
- data/lib/bandwidth/api_helper.rb +280 -280
- data/lib/bandwidth/client.rb +41 -32
- data/lib/bandwidth/configuration.rb +130 -111
- data/lib/bandwidth/exceptions/api_exception.rb +20 -20
- data/lib/bandwidth/http/api_response.rb +36 -36
- data/lib/bandwidth/http/auth/messaging_basic_auth.rb +22 -0
- data/lib/bandwidth/http/auth/voice_basic_auth.rb +22 -22
- data/lib/bandwidth/http/faraday_client.rb +64 -64
- data/lib/bandwidth/http/http_call_back.rb +24 -24
- data/lib/bandwidth/http/http_client.rb +104 -104
- data/lib/bandwidth/http/http_method_enum.rb +13 -13
- data/lib/bandwidth/http/http_request.rb +50 -50
- data/lib/bandwidth/http/http_response.rb +29 -29
- data/lib/bandwidth/messaging_lib/messaging.rb +23 -0
- data/lib/bandwidth/messaging_lib/messaging/client.rb +40 -0
- data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +406 -0
- data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +49 -0
- data/lib/bandwidth/messaging_lib/messaging/exceptions/generic_client_exception.rb +46 -0
- data/lib/bandwidth/messaging_lib/messaging/exceptions/path_client_exception.rb +49 -0
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_callback_message.rb +80 -0
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +125 -0
- data/lib/bandwidth/messaging_lib/messaging/models/deferred_result.rb +44 -0
- data/lib/bandwidth/messaging_lib/messaging/models/field_error.rb +44 -0
- data/lib/bandwidth/messaging_lib/messaging/models/media.rb +123 -0
- data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +80 -0
- data/lib/bandwidth/messaging_lib/messaging/models/tag.rb +44 -0
- data/lib/bandwidth/models/base_model.rb +36 -36
- data/lib/bandwidth/voice_lib/bxml/bxml.rb +40 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/forward.rb +19 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/gather.rb +38 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/hangup.rb +15 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/pause.rb +16 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/phone_number.rb +19 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/play_audio.rb +18 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/redirect.rb +21 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/send_dtmf.rb +14 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/speak_sentence.rb +19 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/transfer.rb +38 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/xml_verb.rb +27 -0
- data/lib/bandwidth/voice_lib/voice.rb +27 -23
- data/lib/bandwidth/voice_lib/voice/client.rb +40 -36
- data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +184 -0
- data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +49 -49
- data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_exception.rb +51 -0
- data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_not_found_exception.rb +49 -0
- data/lib/bandwidth/voice_lib/voice/exceptions/bandwidth_rate_limit_error_exception.rb +56 -0
- data/lib/bandwidth/voice_lib/voice/models/answer_method_enum.rb +35 -35
- data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +116 -116
- data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +125 -125
- data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +80 -80
- data/lib/bandwidth/voice_lib/voice/models/bandwidth_callback_message_voice.rb +98 -98
- data/lib/bandwidth/voice_lib/voice/models/disconnect_method_enum.rb +35 -35
- data/lib/bandwidth/voice_lib/voice/models/field_error.rb +44 -0
- data/lib/bandwidth/voice_lib/voice/models/redirect_method_enum.rb +35 -35
- data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +17 -17
- metadata +36 -47
- data/lib/bandwidth/voice_lib/voice/bxml/bxml.rb +0 -36
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/forward.rb +0 -19
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/gather.rb +0 -37
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/hangup.rb +0 -14
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/pause.rb +0 -15
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/phone_number.rb +0 -18
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/play_audio.rb +0 -17
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/redirect.rb +0 -20
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/send_dtmf.rb +0 -12
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/speak_sentence.rb +0 -18
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/transfer.rb +0 -37
- data/lib/bandwidth/voice_lib/voice/bxml/verbs/xml_verb.rb +0 -26
- data/lib/bandwidth/voice_lib/voice/controllers/calls_controller.rb +0 -88
@@ -1,50 +1,50 @@
|
|
1
|
-
# bandwidth
|
2
|
-
#
|
3
|
-
# This file was automatically generated by APIMATIC v2.0
|
4
|
-
# ( https://apimatic.io ).
|
5
|
-
|
6
|
-
module Bandwidth
|
7
|
-
# Represents a single Http Request.
|
8
|
-
class HttpRequest
|
9
|
-
attr_accessor :http_method, :query_url, :headers,
|
10
|
-
:parameters, :username, :password
|
11
|
-
|
12
|
-
# The constructor.
|
13
|
-
# @param [HttpMethodEnum] The HTTP method.
|
14
|
-
# @param [String] The URL to send the request to.
|
15
|
-
# @param [Hash, Optional] The headers for the HTTP Request.
|
16
|
-
# @param [Hash, Optional] The parameters for the HTTP Request.
|
17
|
-
def initialize(http_method,
|
18
|
-
query_url,
|
19
|
-
headers: {},
|
20
|
-
parameters: {})
|
21
|
-
@http_method = http_method
|
22
|
-
@query_url = query_url
|
23
|
-
@headers = headers
|
24
|
-
@parameters = parameters
|
25
|
-
end
|
26
|
-
|
27
|
-
# Add a header to the HttpRequest.
|
28
|
-
# @param [String] The name of the header.
|
29
|
-
# @param [String] The value of the header.
|
30
|
-
def add_header(name, value)
|
31
|
-
@headers[name] = value
|
32
|
-
end
|
33
|
-
|
34
|
-
# Add a parameter to the HttpRequest.
|
35
|
-
# @param [String] The name of the parameter.
|
36
|
-
# @param [String] The value of the parameter.
|
37
|
-
def add_parameter(name, value)
|
38
|
-
@parameters[name] = value
|
39
|
-
end
|
40
|
-
|
41
|
-
# Add a query parameter to the HttpRequest.
|
42
|
-
# @param [String] The name of the query parameter.
|
43
|
-
# @param [String] The value of the query parameter.
|
44
|
-
def add_query_parameter(name, value)
|
45
|
-
@query_url = APIHelper.append_url_with_query_parameters(@query_url,
|
46
|
-
name => value)
|
47
|
-
@query_url = APIHelper.clean_url(@query_url)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Represents a single Http Request.
|
8
|
+
class HttpRequest
|
9
|
+
attr_accessor :http_method, :query_url, :headers,
|
10
|
+
:parameters, :username, :password
|
11
|
+
|
12
|
+
# The constructor.
|
13
|
+
# @param [HttpMethodEnum] The HTTP method.
|
14
|
+
# @param [String] The URL to send the request to.
|
15
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
16
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
17
|
+
def initialize(http_method,
|
18
|
+
query_url,
|
19
|
+
headers: {},
|
20
|
+
parameters: {})
|
21
|
+
@http_method = http_method
|
22
|
+
@query_url = query_url
|
23
|
+
@headers = headers
|
24
|
+
@parameters = parameters
|
25
|
+
end
|
26
|
+
|
27
|
+
# Add a header to the HttpRequest.
|
28
|
+
# @param [String] The name of the header.
|
29
|
+
# @param [String] The value of the header.
|
30
|
+
def add_header(name, value)
|
31
|
+
@headers[name] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
# Add a parameter to the HttpRequest.
|
35
|
+
# @param [String] The name of the parameter.
|
36
|
+
# @param [String] The value of the parameter.
|
37
|
+
def add_parameter(name, value)
|
38
|
+
@parameters[name] = value
|
39
|
+
end
|
40
|
+
|
41
|
+
# Add a query parameter to the HttpRequest.
|
42
|
+
# @param [String] The name of the query parameter.
|
43
|
+
# @param [String] The value of the query parameter.
|
44
|
+
def add_query_parameter(name, value)
|
45
|
+
@query_url = APIHelper.append_url_with_query_parameters(@query_url,
|
46
|
+
name => value)
|
47
|
+
@query_url = APIHelper.clean_url(@query_url)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
# bandwidth
|
2
|
-
#
|
3
|
-
# This file was automatically generated by APIMATIC v2.0
|
4
|
-
# ( https://apimatic.io ).
|
5
|
-
|
6
|
-
module Bandwidth
|
7
|
-
# Http response received.
|
8
|
-
class HttpResponse
|
9
|
-
attr_reader :status_code, :reason_phrase, :headers, :raw_body, :request
|
10
|
-
|
11
|
-
# The constructor
|
12
|
-
# @param [Integer] The status code returned by the server.
|
13
|
-
# @param [String] The reason phrase returned by the server.
|
14
|
-
# @param [Hash] The headers sent by the server in the response.
|
15
|
-
# @param [String] The raw body of the response.
|
16
|
-
# @param [HttpRequest] The request that resulted in this response.
|
17
|
-
def initialize(status_code,
|
18
|
-
reason_phrase,
|
19
|
-
headers,
|
20
|
-
raw_body,
|
21
|
-
request)
|
22
|
-
@status_code = status_code
|
23
|
-
@reason_phrase = reason_phrase
|
24
|
-
@headers = headers
|
25
|
-
@raw_body = raw_body
|
26
|
-
@request = request
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
# Http response received.
|
8
|
+
class HttpResponse
|
9
|
+
attr_reader :status_code, :reason_phrase, :headers, :raw_body, :request
|
10
|
+
|
11
|
+
# The constructor
|
12
|
+
# @param [Integer] The status code returned by the server.
|
13
|
+
# @param [String] The reason phrase returned by the server.
|
14
|
+
# @param [Hash] The headers sent by the server in the response.
|
15
|
+
# @param [String] The raw body of the response.
|
16
|
+
# @param [HttpRequest] The request that resulted in this response.
|
17
|
+
def initialize(status_code,
|
18
|
+
reason_phrase,
|
19
|
+
headers,
|
20
|
+
raw_body,
|
21
|
+
request)
|
22
|
+
@status_code = status_code
|
23
|
+
@reason_phrase = reason_phrase
|
24
|
+
@headers = headers
|
25
|
+
@raw_body = raw_body
|
26
|
+
@request = request
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
|
7
|
+
require_relative 'messaging/client.rb'
|
8
|
+
|
9
|
+
# Models
|
10
|
+
require_relative 'messaging/models/field_error.rb'
|
11
|
+
require_relative 'messaging/models/media.rb'
|
12
|
+
require_relative 'messaging/models/tag.rb'
|
13
|
+
require_relative 'messaging/models/deferred_result.rb'
|
14
|
+
require_relative 'messaging/models/bandwidth_callback_message.rb'
|
15
|
+
require_relative 'messaging/models/bandwidth_message.rb'
|
16
|
+
require_relative 'messaging/models/message_request.rb'
|
17
|
+
|
18
|
+
# Exceptions
|
19
|
+
require_relative 'messaging/exceptions/generic_client_exception.rb'
|
20
|
+
require_relative 'messaging/exceptions/path_client_exception.rb'
|
21
|
+
# Controllers
|
22
|
+
require_relative 'messaging/controllers/base_controller.rb'
|
23
|
+
require_relative 'messaging/controllers/api_controller.rb'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
module Messaging
|
8
|
+
# bandwidth client class.
|
9
|
+
class Client
|
10
|
+
attr_reader :config
|
11
|
+
|
12
|
+
# Access to client controller.
|
13
|
+
# @return [APIController] Returns the controller instance.
|
14
|
+
def client
|
15
|
+
@client ||= APIController.new config
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(timeout: 0, max_retries: 0, retry_interval: 1,
|
19
|
+
backoff_factor: 1, environment: Environment::PRODUCTION,
|
20
|
+
messaging_basic_auth_user_name: 'TODO: Replace',
|
21
|
+
messaging_basic_auth_password: 'TODO: Replace',
|
22
|
+
voice_basic_auth_user_name: 'TODO: Replace',
|
23
|
+
voice_basic_auth_password: 'TODO: Replace', config: nil)
|
24
|
+
@config = if config.nil?
|
25
|
+
Configuration.new(timeout: timeout,
|
26
|
+
max_retries: max_retries,
|
27
|
+
retry_interval: retry_interval,
|
28
|
+
backoff_factor: backoff_factor,
|
29
|
+
environment: environment,
|
30
|
+
messaging_basic_auth_user_name: messaging_basic_auth_user_name,
|
31
|
+
messaging_basic_auth_password: messaging_basic_auth_password,
|
32
|
+
voice_basic_auth_user_name: voice_basic_auth_user_name,
|
33
|
+
voice_basic_auth_password: voice_basic_auth_password)
|
34
|
+
else
|
35
|
+
config
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,406 @@
|
|
1
|
+
# bandwidth
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Bandwidth
|
7
|
+
module Messaging
|
8
|
+
# APIController
|
9
|
+
class APIController < BaseController
|
10
|
+
def initialize(config, http_call_back: nil)
|
11
|
+
super(config, http_call_back: http_call_back)
|
12
|
+
end
|
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
|
+
# listMedia
|
68
|
+
# @param [String] user_id Required parameter: Example:
|
69
|
+
# @param [String] continuation_token Optional parameter: Example:
|
70
|
+
# @return [List of Media] response from the API call
|
71
|
+
def list_media(user_id,
|
72
|
+
continuation_token: nil)
|
73
|
+
# Prepare query url.
|
74
|
+
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
75
|
+
_query_builder << '/users/{userId}/media'
|
76
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
77
|
+
_query_builder,
|
78
|
+
'userId' => user_id
|
79
|
+
)
|
80
|
+
_query_url = APIHelper.clean_url _query_builder
|
81
|
+
|
82
|
+
# Prepare headers.
|
83
|
+
_headers = {
|
84
|
+
'accept' => 'application/json',
|
85
|
+
'Continuation-Token' => continuation_token
|
86
|
+
}
|
87
|
+
|
88
|
+
# Prepare and execute HttpRequest.
|
89
|
+
_request = config.http_client.get(
|
90
|
+
_query_url,
|
91
|
+
headers: _headers
|
92
|
+
)
|
93
|
+
MessagingBasicAuth.apply(config, _request)
|
94
|
+
_response = execute_request(_request)
|
95
|
+
|
96
|
+
# Validate response against endpoint and global error codes.
|
97
|
+
if _response.status_code == 400
|
98
|
+
raise GenericClientException.new(
|
99
|
+
'400 Request is malformed or invalid',
|
100
|
+
_response
|
101
|
+
)
|
102
|
+
elsif _response.status_code == 401
|
103
|
+
raise PathClientException.new(
|
104
|
+
'401 The specified user does not have access to the account',
|
105
|
+
_response
|
106
|
+
)
|
107
|
+
elsif _response.status_code == 403
|
108
|
+
raise PathClientException.new(
|
109
|
+
'403 The user does not have access to this API',
|
110
|
+
_response
|
111
|
+
)
|
112
|
+
elsif _response.status_code == 404
|
113
|
+
raise PathClientException.new(
|
114
|
+
'404 Path not found',
|
115
|
+
_response
|
116
|
+
)
|
117
|
+
elsif _response.status_code == 415
|
118
|
+
raise GenericClientException.new(
|
119
|
+
'415 The content-type of the request is incorrect',
|
120
|
+
_response
|
121
|
+
)
|
122
|
+
elsif _response.status_code == 429
|
123
|
+
raise GenericClientException.new(
|
124
|
+
'429 The rate limit has been reached',
|
125
|
+
_response
|
126
|
+
)
|
127
|
+
end
|
128
|
+
validate_response(_response)
|
129
|
+
|
130
|
+
# Return appropriate response type.
|
131
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
132
|
+
ApiResponse.new(_response,
|
133
|
+
data: decoded.map { |element| Media.from_hash(element) })
|
134
|
+
end
|
135
|
+
|
136
|
+
# getMedia
|
137
|
+
# @param [String] user_id Required parameter: Example:
|
138
|
+
# @param [String] media_id Required parameter: Example:
|
139
|
+
# @return [Binary] response from the API call
|
140
|
+
def get_media(user_id,
|
141
|
+
media_id)
|
142
|
+
# Prepare query url.
|
143
|
+
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
144
|
+
_query_builder << '/users/{userId}/media/{mediaId}'
|
145
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
146
|
+
_query_builder,
|
147
|
+
'userId' => user_id,
|
148
|
+
'mediaId' => media_id
|
149
|
+
)
|
150
|
+
_query_url = APIHelper.clean_url _query_builder
|
151
|
+
|
152
|
+
# Prepare and execute HttpRequest.
|
153
|
+
_request = config.http_client.get(
|
154
|
+
_query_url
|
155
|
+
)
|
156
|
+
MessagingBasicAuth.apply(config, _request)
|
157
|
+
_response = execute_request(_request, binary: true)
|
158
|
+
|
159
|
+
# Validate response against endpoint and global error codes.
|
160
|
+
if _response.status_code == 400
|
161
|
+
raise GenericClientException.new(
|
162
|
+
'400 Request is malformed or invalid',
|
163
|
+
_response
|
164
|
+
)
|
165
|
+
elsif _response.status_code == 401
|
166
|
+
raise PathClientException.new(
|
167
|
+
'401 The specified user does not have access to the account',
|
168
|
+
_response
|
169
|
+
)
|
170
|
+
elsif _response.status_code == 403
|
171
|
+
raise PathClientException.new(
|
172
|
+
'403 The user does not have access to this API',
|
173
|
+
_response
|
174
|
+
)
|
175
|
+
elsif _response.status_code == 404
|
176
|
+
raise PathClientException.new(
|
177
|
+
'404 Path not found',
|
178
|
+
_response
|
179
|
+
)
|
180
|
+
elsif _response.status_code == 415
|
181
|
+
raise GenericClientException.new(
|
182
|
+
'415 The content-type of the request is incorrect',
|
183
|
+
_response
|
184
|
+
)
|
185
|
+
elsif _response.status_code == 429
|
186
|
+
raise GenericClientException.new(
|
187
|
+
'429 The rate limit has been reached',
|
188
|
+
_response
|
189
|
+
)
|
190
|
+
end
|
191
|
+
validate_response(_response)
|
192
|
+
|
193
|
+
# Return appropriate response type.
|
194
|
+
ApiResponse.new(_response, data: _response.raw_body)
|
195
|
+
end
|
196
|
+
|
197
|
+
# uploadMedia
|
198
|
+
# @param [String] user_id Required parameter: Example:
|
199
|
+
# @param [String] media_id Required parameter: Example:
|
200
|
+
# @param [Long] content_length Required parameter: Example:
|
201
|
+
# @param [String] body Required parameter: Example:
|
202
|
+
# @param [String] content_type Optional parameter: Example:
|
203
|
+
# @param [String] cache_control Optional parameter: Example:
|
204
|
+
# @return [void] response from the API call
|
205
|
+
def upload_media(user_id,
|
206
|
+
media_id,
|
207
|
+
content_length,
|
208
|
+
body,
|
209
|
+
content_type: nil,
|
210
|
+
cache_control: nil)
|
211
|
+
# Prepare query url.
|
212
|
+
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
213
|
+
_query_builder << '/users/{userId}/media/{mediaId}'
|
214
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
215
|
+
_query_builder,
|
216
|
+
'userId' => user_id,
|
217
|
+
'mediaId' => media_id
|
218
|
+
)
|
219
|
+
_query_url = APIHelper.clean_url _query_builder
|
220
|
+
|
221
|
+
# Prepare headers.
|
222
|
+
_headers = {
|
223
|
+
'Content-Length' => content_length,
|
224
|
+
'Content-Type' => content_type,
|
225
|
+
'Cache-Control' => cache_control
|
226
|
+
}
|
227
|
+
|
228
|
+
# Prepare and execute HttpRequest.
|
229
|
+
_request = config.http_client.put(
|
230
|
+
_query_url,
|
231
|
+
headers: _headers,
|
232
|
+
parameters: body
|
233
|
+
)
|
234
|
+
MessagingBasicAuth.apply(config, _request)
|
235
|
+
_response = execute_request(_request)
|
236
|
+
|
237
|
+
# Validate response against endpoint and global error codes.
|
238
|
+
if _response.status_code == 400
|
239
|
+
raise GenericClientException.new(
|
240
|
+
'400 Request is malformed or invalid',
|
241
|
+
_response
|
242
|
+
)
|
243
|
+
elsif _response.status_code == 401
|
244
|
+
raise PathClientException.new(
|
245
|
+
'401 The specified user does not have access to the account',
|
246
|
+
_response
|
247
|
+
)
|
248
|
+
elsif _response.status_code == 403
|
249
|
+
raise PathClientException.new(
|
250
|
+
'403 The user does not have access to this API',
|
251
|
+
_response
|
252
|
+
)
|
253
|
+
elsif _response.status_code == 404
|
254
|
+
raise PathClientException.new(
|
255
|
+
'404 Path not found',
|
256
|
+
_response
|
257
|
+
)
|
258
|
+
elsif _response.status_code == 415
|
259
|
+
raise GenericClientException.new(
|
260
|
+
'415 The content-type of the request is incorrect',
|
261
|
+
_response
|
262
|
+
)
|
263
|
+
elsif _response.status_code == 429
|
264
|
+
raise GenericClientException.new(
|
265
|
+
'429 The rate limit has been reached',
|
266
|
+
_response
|
267
|
+
)
|
268
|
+
end
|
269
|
+
validate_response(_response)
|
270
|
+
|
271
|
+
# Return appropriate response type.
|
272
|
+
ApiResponse.new(_response)
|
273
|
+
end
|
274
|
+
|
275
|
+
# deleteMedia
|
276
|
+
# @param [String] user_id Required parameter: Example:
|
277
|
+
# @param [String] media_id Required parameter: Example:
|
278
|
+
# @return [void] response from the API call
|
279
|
+
def delete_media(user_id,
|
280
|
+
media_id)
|
281
|
+
# Prepare query url.
|
282
|
+
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
283
|
+
_query_builder << '/users/{userId}/media/{mediaId}'
|
284
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
285
|
+
_query_builder,
|
286
|
+
'userId' => user_id,
|
287
|
+
'mediaId' => media_id
|
288
|
+
)
|
289
|
+
_query_url = APIHelper.clean_url _query_builder
|
290
|
+
|
291
|
+
# Prepare and execute HttpRequest.
|
292
|
+
_request = config.http_client.delete(
|
293
|
+
_query_url
|
294
|
+
)
|
295
|
+
MessagingBasicAuth.apply(config, _request)
|
296
|
+
_response = execute_request(_request)
|
297
|
+
|
298
|
+
# Validate response against endpoint and global error codes.
|
299
|
+
if _response.status_code == 400
|
300
|
+
raise GenericClientException.new(
|
301
|
+
'400 Request is malformed or invalid',
|
302
|
+
_response
|
303
|
+
)
|
304
|
+
elsif _response.status_code == 401
|
305
|
+
raise PathClientException.new(
|
306
|
+
'401 The specified user does not have access to the account',
|
307
|
+
_response
|
308
|
+
)
|
309
|
+
elsif _response.status_code == 403
|
310
|
+
raise PathClientException.new(
|
311
|
+
'403 The user does not have access to this API',
|
312
|
+
_response
|
313
|
+
)
|
314
|
+
elsif _response.status_code == 404
|
315
|
+
raise PathClientException.new(
|
316
|
+
'404 Path not found',
|
317
|
+
_response
|
318
|
+
)
|
319
|
+
elsif _response.status_code == 415
|
320
|
+
raise GenericClientException.new(
|
321
|
+
'415 The content-type of the request is incorrect',
|
322
|
+
_response
|
323
|
+
)
|
324
|
+
elsif _response.status_code == 429
|
325
|
+
raise GenericClientException.new(
|
326
|
+
'429 The rate limit has been reached',
|
327
|
+
_response
|
328
|
+
)
|
329
|
+
end
|
330
|
+
validate_response(_response)
|
331
|
+
|
332
|
+
# Return appropriate response type.
|
333
|
+
ApiResponse.new(_response)
|
334
|
+
end
|
335
|
+
|
336
|
+
# createMessage
|
337
|
+
# @param [String] user_id Required parameter: Example:
|
338
|
+
# @param [MessageRequest] body Optional parameter: Example:
|
339
|
+
# @return [BandwidthMessage] response from the API call
|
340
|
+
def create_message(user_id,
|
341
|
+
body: nil)
|
342
|
+
# Prepare query url.
|
343
|
+
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
344
|
+
_query_builder << '/users/{userId}/messages'
|
345
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
346
|
+
_query_builder,
|
347
|
+
'userId' => user_id
|
348
|
+
)
|
349
|
+
_query_url = APIHelper.clean_url _query_builder
|
350
|
+
|
351
|
+
# Prepare headers.
|
352
|
+
_headers = {
|
353
|
+
'accept' => 'application/json',
|
354
|
+
'content-type' => 'application/json; charset=utf-8'
|
355
|
+
}
|
356
|
+
|
357
|
+
# Prepare and execute HttpRequest.
|
358
|
+
_request = config.http_client.post(
|
359
|
+
_query_url,
|
360
|
+
headers: _headers,
|
361
|
+
parameters: body.to_json
|
362
|
+
)
|
363
|
+
MessagingBasicAuth.apply(config, _request)
|
364
|
+
_response = execute_request(_request)
|
365
|
+
|
366
|
+
# Validate response against endpoint and global error codes.
|
367
|
+
if _response.status_code == 400
|
368
|
+
raise GenericClientException.new(
|
369
|
+
'400 Request is malformed or invalid',
|
370
|
+
_response
|
371
|
+
)
|
372
|
+
elsif _response.status_code == 401
|
373
|
+
raise PathClientException.new(
|
374
|
+
'401 The specified user does not have access to the account',
|
375
|
+
_response
|
376
|
+
)
|
377
|
+
elsif _response.status_code == 403
|
378
|
+
raise PathClientException.new(
|
379
|
+
'403 The user does not have access to this API',
|
380
|
+
_response
|
381
|
+
)
|
382
|
+
elsif _response.status_code == 404
|
383
|
+
raise PathClientException.new(
|
384
|
+
'404 Path not found',
|
385
|
+
_response
|
386
|
+
)
|
387
|
+
elsif _response.status_code == 415
|
388
|
+
raise GenericClientException.new(
|
389
|
+
'415 The content-type of the request is incorrect',
|
390
|
+
_response
|
391
|
+
)
|
392
|
+
elsif _response.status_code == 429
|
393
|
+
raise GenericClientException.new(
|
394
|
+
'429 The rate limit has been reached',
|
395
|
+
_response
|
396
|
+
)
|
397
|
+
end
|
398
|
+
validate_response(_response)
|
399
|
+
|
400
|
+
# Return appropriate response type.
|
401
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
402
|
+
ApiResponse.new(_response, data: BandwidthMessage.from_hash(decoded))
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|