bandwidth-sdk 2.1.1 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +85 -70
- data/lib/bandwidth.rb +31 -2
- data/lib/bandwidth/api_helper.rb +14 -9
- data/lib/bandwidth/client.rb +22 -2
- data/lib/bandwidth/configuration.rb +67 -12
- data/lib/bandwidth/http/api_response.rb +2 -0
- data/lib/bandwidth/http/auth/two_factor_auth_basic_auth.rb +22 -0
- data/lib/bandwidth/http/auth/web_rtc_basic_auth.rb +22 -0
- data/lib/bandwidth/http/faraday_client.rb +5 -2
- data/lib/bandwidth/messaging_lib/messaging.rb +5 -3
- data/lib/bandwidth/messaging_lib/messaging/client.rb +13 -2
- data/lib/bandwidth/messaging_lib/messaging/controllers/api_controller.rb +191 -113
- data/lib/bandwidth/messaging_lib/messaging/controllers/base_controller.rb +1 -1
- data/lib/bandwidth/messaging_lib/messaging/exceptions/{generic_client_exception.rb → messaging_exception.rb} +2 -14
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message.rb +23 -13
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_message_item.rb +125 -0
- data/lib/bandwidth/messaging_lib/messaging/models/bandwidth_messages_list.rb +60 -0
- data/lib/bandwidth/messaging_lib/messaging/models/media.rb +4 -4
- data/lib/bandwidth/messaging_lib/messaging/models/message_request.rb +21 -8
- data/lib/bandwidth/messaging_lib/messaging/models/page_info.rb +62 -0
- data/lib/bandwidth/messaging_lib/messaging/models/priority_enum.rb +19 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth.rb +22 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/client.rb +51 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/base_controller.rb +49 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/mfa_controller.rb +209 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/error_with_request_exception.rb +34 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/forbidden_request_exception.rb +29 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/exceptions/unauthorized_request_exception.rb +29 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_code_request_schema.rb +88 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_messaging_response.rb +35 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_code_response.rb +35 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_verify_request_schema.rb +75 -0
- data/lib/bandwidth/two_factor_auth_lib/two_factor_auth/models/two_factor_voice_response.rb +35 -0
- data/lib/bandwidth/utilities/file_wrapper.rb +17 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/bridge.rb +28 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/conference.rb +32 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/gather.rb +13 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/phone_number.rb +7 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/record.rb +9 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/redirect.rb +5 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/ring.rb +15 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/send_dtmf.rb +4 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/sip_uri.rb +25 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/start_gather.rb +20 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/start_recording.rb +4 -1
- data/lib/bandwidth/voice_lib/bxml/verbs/stop_gather.rb +14 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/tag.rb +13 -0
- data/lib/bandwidth/voice_lib/bxml/verbs/transfer.rb +14 -3
- data/lib/bandwidth/voice_lib/voice.rb +19 -4
- data/lib/bandwidth/voice_lib/voice/client.rb +13 -2
- data/lib/bandwidth/voice_lib/voice/controllers/api_controller.rb +1219 -133
- data/lib/bandwidth/voice_lib/voice/controllers/base_controller.rb +1 -1
- data/lib/bandwidth/voice_lib/voice/exceptions/{error_response_exception.rb → api_error_response_exception.rb} +3 -3
- data/lib/bandwidth/voice_lib/voice/models/answer_fallback_method_enum.rb +17 -0
- data/lib/bandwidth/voice_lib/voice/models/api_call_response.rb +56 -2
- data/lib/bandwidth/voice_lib/voice/models/api_call_state_response.rb +164 -0
- data/lib/bandwidth/voice_lib/voice/models/api_create_call_request.rb +135 -12
- data/lib/bandwidth/voice_lib/voice/models/api_modify_call_request.rb +37 -1
- data/lib/bandwidth/voice_lib/voice/models/api_modify_conference_request.rb +107 -0
- data/lib/bandwidth/voice_lib/voice/models/api_transcribe_recording_request.rb +80 -0
- data/lib/bandwidth/voice_lib/voice/models/callback_method_enum.rb +35 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_detail.rb +108 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_event_method_enum.rb +35 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_member_detail.rb +80 -0
- data/lib/bandwidth/voice_lib/voice/models/conference_recording_metadata_response.rb +126 -0
- data/lib/bandwidth/voice_lib/voice/models/disconnect_cause_enum.rb +47 -0
- data/lib/bandwidth/voice_lib/voice/models/modify_call_recording_state.rb +1 -1
- data/lib/bandwidth/voice_lib/voice/models/recording_metadata_response.rb +66 -28
- data/lib/bandwidth/voice_lib/voice/models/redirect_fallback_method_enum.rb +17 -0
- data/lib/bandwidth/voice_lib/voice/models/state1_enum.rb +4 -7
- data/lib/bandwidth/voice_lib/voice/models/state2_enum.rb +20 -0
- data/lib/bandwidth/voice_lib/voice/models/state_enum.rb +7 -4
- data/lib/bandwidth/voice_lib/voice/models/status1_enum.rb +29 -0
- data/lib/bandwidth/voice_lib/voice/models/status3_enum.rb +32 -0
- data/lib/bandwidth/voice_lib/voice/models/status_enum.rb +17 -0
- data/lib/bandwidth/{messaging_lib/messaging/models/field_error.rb → voice_lib/voice/models/transcript.rb} +15 -15
- data/lib/bandwidth/voice_lib/voice/models/transcription.rb +62 -0
- data/lib/bandwidth/voice_lib/voice/models/transcription_response.rb +42 -0
- data/lib/bandwidth/web_rtc_lib/utils/web_rtc_transfer.rb +13 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc.rb +22 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/client.rb +51 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb +692 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/controllers/base_controller.rb +49 -0
- data/lib/bandwidth/{messaging_lib/messaging/exceptions/path_client_exception.rb → web_rtc_lib/web_rtc/exceptions/error_exception.rb} +4 -19
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/accounts_participants_response.rb +47 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/device_api_version_enum.rb +17 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant.rb +92 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/participant_subscription.rb +35 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/publish_permission_enum.rb +17 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/session.rb +44 -0
- data/lib/bandwidth/web_rtc_lib/web_rtc/models/subscriptions.rb +54 -0
- data/test/integration/test_integration.rb +570 -0
- metadata +132 -19
- data/lib/bandwidth/voice_lib/voice/models/api_get_account_recordings_metadata_request.rb +0 -65
- data/lib/bandwidth/voice_lib/voice/models/transcription_status_enum.rb +0 -20
- data/lib/bandwidth/voice_lib/voice/models/type_enum.rb +0 -32
|
@@ -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
|
|
@@ -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
|
|
@@ -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 WebRtcBasicAuth
|
|
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.web_rtc_basic_auth_user_name
|
|
16
|
+
password = config.web_rtc_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
|
|
@@ -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,8 @@ module Bandwidth
|
|
|
34
35
|
http_request.query_url
|
|
35
36
|
) do |request|
|
|
36
37
|
request.headers = http_request.headers
|
|
37
|
-
unless http_request.
|
|
38
|
+
unless http_request.http_method == HttpMethodEnum::GET &&
|
|
39
|
+
http_request.parameters.empty?
|
|
38
40
|
request.body = http_request.parameters
|
|
39
41
|
end
|
|
40
42
|
end
|
|
@@ -48,7 +50,8 @@ module Bandwidth
|
|
|
48
50
|
http_request.query_url
|
|
49
51
|
) do |request|
|
|
50
52
|
request.headers = http_request.headers
|
|
51
|
-
unless http_request.
|
|
53
|
+
unless http_request.http_method == HttpMethodEnum::GET &&
|
|
54
|
+
http_request.parameters.empty?
|
|
52
55
|
request.body = http_request.parameters
|
|
53
56
|
end
|
|
54
57
|
end
|
|
@@ -7,17 +7,19 @@
|
|
|
7
7
|
require_relative 'messaging/client.rb'
|
|
8
8
|
|
|
9
9
|
# Models
|
|
10
|
-
require_relative 'messaging/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'
|
|
11
13
|
require_relative 'messaging/models/media.rb'
|
|
12
14
|
require_relative 'messaging/models/tag.rb'
|
|
13
15
|
require_relative 'messaging/models/deferred_result.rb'
|
|
14
16
|
require_relative 'messaging/models/bandwidth_callback_message.rb'
|
|
15
17
|
require_relative 'messaging/models/bandwidth_message.rb'
|
|
16
18
|
require_relative 'messaging/models/message_request.rb'
|
|
19
|
+
require_relative 'messaging/models/priority_enum.rb'
|
|
17
20
|
|
|
18
21
|
# Exceptions
|
|
19
|
-
require_relative 'messaging/exceptions/
|
|
20
|
-
require_relative 'messaging/exceptions/path_client_exception.rb'
|
|
22
|
+
require_relative 'messaging/exceptions/messaging_exception.rb'
|
|
21
23
|
# Controllers
|
|
22
24
|
require_relative 'messaging/controllers/base_controller.rb'
|
|
23
25
|
require_relative 'messaging/controllers/api_controller.rb'
|
|
@@ -17,20 +17,31 @@ module Bandwidth
|
|
|
17
17
|
|
|
18
18
|
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
|
19
19
|
backoff_factor: 1, environment: Environment::PRODUCTION,
|
|
20
|
+
base_url: 'https://www.example.com',
|
|
20
21
|
messaging_basic_auth_user_name: 'TODO: Replace',
|
|
21
22
|
messaging_basic_auth_password: 'TODO: Replace',
|
|
23
|
+
two_factor_auth_basic_auth_user_name: 'TODO: Replace',
|
|
24
|
+
two_factor_auth_basic_auth_password: 'TODO: Replace',
|
|
22
25
|
voice_basic_auth_user_name: 'TODO: Replace',
|
|
23
|
-
voice_basic_auth_password: 'TODO: Replace',
|
|
26
|
+
voice_basic_auth_password: 'TODO: Replace',
|
|
27
|
+
web_rtc_basic_auth_user_name: 'TODO: Replace',
|
|
28
|
+
web_rtc_basic_auth_password: 'TODO: Replace',
|
|
29
|
+
config: nil)
|
|
24
30
|
@config = if config.nil?
|
|
25
31
|
Configuration.new(timeout: timeout,
|
|
26
32
|
max_retries: max_retries,
|
|
27
33
|
retry_interval: retry_interval,
|
|
28
34
|
backoff_factor: backoff_factor,
|
|
29
35
|
environment: environment,
|
|
36
|
+
base_url: base_url,
|
|
30
37
|
messaging_basic_auth_user_name: messaging_basic_auth_user_name,
|
|
31
38
|
messaging_basic_auth_password: messaging_basic_auth_password,
|
|
39
|
+
two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
|
|
40
|
+
two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
|
|
32
41
|
voice_basic_auth_user_name: voice_basic_auth_user_name,
|
|
33
|
-
voice_basic_auth_password: voice_basic_auth_password
|
|
42
|
+
voice_basic_auth_password: voice_basic_auth_password,
|
|
43
|
+
web_rtc_basic_auth_user_name: web_rtc_basic_auth_user_name,
|
|
44
|
+
web_rtc_basic_auth_password: web_rtc_basic_auth_password)
|
|
34
45
|
else
|
|
35
46
|
config
|
|
36
47
|
end
|
|
@@ -11,62 +11,10 @@ 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
|
-
# @param [String] user_id Required parameter:
|
|
69
|
-
# @param [String] continuation_token Optional parameter:
|
|
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.
|
|
70
18
|
# @return [List of Media] response from the API call
|
|
71
19
|
def list_media(user_id,
|
|
72
20
|
continuation_token: nil)
|
|
@@ -75,7 +23,7 @@ module Messaging
|
|
|
75
23
|
_query_builder << '/users/{userId}/media'
|
|
76
24
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
|
77
25
|
_query_builder,
|
|
78
|
-
'userId' => user_id
|
|
26
|
+
'userId' => { 'value' => user_id, 'encode' => false }
|
|
79
27
|
)
|
|
80
28
|
_query_url = APIHelper.clean_url _query_builder
|
|
81
29
|
|
|
@@ -95,32 +43,32 @@ module Messaging
|
|
|
95
43
|
|
|
96
44
|
# Validate response against endpoint and global error codes.
|
|
97
45
|
if _response.status_code == 400
|
|
98
|
-
raise
|
|
46
|
+
raise MessagingException.new(
|
|
99
47
|
'400 Request is malformed or invalid',
|
|
100
48
|
_response
|
|
101
49
|
)
|
|
102
50
|
elsif _response.status_code == 401
|
|
103
|
-
raise
|
|
51
|
+
raise MessagingException.new(
|
|
104
52
|
'401 The specified user does not have access to the account',
|
|
105
53
|
_response
|
|
106
54
|
)
|
|
107
55
|
elsif _response.status_code == 403
|
|
108
|
-
raise
|
|
56
|
+
raise MessagingException.new(
|
|
109
57
|
'403 The user does not have access to this API',
|
|
110
58
|
_response
|
|
111
59
|
)
|
|
112
60
|
elsif _response.status_code == 404
|
|
113
|
-
raise
|
|
61
|
+
raise MessagingException.new(
|
|
114
62
|
'404 Path not found',
|
|
115
63
|
_response
|
|
116
64
|
)
|
|
117
65
|
elsif _response.status_code == 415
|
|
118
|
-
raise
|
|
66
|
+
raise MessagingException.new(
|
|
119
67
|
'415 The content-type of the request is incorrect',
|
|
120
68
|
_response
|
|
121
69
|
)
|
|
122
70
|
elsif _response.status_code == 429
|
|
123
|
-
raise
|
|
71
|
+
raise MessagingException.new(
|
|
124
72
|
'429 The rate limit has been reached',
|
|
125
73
|
_response
|
|
126
74
|
)
|
|
@@ -129,13 +77,15 @@ module Messaging
|
|
|
129
77
|
|
|
130
78
|
# Return appropriate response type.
|
|
131
79
|
decoded = APIHelper.json_deserialize(_response.raw_body)
|
|
132
|
-
ApiResponse.new(
|
|
133
|
-
|
|
80
|
+
ApiResponse.new(
|
|
81
|
+
_response,
|
|
82
|
+
data: decoded.map { |element| Media.from_hash(element) }
|
|
83
|
+
)
|
|
134
84
|
end
|
|
135
85
|
|
|
136
86
|
# getMedia
|
|
137
|
-
# @param [String] user_id Required parameter:
|
|
138
|
-
# @param [String] media_id Required parameter:
|
|
87
|
+
# @param [String] user_id Required parameter: User's account ID
|
|
88
|
+
# @param [String] media_id Required parameter: Media ID to retrieve
|
|
139
89
|
# @return [Binary] response from the API call
|
|
140
90
|
def get_media(user_id,
|
|
141
91
|
media_id)
|
|
@@ -144,8 +94,8 @@ module Messaging
|
|
|
144
94
|
_query_builder << '/users/{userId}/media/{mediaId}'
|
|
145
95
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
|
146
96
|
_query_builder,
|
|
147
|
-
'userId' => user_id,
|
|
148
|
-
'mediaId' => media_id
|
|
97
|
+
'userId' => { 'value' => user_id, 'encode' => false },
|
|
98
|
+
'mediaId' => { 'value' => media_id, 'encode' => false }
|
|
149
99
|
)
|
|
150
100
|
_query_url = APIHelper.clean_url _query_builder
|
|
151
101
|
|
|
@@ -158,32 +108,32 @@ module Messaging
|
|
|
158
108
|
|
|
159
109
|
# Validate response against endpoint and global error codes.
|
|
160
110
|
if _response.status_code == 400
|
|
161
|
-
raise
|
|
111
|
+
raise MessagingException.new(
|
|
162
112
|
'400 Request is malformed or invalid',
|
|
163
113
|
_response
|
|
164
114
|
)
|
|
165
115
|
elsif _response.status_code == 401
|
|
166
|
-
raise
|
|
116
|
+
raise MessagingException.new(
|
|
167
117
|
'401 The specified user does not have access to the account',
|
|
168
118
|
_response
|
|
169
119
|
)
|
|
170
120
|
elsif _response.status_code == 403
|
|
171
|
-
raise
|
|
121
|
+
raise MessagingException.new(
|
|
172
122
|
'403 The user does not have access to this API',
|
|
173
123
|
_response
|
|
174
124
|
)
|
|
175
125
|
elsif _response.status_code == 404
|
|
176
|
-
raise
|
|
126
|
+
raise MessagingException.new(
|
|
177
127
|
'404 Path not found',
|
|
178
128
|
_response
|
|
179
129
|
)
|
|
180
130
|
elsif _response.status_code == 415
|
|
181
|
-
raise
|
|
131
|
+
raise MessagingException.new(
|
|
182
132
|
'415 The content-type of the request is incorrect',
|
|
183
133
|
_response
|
|
184
134
|
)
|
|
185
135
|
elsif _response.status_code == 429
|
|
186
|
-
raise
|
|
136
|
+
raise MessagingException.new(
|
|
187
137
|
'429 The rate limit has been reached',
|
|
188
138
|
_response
|
|
189
139
|
)
|
|
@@ -191,37 +141,53 @@ module Messaging
|
|
|
191
141
|
validate_response(_response)
|
|
192
142
|
|
|
193
143
|
# Return appropriate response type.
|
|
194
|
-
ApiResponse.new(
|
|
144
|
+
ApiResponse.new(
|
|
145
|
+
_response, data: _response.raw_body
|
|
146
|
+
)
|
|
195
147
|
end
|
|
196
148
|
|
|
197
149
|
# uploadMedia
|
|
198
|
-
# @param [String] user_id Required parameter:
|
|
199
|
-
# @param [String] media_id Required parameter:
|
|
200
|
-
#
|
|
201
|
-
# @param [
|
|
202
|
-
#
|
|
203
|
-
# @param [
|
|
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
|
|
155
|
+
# @param [File | UploadIO] body Required 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.
|
|
204
161
|
# @return [void] response from the API call
|
|
205
162
|
def upload_media(user_id,
|
|
206
163
|
media_id,
|
|
207
164
|
content_length,
|
|
208
165
|
body,
|
|
209
|
-
content_type:
|
|
166
|
+
content_type: 'application/octet-stream',
|
|
210
167
|
cache_control: nil)
|
|
211
168
|
# Prepare query url.
|
|
212
169
|
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
|
213
170
|
_query_builder << '/users/{userId}/media/{mediaId}'
|
|
214
171
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
|
215
172
|
_query_builder,
|
|
216
|
-
'userId' => user_id,
|
|
217
|
-
'mediaId' => media_id
|
|
173
|
+
'userId' => { 'value' => user_id, 'encode' => false },
|
|
174
|
+
'mediaId' => { 'value' => media_id, 'encode' => false }
|
|
218
175
|
)
|
|
219
176
|
_query_url = APIHelper.clean_url _query_builder
|
|
220
177
|
|
|
178
|
+
if body.is_a? FileWrapper
|
|
179
|
+
body_wrapper = body.file
|
|
180
|
+
body_content_type = body.content_type
|
|
181
|
+
else
|
|
182
|
+
body_wrapper = body
|
|
183
|
+
body_content_type = content_type
|
|
184
|
+
end
|
|
185
|
+
|
|
221
186
|
# Prepare headers.
|
|
222
187
|
_headers = {
|
|
188
|
+
'content-type' => body_content_type,
|
|
189
|
+
'content-length' => body_wrapper.size.to_s,
|
|
223
190
|
'Content-Length' => content_length,
|
|
224
|
-
'Content-Type' => content_type,
|
|
225
191
|
'Cache-Control' => cache_control
|
|
226
192
|
}
|
|
227
193
|
|
|
@@ -229,39 +195,39 @@ module Messaging
|
|
|
229
195
|
_request = config.http_client.put(
|
|
230
196
|
_query_url,
|
|
231
197
|
headers: _headers,
|
|
232
|
-
parameters:
|
|
198
|
+
parameters: body_wrapper
|
|
233
199
|
)
|
|
234
200
|
MessagingBasicAuth.apply(config, _request)
|
|
235
201
|
_response = execute_request(_request)
|
|
236
202
|
|
|
237
203
|
# Validate response against endpoint and global error codes.
|
|
238
204
|
if _response.status_code == 400
|
|
239
|
-
raise
|
|
205
|
+
raise MessagingException.new(
|
|
240
206
|
'400 Request is malformed or invalid',
|
|
241
207
|
_response
|
|
242
208
|
)
|
|
243
209
|
elsif _response.status_code == 401
|
|
244
|
-
raise
|
|
210
|
+
raise MessagingException.new(
|
|
245
211
|
'401 The specified user does not have access to the account',
|
|
246
212
|
_response
|
|
247
213
|
)
|
|
248
214
|
elsif _response.status_code == 403
|
|
249
|
-
raise
|
|
215
|
+
raise MessagingException.new(
|
|
250
216
|
'403 The user does not have access to this API',
|
|
251
217
|
_response
|
|
252
218
|
)
|
|
253
219
|
elsif _response.status_code == 404
|
|
254
|
-
raise
|
|
220
|
+
raise MessagingException.new(
|
|
255
221
|
'404 Path not found',
|
|
256
222
|
_response
|
|
257
223
|
)
|
|
258
224
|
elsif _response.status_code == 415
|
|
259
|
-
raise
|
|
225
|
+
raise MessagingException.new(
|
|
260
226
|
'415 The content-type of the request is incorrect',
|
|
261
227
|
_response
|
|
262
228
|
)
|
|
263
229
|
elsif _response.status_code == 429
|
|
264
|
-
raise
|
|
230
|
+
raise MessagingException.new(
|
|
265
231
|
'429 The rate limit has been reached',
|
|
266
232
|
_response
|
|
267
233
|
)
|
|
@@ -273,8 +239,8 @@ module Messaging
|
|
|
273
239
|
end
|
|
274
240
|
|
|
275
241
|
# deleteMedia
|
|
276
|
-
# @param [String] user_id Required parameter:
|
|
277
|
-
# @param [String] media_id Required parameter:
|
|
242
|
+
# @param [String] user_id Required parameter: User's account ID
|
|
243
|
+
# @param [String] media_id Required parameter: The media ID to delete
|
|
278
244
|
# @return [void] response from the API call
|
|
279
245
|
def delete_media(user_id,
|
|
280
246
|
media_id)
|
|
@@ -283,8 +249,8 @@ module Messaging
|
|
|
283
249
|
_query_builder << '/users/{userId}/media/{mediaId}'
|
|
284
250
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
|
285
251
|
_query_builder,
|
|
286
|
-
'userId' => user_id,
|
|
287
|
-
'mediaId' => media_id
|
|
252
|
+
'userId' => { 'value' => user_id, 'encode' => false },
|
|
253
|
+
'mediaId' => { 'value' => media_id, 'encode' => false }
|
|
288
254
|
)
|
|
289
255
|
_query_url = APIHelper.clean_url _query_builder
|
|
290
256
|
|
|
@@ -297,32 +263,32 @@ module Messaging
|
|
|
297
263
|
|
|
298
264
|
# Validate response against endpoint and global error codes.
|
|
299
265
|
if _response.status_code == 400
|
|
300
|
-
raise
|
|
266
|
+
raise MessagingException.new(
|
|
301
267
|
'400 Request is malformed or invalid',
|
|
302
268
|
_response
|
|
303
269
|
)
|
|
304
270
|
elsif _response.status_code == 401
|
|
305
|
-
raise
|
|
271
|
+
raise MessagingException.new(
|
|
306
272
|
'401 The specified user does not have access to the account',
|
|
307
273
|
_response
|
|
308
274
|
)
|
|
309
275
|
elsif _response.status_code == 403
|
|
310
|
-
raise
|
|
276
|
+
raise MessagingException.new(
|
|
311
277
|
'403 The user does not have access to this API',
|
|
312
278
|
_response
|
|
313
279
|
)
|
|
314
280
|
elsif _response.status_code == 404
|
|
315
|
-
raise
|
|
281
|
+
raise MessagingException.new(
|
|
316
282
|
'404 Path not found',
|
|
317
283
|
_response
|
|
318
284
|
)
|
|
319
285
|
elsif _response.status_code == 415
|
|
320
|
-
raise
|
|
286
|
+
raise MessagingException.new(
|
|
321
287
|
'415 The content-type of the request is incorrect',
|
|
322
288
|
_response
|
|
323
289
|
)
|
|
324
290
|
elsif _response.status_code == 429
|
|
325
|
-
raise
|
|
291
|
+
raise MessagingException.new(
|
|
326
292
|
'429 The rate limit has been reached',
|
|
327
293
|
_response
|
|
328
294
|
)
|
|
@@ -333,18 +299,128 @@ module Messaging
|
|
|
333
299
|
ApiResponse.new(_response)
|
|
334
300
|
end
|
|
335
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
|
+
|
|
336
412
|
# createMessage
|
|
337
|
-
# @param [String] user_id Required parameter:
|
|
338
|
-
# @param [MessageRequest] body
|
|
413
|
+
# @param [String] user_id Required parameter: User's account ID
|
|
414
|
+
# @param [MessageRequest] body Required parameter: Example:
|
|
339
415
|
# @return [BandwidthMessage] response from the API call
|
|
340
416
|
def create_message(user_id,
|
|
341
|
-
body
|
|
417
|
+
body)
|
|
342
418
|
# Prepare query url.
|
|
343
419
|
_query_builder = config.get_base_uri(Server::MESSAGINGDEFAULT)
|
|
344
420
|
_query_builder << '/users/{userId}/messages'
|
|
345
421
|
_query_builder = APIHelper.append_url_with_template_parameters(
|
|
346
422
|
_query_builder,
|
|
347
|
-
'userId' => user_id
|
|
423
|
+
'userId' => { 'value' => user_id, 'encode' => false }
|
|
348
424
|
)
|
|
349
425
|
_query_url = APIHelper.clean_url _query_builder
|
|
350
426
|
|
|
@@ -365,32 +441,32 @@ module Messaging
|
|
|
365
441
|
|
|
366
442
|
# Validate response against endpoint and global error codes.
|
|
367
443
|
if _response.status_code == 400
|
|
368
|
-
raise
|
|
444
|
+
raise MessagingException.new(
|
|
369
445
|
'400 Request is malformed or invalid',
|
|
370
446
|
_response
|
|
371
447
|
)
|
|
372
448
|
elsif _response.status_code == 401
|
|
373
|
-
raise
|
|
449
|
+
raise MessagingException.new(
|
|
374
450
|
'401 The specified user does not have access to the account',
|
|
375
451
|
_response
|
|
376
452
|
)
|
|
377
453
|
elsif _response.status_code == 403
|
|
378
|
-
raise
|
|
454
|
+
raise MessagingException.new(
|
|
379
455
|
'403 The user does not have access to this API',
|
|
380
456
|
_response
|
|
381
457
|
)
|
|
382
458
|
elsif _response.status_code == 404
|
|
383
|
-
raise
|
|
459
|
+
raise MessagingException.new(
|
|
384
460
|
'404 Path not found',
|
|
385
461
|
_response
|
|
386
462
|
)
|
|
387
463
|
elsif _response.status_code == 415
|
|
388
|
-
raise
|
|
464
|
+
raise MessagingException.new(
|
|
389
465
|
'415 The content-type of the request is incorrect',
|
|
390
466
|
_response
|
|
391
467
|
)
|
|
392
468
|
elsif _response.status_code == 429
|
|
393
|
-
raise
|
|
469
|
+
raise MessagingException.new(
|
|
394
470
|
'429 The rate limit has been reached',
|
|
395
471
|
_response
|
|
396
472
|
)
|
|
@@ -399,7 +475,9 @@ module Messaging
|
|
|
399
475
|
|
|
400
476
|
# Return appropriate response type.
|
|
401
477
|
decoded = APIHelper.json_deserialize(_response.raw_body)
|
|
402
|
-
ApiResponse.new(
|
|
478
|
+
ApiResponse.new(
|
|
479
|
+
_response, data: BandwidthMessage.from_hash(decoded)
|
|
480
|
+
)
|
|
403
481
|
end
|
|
404
482
|
end
|
|
405
483
|
end
|