messagemedia_messages_sdk 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +240 -55
- data/lib/message_media_messages.rb +32 -18
- data/lib/message_media_messages/api_helper.rb +76 -9
- data/lib/message_media_messages/configuration.rb +8 -6
- data/lib/message_media_messages/controllers/base_controller.rb +13 -29
- data/lib/message_media_messages/controllers/delivery_reports_controller.rb +55 -100
- data/lib/message_media_messages/controllers/messages_controller.rb +162 -199
- data/lib/message_media_messages/controllers/replies_controller.rb +79 -123
- data/lib/message_media_messages/exceptions/api_exception.rb +5 -3
- data/lib/message_media_messages/exceptions/send_messages400_response_exception.rb +29 -0
- data/lib/message_media_messages/http/auth/auth_manager.rb +90 -0
- data/lib/message_media_messages/http/faraday_client.rb +10 -3
- data/lib/message_media_messages/http/http_call_back.rb +5 -3
- data/lib/message_media_messages/http/http_client.rb +29 -18
- data/lib/message_media_messages/http/http_context.rb +5 -3
- data/lib/message_media_messages/http/http_method_enum.rb +4 -2
- data/lib/message_media_messages/http/http_request.rb +13 -11
- data/lib/message_media_messages/http/http_response.rb +6 -4
- data/lib/message_media_messages/message_media_messages_client.rb +9 -6
- data/lib/message_media_messages/models/base_model.rb +4 -1
- data/lib/message_media_messages/models/cancel_scheduled_message_request.rb +7 -7
- data/lib/message_media_messages/models/check_delivery_reports_response.rb +15 -8
- data/lib/message_media_messages/models/check_replies_response.rb +15 -8
- data/lib/message_media_messages/models/confirm_delivery_reports_as_received_request.rb +5 -5
- data/lib/message_media_messages/models/{confirm_delivery_reports_as_received_request_11.rb → confirm_delivery_reports_as_received_request1.rb} +8 -8
- data/lib/message_media_messages/models/confirm_replies_as_received_request.rb +5 -5
- data/lib/message_media_messages/models/{confirm_replies_as_received_request_8.rb → confirm_replies_as_received_request1.rb} +8 -8
- data/lib/message_media_messages/models/delivery_report.rb +135 -0
- data/lib/message_media_messages/models/format1_enum.rb +20 -0
- data/lib/message_media_messages/models/format_enum.rb +20 -0
- data/lib/message_media_messages/models/get_message_status_response.rb +145 -0
- data/lib/message_media_messages/models/message.rb +166 -0
- data/lib/message_media_messages/models/reply.rb +112 -0
- data/lib/message_media_messages/models/send_messages_request.rb +14 -7
- data/lib/message_media_messages/models/send_messages_response.rb +14 -7
- data/lib/message_media_messages/models/source_number_type_enum.rb +21 -0
- data/lib/message_media_messages/models/status2_enum.rb +32 -0
- data/lib/message_media_messages/models/status_enum.rb +44 -0
- data/lib/message_media_messages/models/vendor_account_id.rb +44 -0
- metadata +18 -21
- data/lib/message_media_messages/http/auth/basic_auth.rb +0 -20
- data/lib/message_media_messages/http/auth/hmac_auth.rb +0 -54
- data/test/controllers/controller_test_base.rb +0 -33
- data/test/controllers/test_delivery_reports_controller.rb +0 -164
- data/test/controllers/test_messages_controller.rb +0 -166
- data/test/controllers/test_replies_controller.rb +0 -164
- data/test/http_response_catcher.rb +0 -16
- data/test/test_helper.rb +0 -79
@@ -1,27 +1,29 @@
|
|
1
|
-
#
|
1
|
+
# message_media_messages
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
2
4
|
# ( https://apimatic.io ).
|
3
5
|
|
4
6
|
module MessageMediaMessages
|
5
|
-
|
6
|
-
Logging.logger.root.appenders = Logging.appenders.stdout
|
7
|
-
Logging.logger.root.level = :info
|
8
|
-
|
9
7
|
# All configuration including auth info and base URI for the API access
|
10
8
|
# are configured in this class.
|
11
9
|
class Configuration
|
12
10
|
# The base Uri for API calls
|
13
|
-
@base_uri = '
|
11
|
+
@base_uri = 'https://api.messagemedia.com'
|
14
12
|
|
15
13
|
# The username to use with basic authentication
|
14
|
+
# TODO: Set an appropriate value
|
16
15
|
@basic_auth_user_name = 'TODO: Replace'
|
17
16
|
|
18
17
|
# The password to use with basic authentication
|
18
|
+
# TODO: Set an appropriate value
|
19
19
|
@basic_auth_password = 'TODO: Replace'
|
20
20
|
|
21
21
|
# The username to use with HMAC authentication
|
22
|
+
# TODO: Set an appropriate value
|
22
23
|
@hmac_auth_user_name = nil
|
23
24
|
|
24
25
|
# The password to use with HMAC authentication
|
26
|
+
# TODO: Set an appropriate value
|
25
27
|
@hmac_auth_password = nil
|
26
28
|
|
27
29
|
# The attribute accessors for public properties.
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# message_media_messages
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
2
4
|
# ( https://apimatic.io ).
|
3
5
|
|
4
|
-
require 'message_media_messages/configuration.rb'
|
5
|
-
|
6
6
|
module MessageMediaMessages
|
7
7
|
# Base controller.
|
8
8
|
class BaseController
|
@@ -13,11 +13,8 @@ module MessageMediaMessages
|
|
13
13
|
@http_call_back = http_call_back
|
14
14
|
|
15
15
|
@global_headers = {
|
16
|
-
'user-agent' => 'messagemedia-messages
|
16
|
+
'user-agent' => 'messagemedia-messages'
|
17
17
|
}
|
18
|
-
|
19
|
-
@logger = Logging.logger[self]
|
20
|
-
@logger.info("Instantiated controller class.")
|
21
18
|
end
|
22
19
|
|
23
20
|
def validate_parameters(args)
|
@@ -28,46 +25,33 @@ module MessageMediaMessages
|
|
28
25
|
end
|
29
26
|
end
|
30
27
|
|
31
|
-
def
|
32
|
-
if Configuration.hmac_auth_user_name == nil or Configuration.hmac_auth_password == nil
|
33
|
-
BasicAuth.apply(request)
|
34
|
-
else
|
35
|
-
HmacAuth.apply(request, url, body)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def execute_request(request, binary: false, name: nil)
|
40
|
-
@logger.info("Calling the on_before_request method of http_call_back for #{name}.") if @http_call_back
|
28
|
+
def execute_request(request, binary: false)
|
41
29
|
@http_call_back.on_before_request(request) if @http_call_back
|
42
30
|
|
43
|
-
@logger.info("Merging global headers with endpoint headers for #{name}.")
|
44
31
|
APIHelper.clean_hash(request.headers)
|
45
32
|
request.headers = @global_headers.clone.merge(request.headers)
|
46
33
|
|
47
|
-
@logger.debug("Raw request for #{name} is: #{request.inspect}")
|
48
34
|
response = if binary
|
49
35
|
@http_client.execute_as_binary(request)
|
50
36
|
else
|
51
37
|
@http_client.execute_as_string(request)
|
52
38
|
end
|
53
|
-
@logger.debug("Raw response for #{name} is: #{response.inspect}")
|
54
|
-
@logger.info("Wrapping request and response in a context object for #{name}.")
|
55
39
|
context = HttpContext.new(request, response)
|
56
40
|
|
57
|
-
@logger.info("Calling on_after_response method of http_call_back for #{name}.") if @http_call_back
|
58
41
|
@http_call_back.on_after_response(context) if @http_call_back
|
59
42
|
|
60
43
|
context
|
61
44
|
end
|
62
45
|
|
63
|
-
def add_account_header(headers, account_header_value)
|
64
|
-
if headers != nil && account_header_value != nil
|
65
|
-
headers["account"] = account_header_value
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
46
|
def validate_response(context)
|
70
|
-
|
47
|
+
if context.response.status_code == 400
|
48
|
+
raise APIException.new('Request was invalid',
|
49
|
+
context)
|
50
|
+
elsif context.response.status_code == 404
|
51
|
+
raise APIException.new('Message not found',
|
52
|
+
context)
|
53
|
+
end
|
54
|
+
raise APIException.new 'HTTP Response Not OK', context unless
|
71
55
|
context.response.status_code.between?(200, 208) # [200,208] = HTTP OK
|
72
56
|
end
|
73
57
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# message_media_messages
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
2
4
|
# ( https://apimatic.io ).
|
3
5
|
|
4
6
|
module MessageMediaMessages
|
5
7
|
# DeliveryReportsController
|
6
|
-
# noinspection RubyResolve,RubyInstanceMethodNamingConvention,RubyStringKeysInHashInspection
|
7
8
|
class DeliveryReportsController < BaseController
|
8
9
|
@instance = DeliveryReportsController.new
|
9
10
|
|
@@ -95,48 +96,31 @@ module MessageMediaMessages
|
|
95
96
|
# *Note: It is recommended to use the Webhooks feature to receive reply
|
96
97
|
# messages rather than
|
97
98
|
# polling the check delivery reports endpoint.*
|
98
|
-
# @param [Object] account_header_value The account id to pass to the API
|
99
99
|
# @return CheckDeliveryReportsResponse response from the API call
|
100
|
-
def
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
)
|
125
|
-
|
126
|
-
apply_authentication(request, request_url)
|
127
|
-
|
128
|
-
context = execute_request(request, name: 'get_check_delivery_reports')
|
129
|
-
validate_response(context)
|
130
|
-
|
131
|
-
# Return appropriate response type.
|
132
|
-
@logger.info("Returning response for get_check_delivery_reports.")
|
133
|
-
decoded = APIHelper.json_deserialize(context.response.raw_body)
|
134
|
-
CheckDeliveryReportsResponse.from_hash(decoded)
|
135
|
-
|
136
|
-
rescue Exception => e
|
137
|
-
@logger.error(e)
|
138
|
-
raise e
|
139
|
-
end
|
100
|
+
def check_delivery_reports
|
101
|
+
# Prepare query url.
|
102
|
+
_path_url = '/v1/delivery_reports'
|
103
|
+
_query_builder = Configuration.base_uri.dup
|
104
|
+
_query_builder << _path_url
|
105
|
+
_query_url = APIHelper.clean_url _query_builder
|
106
|
+
|
107
|
+
# Prepare headers.
|
108
|
+
_headers = {
|
109
|
+
'accept' => 'application/json'
|
110
|
+
}
|
111
|
+
|
112
|
+
# Prepare and execute HttpRequest.
|
113
|
+
_request = @http_client.get(
|
114
|
+
_query_url,
|
115
|
+
headers: _headers
|
116
|
+
)
|
117
|
+
AuthManager.apply(_request, _path_url)
|
118
|
+
_context = execute_request(_request)
|
119
|
+
validate_response(_context)
|
120
|
+
|
121
|
+
# Return appropriate response type.
|
122
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
123
|
+
CheckDeliveryReportsResponse.from_hash(decoded)
|
140
124
|
end
|
141
125
|
|
142
126
|
# Mark a delivery report as confirmed so it is no longer return in check
|
@@ -163,64 +147,35 @@ module MessageMediaMessages
|
|
163
147
|
# reports request.
|
164
148
|
# @param [ConfirmDeliveryReportsAsReceivedRequest] body Required parameter:
|
165
149
|
# Example:
|
166
|
-
# @param [Object] account_header_value The account id to pass to the API
|
167
150
|
# @return Mixed response from the API call
|
168
|
-
def
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
parameters: json_body
|
197
|
-
)
|
198
|
-
|
199
|
-
apply_authentication(request, request_url, json_body)
|
200
|
-
|
201
|
-
context = execute_request(request, name: 'create_confirm_delivery_reports_as_received')
|
202
|
-
|
203
|
-
# Validate response against endpoint and global error codes.
|
204
|
-
@logger.info("Validating response for create_confirm_delivery_reports_as_received.")
|
205
|
-
if context.response.status_code == 400
|
206
|
-
raise APIException.new(
|
207
|
-
'',
|
208
|
-
context
|
209
|
-
)
|
210
|
-
end
|
211
|
-
|
212
|
-
validate_response(context)
|
213
|
-
|
214
|
-
# Return appropriate response type.
|
215
|
-
@logger.info("Returning response for create_confirm_delivery_reports_as_received.")
|
216
|
-
return APIHelper.json_deserialize(context.response.raw_body) unless
|
217
|
-
context.response.raw_body.nil? ||
|
218
|
-
context.response.raw_body.to_s.strip.empty?
|
219
|
-
|
220
|
-
rescue Exception => e
|
221
|
-
@logger.error(e)
|
222
|
-
raise e
|
223
|
-
end
|
151
|
+
def confirm_delivery_reports_as_received(body)
|
152
|
+
# Prepare query url.
|
153
|
+
_path_url = '/v1/delivery_reports/confirmed'
|
154
|
+
_query_builder = Configuration.base_uri.dup
|
155
|
+
_query_builder << _path_url
|
156
|
+
_query_url = APIHelper.clean_url _query_builder
|
157
|
+
|
158
|
+
# Prepare headers.
|
159
|
+
_headers = {
|
160
|
+
'accept' => 'application/json',
|
161
|
+
'content-type' => 'application/json; charset=utf-8'
|
162
|
+
}
|
163
|
+
|
164
|
+
# Prepare and execute HttpRequest.
|
165
|
+
_request = @http_client.post(
|
166
|
+
_query_url,
|
167
|
+
headers: _headers,
|
168
|
+
parameters: body.to_json
|
169
|
+
)
|
170
|
+
AuthManager.apply(_request, _path_url, body.to_json)
|
171
|
+
_context = execute_request(_request)
|
172
|
+
validate_response(_context)
|
173
|
+
|
174
|
+
# Return appropriate response type.
|
175
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body) unless
|
176
|
+
_context.response.raw_body.nil? ||
|
177
|
+
_context.response.raw_body.to_s.strip.empty?
|
178
|
+
decoded
|
224
179
|
end
|
225
180
|
end
|
226
181
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# message_media_messages
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
2
4
|
# ( https://apimatic.io ).
|
3
5
|
|
4
6
|
module MessageMediaMessages
|
5
7
|
# MessagesController
|
6
|
-
# noinspection RubyResolve,RubyInstanceMethodNamingConvention,RubyStringKeysInHashInspection
|
7
8
|
class MessagesController < BaseController
|
8
9
|
@instance = MessagesController.new
|
9
10
|
|
@@ -15,97 +16,6 @@ module MessageMediaMessages
|
|
15
16
|
self.class.instance
|
16
17
|
end
|
17
18
|
|
18
|
-
# Cancel a scheduled message that has not yet been delivered.
|
19
|
-
# A scheduled message can be cancelled by updating the status of a message
|
20
|
-
# from ```scheduled```
|
21
|
-
# to ```cancelled```. This is done by submitting a PUT request to the
|
22
|
-
# messages endpoint using
|
23
|
-
# the message ID as a parameter (the same endpoint used above to retrieve
|
24
|
-
# the status of a message).
|
25
|
-
# The body of the request simply needs to contain a ```status``` property
|
26
|
-
# with the value set
|
27
|
-
# to ```cancelled```.
|
28
|
-
# ```json
|
29
|
-
# {
|
30
|
-
# "status": "cancelled"
|
31
|
-
# }
|
32
|
-
# ```
|
33
|
-
# *Note: Only messages with a status of scheduled can be cancelled. If an
|
34
|
-
# invalid or non existent
|
35
|
-
# message ID parameter is specified in the request, then a HTTP 404 Not
|
36
|
-
# Found response will be
|
37
|
-
# returned*
|
38
|
-
# @param [String] message_id Required parameter: Example:
|
39
|
-
# @param [CancelScheduledMessageRequest] body Required parameter: Example:
|
40
|
-
# @param [Object] account_header_value The account id to pass to the API
|
41
|
-
# @return Mixed response from the API call
|
42
|
-
def update_cancel_scheduled_message(message_id, body, account_header_value=nil)
|
43
|
-
begin
|
44
|
-
@logger.info("update_cancel_scheduled_message called.")
|
45
|
-
|
46
|
-
request_url = '/v1/messages/{messageId}'
|
47
|
-
request_url = APIHelper.append_url_with_template_parameters(
|
48
|
-
request_url,
|
49
|
-
'messageId' => message_id
|
50
|
-
)
|
51
|
-
|
52
|
-
# Prepare query url.
|
53
|
-
@logger.info("Preparing query URL for update_cancel_scheduled_message.")
|
54
|
-
query_builder = Configuration.base_uri.dup
|
55
|
-
query_builder << request_url
|
56
|
-
query_url = APIHelper.clean_url query_builder
|
57
|
-
|
58
|
-
# Prepare headers.
|
59
|
-
@logger.info("Preparing headers for update_cancel_scheduled_message.")
|
60
|
-
headers = {
|
61
|
-
'accept' => 'application/json',
|
62
|
-
'content-type' => 'application/json; charset=utf-8'
|
63
|
-
}
|
64
|
-
|
65
|
-
add_account_header(headers, account_header_value)
|
66
|
-
|
67
|
-
json_body = body.to_json
|
68
|
-
|
69
|
-
# Prepare and execute HttpRequest.
|
70
|
-
@logger.info('Preparing and executing HttpRequest for update_cancel_scheduled_message.')
|
71
|
-
request = @http_client.put(
|
72
|
-
query_url,
|
73
|
-
headers: headers,
|
74
|
-
parameters: json_body
|
75
|
-
)
|
76
|
-
|
77
|
-
apply_authentication(request, request_url, json_body)
|
78
|
-
|
79
|
-
context = execute_request(request, name: 'update_cancel_scheduled_message')
|
80
|
-
|
81
|
-
# Validate response against endpoint and global error codes.
|
82
|
-
@logger.info("Validating response for update_cancel_scheduled_message.")
|
83
|
-
if context.response.status_code == 400
|
84
|
-
raise APIException.new(
|
85
|
-
'',
|
86
|
-
context
|
87
|
-
)
|
88
|
-
elsif context.response.status_code == 404
|
89
|
-
raise APIException.new(
|
90
|
-
'',
|
91
|
-
context
|
92
|
-
)
|
93
|
-
end
|
94
|
-
validate_response(context)
|
95
|
-
|
96
|
-
# Return appropriate response type.
|
97
|
-
@logger.info("Returning response for update_cancel_scheduled_message.")
|
98
|
-
decoded = APIHelper.json_deserialize(context.response.raw_body) unless
|
99
|
-
context.response.raw_body.nil? ||
|
100
|
-
context.response.raw_body.to_s.strip.empty?
|
101
|
-
decoded
|
102
|
-
|
103
|
-
rescue Exception => e
|
104
|
-
@logger.error(e)
|
105
|
-
raise e
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
19
|
# Retrieve the current status of a message using the message ID returned in
|
110
20
|
# the send messages end point.
|
111
21
|
# A successful request to the get message status endpoint will return a
|
@@ -124,7 +34,7 @@ module MessageMediaMessages
|
|
124
34
|
# "destination_number": "+61401760575",
|
125
35
|
# "scheduled": "2016-11-03T11:49:02.807Z",
|
126
36
|
# "source_number": "+61491570157",
|
127
|
-
# "source_number_type": "INTERNATIONAL"
|
37
|
+
# "source_number_type": "INTERNATIONAL",
|
128
38
|
# "message_expiry_timestamp": "2016-11-03T11:49:02.807Z",
|
129
39
|
# "status": "enroute"
|
130
40
|
# }
|
@@ -137,68 +47,47 @@ module MessageMediaMessages
|
|
137
47
|
# the request, then
|
138
48
|
# a HTTP 404 Not Found response will be returned*
|
139
49
|
# @param [String] message_id Required parameter: Example:
|
140
|
-
# @
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
50
|
+
# @return GetMessageStatusResponse response from the API call
|
51
|
+
def get_message_status(message_id)
|
52
|
+
# Prepare query url.
|
53
|
+
_path_url = '/v1/messages/{messageId}'
|
54
|
+
_path_url = APIHelper.append_url_with_template_parameters(
|
55
|
+
_path_url,
|
56
|
+
'messageId' => message_id
|
57
|
+
)
|
58
|
+
_query_builder = Configuration.base_uri.dup
|
59
|
+
_query_builder << _path_url
|
60
|
+
_query_url = APIHelper.clean_url _query_builder
|
145
61
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
)
|
62
|
+
# Prepare headers.
|
63
|
+
_headers = {
|
64
|
+
'accept' => 'application/json'
|
65
|
+
}
|
151
66
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
@logger.info("Preparing headers for get_message_status.")
|
160
|
-
headers = {
|
161
|
-
'accept' => 'application/json'
|
162
|
-
}
|
67
|
+
# Prepare and execute HttpRequest.
|
68
|
+
_request = @http_client.get(
|
69
|
+
_query_url,
|
70
|
+
headers: _headers
|
71
|
+
)
|
72
|
+
AuthManager.apply(_request, _path_url)
|
73
|
+
_context = execute_request(_request)
|
163
74
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
query_url,
|
170
|
-
headers: headers
|
75
|
+
# Validate response against endpoint and global error codes.
|
76
|
+
if _context.response.status_code == 404
|
77
|
+
raise APIException.new(
|
78
|
+
'Resource not found',
|
79
|
+
_context
|
171
80
|
)
|
172
|
-
|
173
|
-
apply_authentication(request, request_url)
|
174
|
-
|
175
|
-
context = execute_request(request, name: 'get_message_status')
|
176
|
-
|
177
|
-
# Validate response against endpoint and global error codes.
|
178
|
-
@logger.info("Validating response for get_message_status.")
|
179
|
-
if context.response.status_code == 404
|
180
|
-
raise APIException.new(
|
181
|
-
'',
|
182
|
-
context
|
183
|
-
)
|
184
|
-
end
|
185
|
-
validate_response(context)
|
186
|
-
|
187
|
-
# Return appropriate response type.
|
188
|
-
@logger.info("Returning response for get_message_status.")
|
189
|
-
decoded = APIHelper.json_deserialize(context.response.raw_body) unless
|
190
|
-
context.response.raw_body.nil? ||
|
191
|
-
context.response.raw_body.to_s.strip.empty?
|
192
|
-
decoded
|
193
|
-
|
194
|
-
rescue Exception => e
|
195
|
-
@logger.error(e)
|
196
|
-
raise e
|
197
81
|
end
|
82
|
+
validate_response(_context)
|
83
|
+
|
84
|
+
# Return appropriate response type.
|
85
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
86
|
+
GetMessageStatusResponse.from_hash(decoded)
|
198
87
|
end
|
199
88
|
|
200
|
-
# Submit one or more (up to 100 per request) SMS or text to voice
|
201
|
-
# for delivery.
|
89
|
+
# Submit one or more (up to 100 per request) SMS, MMS or text to voice
|
90
|
+
# messages for delivery.
|
202
91
|
# The most basic message has the following structure:
|
203
92
|
# ```json
|
204
93
|
# {
|
@@ -238,7 +127,7 @@ module MessageMediaMessages
|
|
238
127
|
# http://en.wikipedia.org/wiki/E.164.
|
239
128
|
# A destination number is required.
|
240
129
|
# - ```format``` The format specifies which format the message will be sent
|
241
|
-
# as, ```SMS``` (text message)
|
130
|
+
# as, ```SMS``` (text message), ```MMS``` (multimedia message)
|
242
131
|
# or ```TTS``` (text to speech). With ```TTS``` format, we will call the
|
243
132
|
# destination number and read out the
|
244
133
|
# message using a computer generated voice. Specifying a format is
|
@@ -247,10 +136,16 @@ module MessageMediaMessages
|
|
247
136
|
# this will be the number that
|
248
137
|
# the message appears from on the handset. By default this feature is
|
249
138
|
# _not_ available and will be ignored
|
250
|
-
# in the request. Please contact <support@
|
139
|
+
# in the request. Please contact <support@messagemedia.com> for more
|
251
140
|
# information. Specifying a source
|
252
141
|
# number is optional and a by default a source number will be assigned to
|
253
142
|
# the message.
|
143
|
+
# - ```media``` The media is used to specify the url of the media file that
|
144
|
+
# you are trying to send. Supported file formats include png, jpeg and gif.
|
145
|
+
# ```format``` parameter must be set to ```MMS``` for this to work.
|
146
|
+
# - ```subject``` The subject field is used to denote subject of the MMS
|
147
|
+
# message and has a maximum size of 64 characters long. Specifying a subject
|
148
|
+
# is optional.
|
254
149
|
# - ```source_number_type``` If a source number is specified, the type of
|
255
150
|
# source number may also be
|
256
151
|
# specified. This is recommended when using a source address type that is
|
@@ -303,61 +198,129 @@ module MessageMediaMessages
|
|
303
198
|
# valid for the request to be successful.
|
304
199
|
# If any messages in the request are invalid, no messages will be sent.*
|
305
200
|
# @param [SendMessagesRequest] body Required parameter: Example:
|
306
|
-
# @param [Object] account_header_value The account id to pass to the API
|
307
201
|
# @return SendMessagesResponse response from the API call
|
308
|
-
def
|
309
|
-
|
310
|
-
|
202
|
+
def send_messages(body)
|
203
|
+
# Prepare query url.
|
204
|
+
_path_url = '/v1/messages'
|
205
|
+
_query_builder = Configuration.base_uri.dup
|
206
|
+
_query_builder << _path_url
|
207
|
+
_query_url = APIHelper.clean_url _query_builder
|
311
208
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
query_url = APIHelper.clean_url query_builder
|
318
|
-
|
319
|
-
# Prepare headers.
|
320
|
-
@logger.info("Preparing headers for create_send_messages.")
|
321
|
-
headers = {
|
322
|
-
'accept' => 'application/json',
|
323
|
-
'content-type' => 'application/json; charset=utf-8'
|
324
|
-
}
|
209
|
+
# Prepare headers.
|
210
|
+
_headers = {
|
211
|
+
'accept' => 'application/json',
|
212
|
+
'content-type' => 'application/json; charset=utf-8'
|
213
|
+
}
|
325
214
|
|
326
|
-
|
215
|
+
# Prepare and execute HttpRequest.
|
216
|
+
_request = @http_client.post(
|
217
|
+
_query_url,
|
218
|
+
headers: _headers,
|
219
|
+
parameters: body.to_json
|
220
|
+
)
|
221
|
+
AuthManager.apply(_request, _path_url, body.to_json)
|
222
|
+
_context = execute_request(_request)
|
327
223
|
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
query_url,
|
334
|
-
headers: headers,
|
335
|
-
parameters: json_body
|
224
|
+
# Validate response against endpoint and global error codes.
|
225
|
+
if _context.response.status_code == 400
|
226
|
+
raise SendMessages400ResponseException.new(
|
227
|
+
'Unexpected error in API call. See HTTP response body for details.',
|
228
|
+
_context
|
336
229
|
)
|
230
|
+
end
|
231
|
+
validate_response(_context)
|
232
|
+
|
233
|
+
# Return appropriate response type.
|
234
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body)
|
235
|
+
SendMessagesResponse.from_hash(decoded)
|
236
|
+
end
|
237
|
+
|
238
|
+
# Cancel a scheduled message that has not yet been delivered.
|
239
|
+
# A scheduled message can be cancelled by updating the status of a message
|
240
|
+
# from ```scheduled```
|
241
|
+
# to ```cancelled```. This is done by submitting a PUT request to the
|
242
|
+
# messages endpoint using
|
243
|
+
# the message ID as a parameter (the same endpoint used above to retrieve
|
244
|
+
# the status of a message).
|
245
|
+
# The body of the request simply needs to contain a ```status``` property
|
246
|
+
# with the value set
|
247
|
+
# to ```cancelled```.
|
248
|
+
# ```json
|
249
|
+
# {
|
250
|
+
# "status": "cancelled"
|
251
|
+
# }
|
252
|
+
# ```
|
253
|
+
# *Note: Only messages with a status of scheduled can be cancelled. If an
|
254
|
+
# invalid or non existent
|
255
|
+
# message ID parameter is specified in the request, then a HTTP 404 Not
|
256
|
+
# Found response will be
|
257
|
+
# returned*
|
258
|
+
# @param [String] message_id Required parameter: Example:
|
259
|
+
# @param [CancelScheduledMessageRequest] body Required parameter: Example:
|
260
|
+
# @return Mixed response from the API call
|
261
|
+
def cancel_scheduled_message(message_id,
|
262
|
+
body)
|
263
|
+
# Prepare query url.
|
264
|
+
_path_url = '/v1/messages/{messageId}'
|
265
|
+
_path_url = APIHelper.append_url_with_template_parameters(
|
266
|
+
_path_url,
|
267
|
+
'messageId' => message_id
|
268
|
+
)
|
269
|
+
_query_builder = Configuration.base_uri.dup
|
270
|
+
_query_builder << _path_url
|
271
|
+
_query_url = APIHelper.clean_url _query_builder
|
337
272
|
|
338
|
-
|
273
|
+
# Prepare headers.
|
274
|
+
_headers = {
|
275
|
+
'accept' => 'application/json',
|
276
|
+
'content-type' => 'application/json; charset=utf-8'
|
277
|
+
}
|
339
278
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
end
|
350
|
-
validate_response(context)
|
351
|
-
|
352
|
-
# Return appropriate response type.
|
353
|
-
@logger.info("Returning response for create_send_messages.")
|
354
|
-
decoded = APIHelper.json_deserialize(context.response.raw_body)
|
355
|
-
SendMessagesResponse.from_hash(decoded)
|
279
|
+
# Prepare and execute HttpRequest.
|
280
|
+
_request = @http_client.put(
|
281
|
+
_query_url,
|
282
|
+
headers: _headers,
|
283
|
+
parameters: body.to_json
|
284
|
+
)
|
285
|
+
AuthManager.apply(_request, _path_url, body.to_json)
|
286
|
+
_context = execute_request(_request)
|
287
|
+
validate_response(_context)
|
356
288
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
289
|
+
# Return appropriate response type.
|
290
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body) unless
|
291
|
+
_context.response.raw_body.nil? ||
|
292
|
+
_context.response.raw_body.to_s.strip.empty?
|
293
|
+
decoded
|
294
|
+
end
|
295
|
+
|
296
|
+
# TODO: type endpoint description here
|
297
|
+
# @return Mixed response from the API call
|
298
|
+
def check_credits_remaining
|
299
|
+
# Prepare query url.
|
300
|
+
_path_url = '/v1/messaging/credits'
|
301
|
+
_query_builder = Configuration.base_uri.dup
|
302
|
+
_query_builder << _path_url
|
303
|
+
_query_url = APIHelper.clean_url _query_builder
|
304
|
+
|
305
|
+
# Prepare headers.
|
306
|
+
_headers = {
|
307
|
+
'accept' => 'application/json'
|
308
|
+
}
|
309
|
+
|
310
|
+
# Prepare and execute HttpRequest.
|
311
|
+
_request = @http_client.get(
|
312
|
+
_query_url,
|
313
|
+
headers: _headers
|
314
|
+
)
|
315
|
+
AuthManager.apply(_request, _path_url)
|
316
|
+
_context = execute_request(_request)
|
317
|
+
validate_response(_context)
|
318
|
+
|
319
|
+
# Return appropriate response type.
|
320
|
+
decoded = APIHelper.json_deserialize(_context.response.raw_body) unless
|
321
|
+
_context.response.raw_body.nil? ||
|
322
|
+
_context.response.raw_body.to_s.strip.empty?
|
323
|
+
decoded
|
361
324
|
end
|
362
325
|
end
|
363
|
-
end
|
326
|
+
end
|