messagemedia_messages_sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/README.md +608 -0
  4. data/lib/message_media_messages.rb +50 -0
  5. data/lib/message_media_messages/api_helper.rb +209 -0
  6. data/lib/message_media_messages/configuration.rb +29 -0
  7. data/lib/message_media_messages/controllers/base_controller.rb +57 -0
  8. data/lib/message_media_messages/controllers/delivery_reports_controller.rb +208 -0
  9. data/lib/message_media_messages/controllers/messages_controller.rb +336 -0
  10. data/lib/message_media_messages/controllers/replies_controller.rb +208 -0
  11. data/lib/message_media_messages/exceptions/api_exception.rb +18 -0
  12. data/lib/message_media_messages/http/auth/basic_auth.rb +20 -0
  13. data/lib/message_media_messages/http/faraday_client.rb +55 -0
  14. data/lib/message_media_messages/http/http_call_back.rb +22 -0
  15. data/lib/message_media_messages/http/http_client.rb +92 -0
  16. data/lib/message_media_messages/http/http_context.rb +18 -0
  17. data/lib/message_media_messages/http/http_method_enum.rb +11 -0
  18. data/lib/message_media_messages/http/http_request.rb +48 -0
  19. data/lib/message_media_messages/http/http_response.rb +21 -0
  20. data/lib/message_media_messages/message_media_messages_client.rb +39 -0
  21. data/lib/message_media_messages/models/base_model.rb +34 -0
  22. data/lib/message_media_messages/models/cancel_scheduled_message_request.rb +35 -0
  23. data/lib/message_media_messages/models/check_delivery_reports_response.rb +35 -0
  24. data/lib/message_media_messages/models/check_replies_response.rb +35 -0
  25. data/lib/message_media_messages/models/confirm_delivery_reports_as_received_request.rb +35 -0
  26. data/lib/message_media_messages/models/confirm_delivery_reports_as_received_request_11.rb +35 -0
  27. data/lib/message_media_messages/models/confirm_replies_as_received_request.rb +35 -0
  28. data/lib/message_media_messages/models/confirm_replies_as_received_request_8.rb +35 -0
  29. data/lib/message_media_messages/models/send_messages_request.rb +35 -0
  30. data/lib/message_media_messages/models/send_messages_response.rb +35 -0
  31. data/test/controllers/controller_test_base.rb +30 -0
  32. data/test/controllers/test_delivery_reports_controller.rb +131 -0
  33. data/test/controllers/test_messages_controller.rb +105 -0
  34. data/test/controllers/test_replies_controller.rb +132 -0
  35. data/test/http_response_catcher.rb +16 -0
  36. data/test/test_helper.rb +91 -0
  37. metadata +168 -0
@@ -0,0 +1,336 @@
1
+ # This file was automatically generated for MessageMedia by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module MessageMediaMessages
5
+ # MessagesController
6
+ class MessagesController < BaseController
7
+ @instance = MessagesController.new
8
+
9
+ class << self
10
+ attr_accessor :instance
11
+ end
12
+
13
+ def instance
14
+ self.class.instance
15
+ end
16
+
17
+ # Cancel a scheduled message that has not yet been delivered.
18
+ # A scheduled message can be cancelled by updating the status of a message
19
+ # from ```scheduled```
20
+ # to ```cancelled```. This is done by submitting a PUT request to the
21
+ # messages endpoint using
22
+ # the message ID as a parameter (the same endpoint used above to retrieve
23
+ # the status of a message).
24
+ # The body of the request simply needs to contain a ```status``` property
25
+ # with the value set
26
+ # to ```cancelled```.
27
+ # ```json
28
+ # {
29
+ # "status": "cancelled"
30
+ # }
31
+ # ```
32
+ # *Note: Only messages with a status of scheduled can be cancelled. If an
33
+ # invalid or non existent
34
+ # message ID parameter is specified in the request, then a HTTP 404 Not
35
+ # Found response will be
36
+ # returned*
37
+ # @param [String] message_id Required parameter: Example:
38
+ # @param [CancelScheduledMessageRequest] body Required parameter: Example:
39
+ # @return Mixed response from the API call
40
+ def update_cancel_scheduled_message(message_id,
41
+ body)
42
+ begin
43
+ @logger.info("update_cancel_scheduled_message called.")
44
+ # Prepare query url.
45
+ @logger.info("Preparing query URL for update_cancel_scheduled_message.")
46
+ _query_builder = Configuration.base_uri.dup
47
+ _query_builder << '/v1/messages/{messageId}'
48
+ _query_builder = APIHelper.append_url_with_template_parameters(
49
+ _query_builder,
50
+ 'messageId' => message_id
51
+ )
52
+ _query_url = APIHelper.clean_url _query_builder
53
+
54
+ # Prepare headers.
55
+ @logger.info("Preparing headers for update_cancel_scheduled_message.")
56
+ _headers = {
57
+ 'accept' => 'application/json',
58
+ 'content-type' => 'application/json; charset=utf-8'
59
+ }
60
+
61
+ # Prepare and execute HttpRequest.
62
+ @logger.info('Preparing and executing HttpRequest for update_cancel_scheduled_message.')
63
+ _request = @http_client.put(
64
+ _query_url,
65
+ headers: _headers,
66
+ parameters: body.to_json
67
+ )
68
+ BasicAuth.apply(_request)
69
+ _context = execute_request(_request, name: 'update_cancel_scheduled_message')
70
+
71
+ # Validate response against endpoint and global error codes.
72
+ @logger.info("Validating response for update_cancel_scheduled_message.")
73
+ if _context.response.status_code == 400
74
+ raise APIException.new(
75
+ '',
76
+ _context
77
+ )
78
+ elsif _context.response.status_code == 404
79
+ raise APIException.new(
80
+ '',
81
+ _context
82
+ )
83
+ end
84
+ validate_response(_context)
85
+
86
+ # Return appropriate response type.
87
+ @logger.info("Returning response for update_cancel_scheduled_message.")
88
+ decoded = APIHelper.json_deserialize(_context.response.raw_body) unless
89
+ _context.response.raw_body.nil? ||
90
+ _context.response.raw_body.to_s.strip.empty?
91
+ decoded
92
+
93
+ rescue Exception => e
94
+ @logger.error(e)
95
+ raise e
96
+ end
97
+ end
98
+
99
+ # Retrieve the current status of a message using the message ID returned in
100
+ # the send messages end point.
101
+ # A successful request to the get message status endpoint will return a
102
+ # response body as follows:
103
+ # ```json
104
+ # {
105
+ # "format": "SMS",
106
+ # "content": "My first message!",
107
+ # "metadata": {
108
+ # "key1": "value1",
109
+ # "key2": "value2"
110
+ # },
111
+ # "message_id": "877c19ef-fa2e-4cec-827a-e1df9b5509f7",
112
+ # "callback_url": "https://my.callback.url.com",
113
+ # "delivery_report": true,
114
+ # "destination_number": "+61401760575",
115
+ # "scheduled": "2016-11-03T11:49:02.807Z",
116
+ # "source_number": "+61491570157",
117
+ # "source_number_type": "INTERNATIONAL"
118
+ # "message_expiry_timestamp": "2016-11-03T11:49:02.807Z",
119
+ # "status": "enroute"
120
+ # }
121
+ # ```
122
+ # The status property of the response indicates the current status of the
123
+ # message. See the Delivery
124
+ # Reports section of this documentation for more information on message
125
+ # statues.
126
+ # *Note: If an invalid or non existent message ID parameter is specified in
127
+ # the request, then
128
+ # a HTTP 404 Not Found response will be returned*
129
+ # @param [String] message_id Required parameter: Example:
130
+ # @return Mixed response from the API call
131
+ def get_message_status(message_id)
132
+ begin
133
+ @logger.info("get_message_status called.")
134
+ # Prepare query url.
135
+ @logger.info("Preparing query URL for get_message_status.")
136
+ _query_builder = Configuration.base_uri.dup
137
+ _query_builder << '/v1/messages/{messageId}'
138
+ _query_builder = APIHelper.append_url_with_template_parameters(
139
+ _query_builder,
140
+ 'messageId' => message_id
141
+ )
142
+ _query_url = APIHelper.clean_url _query_builder
143
+
144
+ # Prepare headers.
145
+ @logger.info("Preparing headers for get_message_status.")
146
+ _headers = {
147
+ 'accept' => 'application/json'
148
+ }
149
+
150
+ # Prepare and execute HttpRequest.
151
+ @logger.info('Preparing and executing HttpRequest for get_message_status.')
152
+ _request = @http_client.get(
153
+ _query_url,
154
+ headers: _headers
155
+ )
156
+ BasicAuth.apply(_request)
157
+ _context = execute_request(_request, name: 'get_message_status')
158
+
159
+ # Validate response against endpoint and global error codes.
160
+ @logger.info("Validating response for get_message_status.")
161
+ if _context.response.status_code == 404
162
+ raise APIException.new(
163
+ '',
164
+ _context
165
+ )
166
+ end
167
+ validate_response(_context)
168
+
169
+ # Return appropriate response type.
170
+ @logger.info("Returning response for get_message_status.")
171
+ decoded = APIHelper.json_deserialize(_context.response.raw_body) unless
172
+ _context.response.raw_body.nil? ||
173
+ _context.response.raw_body.to_s.strip.empty?
174
+ decoded
175
+
176
+ rescue Exception => e
177
+ @logger.error(e)
178
+ raise e
179
+ end
180
+ end
181
+
182
+ # Submit one or more (up to 100 per request) SMS or text to voice messages
183
+ # for delivery.
184
+ # The most basic message has the following structure:
185
+ # ```json
186
+ # {
187
+ # "messages": [
188
+ # {
189
+ # "content": "My first message!",
190
+ # "destination_number": "+61491570156"
191
+ # }
192
+ # ]
193
+ # }
194
+ # ```
195
+ # More advanced delivery features can be specified by setting the following
196
+ # properties in a message:
197
+ # - ```callback_url``` A URL can be included with each message to which
198
+ # Webhooks will be pushed to
199
+ # via a HTTP POST request. Webhooks will be sent if and when the status of
200
+ # the message changes as
201
+ # it is processed (if the delivery report property of the request is set
202
+ # to ```true```) and when replies
203
+ # are received. Specifying a callback URL is optional.
204
+ # - ```content``` The content of the message. This can be a Unicode string,
205
+ # up to 5,000 characters long.
206
+ # Message content is required.
207
+ # - ```delivery_report``` Delivery reports can be requested with each
208
+ # message. If delivery reports are requested, a webhook
209
+ # will be submitted to the ```callback_url``` property specified for the
210
+ # message (or to the webhooks)
211
+ # specified for the account every time the status of the message changes
212
+ # as it is processed. The
213
+ # current status of the message can also be retrieved via the Delivery
214
+ # Reports endpoint of the
215
+ # Messages API. Delivery reports are optional and by default will not be
216
+ # requested.
217
+ # - ```destination_number``` The destination number the message should be
218
+ # delivered to. This should be specified in E.164
219
+ # international format. For information on E.164, please refer to
220
+ # http://en.wikipedia.org/wiki/E.164.
221
+ # A destination number is required.
222
+ # - ```format``` The format specifies which format the message will be sent
223
+ # as, ```SMS``` (text message)
224
+ # or ```TTS``` (text to speech). With ```TTS``` format, we will call the
225
+ # destination number and read out the
226
+ # message using a computer generated voice. Specifying a format is
227
+ # optional, by default ```SMS``` will be used.
228
+ # - ```source_number``` A source number may be specified for the message,
229
+ # this will be the number that
230
+ # the message appears from on the handset. By default this feature is
231
+ # _not_ available and will be ignored
232
+ # in the request. Please contact <support@messagemeda.com> for more
233
+ # information. Specifying a source
234
+ # number is optional and a by default a source number will be assigned to
235
+ # the message.
236
+ # - ```source_number_type``` If a source number is specified, the type of
237
+ # source number may also be
238
+ # specified. This is recommended when using a source address type that is
239
+ # not an internationally
240
+ # formatted number, available options are ```INTERNATIONAL```,
241
+ # ```ALPHANUMERIC``` or ```SHORTCODE```. Specifying a
242
+ # source number type is only valid when the ```source_number``` parameter
243
+ # is specified and is optional.
244
+ # If a source number is specified and no source number type is specified,
245
+ # the source number type will be
246
+ # inferred from the source number, however this may be inaccurate.
247
+ # - ```scheduled``` A message can be scheduled for delivery in the future by
248
+ # setting the scheduled property.
249
+ # The scheduled property expects a date time specified in ISO 8601 format.
250
+ # The scheduled time must be
251
+ # provided in UTC and is optional. If no scheduled property is set, the
252
+ # message will be delivered immediately.
253
+ # - ```message_expiry_timestamp``` A message expiry timestamp can be
254
+ # provided to specify the latest time
255
+ # at which the message should be delivered. If the message cannot be
256
+ # delivered before the specified
257
+ # message expiry timestamp elapses, the message will be discarded.
258
+ # Specifying a message expiry
259
+ # timestamp is optional.
260
+ # - ```metadata``` Metadata can be included with the message which will then
261
+ # be included with any delivery
262
+ # reports or replies matched to the message. This can be used to create
263
+ # powerful two-way messaging
264
+ # applications without having to store persistent data in the application.
265
+ # Up to 10 key / value metadata data
266
+ # pairs can be specified in a message. Each key can be up to 100
267
+ # characters long, and each value up to
268
+ # 256 characters long. Specifying metadata for a message is optional.
269
+ # The response body of a successful POST request to the messages endpoint
270
+ # will include a ```messages```
271
+ # property which contains a list of all messages submitted. The list of
272
+ # messages submitted will
273
+ # reflect the list of messages included in the request, but each message
274
+ # will also contain two new
275
+ # properties, ```message_id``` and ```status```. The returned message ID
276
+ # will be a 36 character UUID
277
+ # which can be used to check the status of the message via the Get Message
278
+ # Status endpoint. The status
279
+ # of the message which reflect the status of the message at submission time
280
+ # which will always be
281
+ # ```queued```. See the Delivery Reports section of this documentation for
282
+ # more information on message
283
+ # statues.
284
+ # *Note: when sending multiple messages in a request, all messages must be
285
+ # valid for the request to be successful.
286
+ # If any messages in the request are invalid, no messages will be sent.*
287
+ # @param [SendMessagesRequest] body Required parameter: Example:
288
+ # @return SendMessagesResponse response from the API call
289
+ def create_send_messages(body)
290
+ begin
291
+ @logger.info("create_send_messages called.")
292
+ # Prepare query url.
293
+ @logger.info("Preparing query URL for create_send_messages.")
294
+ _query_builder = Configuration.base_uri.dup
295
+ _query_builder << '/v1/messages'
296
+ _query_url = APIHelper.clean_url _query_builder
297
+
298
+ # Prepare headers.
299
+ @logger.info("Preparing headers for create_send_messages.")
300
+ _headers = {
301
+ 'accept' => 'application/json',
302
+ 'content-type' => 'application/json; charset=utf-8'
303
+ }
304
+
305
+ # Prepare and execute HttpRequest.
306
+ @logger.info('Preparing and executing HttpRequest for create_send_messages.')
307
+ _request = @http_client.post(
308
+ _query_url,
309
+ headers: _headers,
310
+ parameters: body.to_json
311
+ )
312
+ BasicAuth.apply(_request)
313
+ _context = execute_request(_request, name: 'create_send_messages')
314
+
315
+ # Validate response against endpoint and global error codes.
316
+ @logger.info("Validating response for create_send_messages.")
317
+ if _context.response.status_code == 400
318
+ raise APIException.new(
319
+ '',
320
+ _context
321
+ )
322
+ end
323
+ validate_response(_context)
324
+
325
+ # Return appropriate response type.
326
+ @logger.info("Returning response for create_send_messages.")
327
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
328
+ SendMessagesResponse.from_hash(decoded)
329
+
330
+ rescue Exception => e
331
+ @logger.error(e)
332
+ raise e
333
+ end
334
+ end
335
+ end
336
+ end
@@ -0,0 +1,208 @@
1
+ # This file was automatically generated for MessageMedia by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module MessageMediaMessages
5
+ # RepliesController
6
+ class RepliesController < BaseController
7
+ @instance = RepliesController.new
8
+
9
+ class << self
10
+ attr_accessor :instance
11
+ end
12
+
13
+ def instance
14
+ self.class.instance
15
+ end
16
+
17
+ # Mark a reply message as confirmed so it is no longer returned in check
18
+ # replies requests.
19
+ # The confirm replies endpoint is intended to be used in conjunction with
20
+ # the check replies endpoint
21
+ # to allow for robust processing of reply messages. Once one or more reply
22
+ # messages have been processed
23
+ # they can then be confirmed using the confirm replies endpoint so they are
24
+ # no longer returned in
25
+ # subsequent check replies requests.
26
+ # The confirm replies endpoint takes a list of reply IDs as follows:
27
+ # ```json
28
+ # {
29
+ # "reply_ids": [
30
+ # "011dcead-6988-4ad6-a1c7-6b6c68ea628d",
31
+ # "3487b3fa-6586-4979-a233-2d1b095c7718",
32
+ # "ba28e94b-c83d-4759-98e7-ff9c7edb87a1"
33
+ # ]
34
+ # }
35
+ # ```
36
+ # Up to 100 replies can be confirmed in a single confirm replies request.
37
+ # @param [ConfirmRepliesAsReceivedRequest] body Required parameter:
38
+ # Example:
39
+ # @return Mixed response from the API call
40
+ def create_confirm_replies_as_received(body)
41
+ begin
42
+ @logger.info("create_confirm_replies_as_received called.")
43
+ # Prepare query url.
44
+ @logger.info("Preparing query URL for create_confirm_replies_as_received.")
45
+ _query_builder = Configuration.base_uri.dup
46
+ _query_builder << '/v1/replies/confirmed'
47
+ _query_url = APIHelper.clean_url _query_builder
48
+
49
+ # Prepare headers.
50
+ @logger.info("Preparing headers for create_confirm_replies_as_received.")
51
+ _headers = {
52
+ 'accept' => 'application/json',
53
+ 'content-type' => 'application/json; charset=utf-8'
54
+ }
55
+
56
+ # Prepare and execute HttpRequest.
57
+ @logger.info('Preparing and executing HttpRequest for create_confirm_replies_as_received.')
58
+ _request = @http_client.post(
59
+ _query_url,
60
+ headers: _headers,
61
+ parameters: body.to_json
62
+ )
63
+ BasicAuth.apply(_request)
64
+ _context = execute_request(_request, name: 'create_confirm_replies_as_received')
65
+
66
+ # Validate response against endpoint and global error codes.
67
+ @logger.info("Validating response for create_confirm_replies_as_received.")
68
+ if _context.response.status_code == 400
69
+ raise APIException.new(
70
+ '',
71
+ _context
72
+ )
73
+ end
74
+ validate_response(_context)
75
+
76
+ # Return appropriate response type.
77
+ @logger.info("Returning response for create_confirm_replies_as_received.")
78
+ decoded = APIHelper.json_deserialize(_context.response.raw_body) unless
79
+ _context.response.raw_body.nil? ||
80
+ _context.response.raw_body.to_s.strip.empty?
81
+ decoded
82
+
83
+ rescue Exception => e
84
+ @logger.error(e)
85
+ raise e
86
+ end
87
+ end
88
+
89
+ # Check for any replies that have been received.
90
+ # Replies are messages that have been sent from a handset in response to a
91
+ # message sent by an
92
+ # application or messages that have been sent from a handset to a inbound
93
+ # number associated with
94
+ # an account, known as a dedicated inbound number (contact
95
+ # <support@messagemedia.com> for more
96
+ # information on dedicated inbound numbers).
97
+ # Each request to the check replies endpoint will return any replies
98
+ # received that have not yet
99
+ # been confirmed using the confirm replies endpoint. A response from the
100
+ # check replies endpoint
101
+ # will have the following structure:
102
+ # ```json
103
+ # {
104
+ # "replies": [
105
+ # {
106
+ # "metadata": {
107
+ # "key1": "value1",
108
+ # "key2": "value2"
109
+ # },
110
+ # "message_id": "877c19ef-fa2e-4cec-827a-e1df9b5509f7",
111
+ # "reply_id": "a175e797-2b54-468b-9850-41a3eab32f74",
112
+ # "date_received": "2016-12-07T08:43:00.850Z",
113
+ # "callback_url": "https://my.callback.url.com",
114
+ # "destination_number": "+61491570156",
115
+ # "source_number": "+61491570157",
116
+ # "vendor_account_id": {
117
+ # "vendor_id": "MessageMedia",
118
+ # "account_id": "MyAccount"
119
+ # },
120
+ # "content": "My first reply!"
121
+ # },
122
+ # {
123
+ # "metadata": {
124
+ # "key1": "value1",
125
+ # "key2": "value2"
126
+ # },
127
+ # "message_id": "8f2f5927-2e16-4f1c-bd43-47dbe2a77ae4",
128
+ # "reply_id": "3d8d53d8-01d3-45dd-8cfa-4dfc81600f7f",
129
+ # "date_received": "2016-12-07T08:43:00.850Z",
130
+ # "callback_url": "https://my.callback.url.com",
131
+ # "destination_number": "+61491570157",
132
+ # "source_number": "+61491570158",
133
+ # "vendor_account_id": {
134
+ # "vendor_id": "MessageMedia",
135
+ # "account_id": "MyAccount"
136
+ # },
137
+ # "content": "My second reply!"
138
+ # }
139
+ # ]
140
+ # }
141
+ # ```
142
+ # Each reply will contain details about the reply message, as well as
143
+ # details of the message the reply was sent
144
+ # in response to, including any metadata specified. Every reply will have a
145
+ # reply ID to be used with the
146
+ # confirm replies endpoint.
147
+ # *Note: The source number and destination number properties in a reply are
148
+ # the inverse of those
149
+ # specified in the message the reply is in response to. The source number of
150
+ # the reply message is the
151
+ # same as the destination number of the original message, and the
152
+ # destination number of the reply
153
+ # message is the same as the source number of the original message. If a
154
+ # source number
155
+ # wasn't specified in the original message, then the destination number
156
+ # property will not be present
157
+ # in the reply message.*
158
+ # Subsequent requests to the check replies endpoint will return the same
159
+ # reply messages and a maximum
160
+ # of 100 replies will be returned in each request. Applications should use
161
+ # the confirm replies endpoint
162
+ # in the following pattern so that replies that have been processed are no
163
+ # longer returned in
164
+ # subsequent check replies requests.
165
+ # 1. Call check replies endpoint
166
+ # 2. Process each reply message
167
+ # 3. Confirm all processed reply messages using the confirm replies endpoint
168
+ # *Note: It is recommended to use the Webhooks feature to receive reply
169
+ # messages rather than polling
170
+ # the check replies endpoint.*
171
+ # @return CheckRepliesResponse response from the API call
172
+ def get_check_replies
173
+ begin
174
+ @logger.info("get_check_replies called.")
175
+ # Prepare query url.
176
+ @logger.info("Preparing query URL for get_check_replies.")
177
+ _query_builder = Configuration.base_uri.dup
178
+ _query_builder << '/v1/replies'
179
+ _query_url = APIHelper.clean_url _query_builder
180
+
181
+ # Prepare headers.
182
+ @logger.info("Preparing headers for get_check_replies.")
183
+ _headers = {
184
+ 'accept' => 'application/json'
185
+ }
186
+
187
+ # Prepare and execute HttpRequest.
188
+ @logger.info('Preparing and executing HttpRequest for get_check_replies.')
189
+ _request = @http_client.get(
190
+ _query_url,
191
+ headers: _headers
192
+ )
193
+ BasicAuth.apply(_request)
194
+ _context = execute_request(_request, name: 'get_check_replies')
195
+ validate_response(_context)
196
+
197
+ # Return appropriate response type.
198
+ @logger.info("Returning response for get_check_replies.")
199
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
200
+ CheckRepliesResponse.from_hash(decoded)
201
+
202
+ rescue Exception => e
203
+ @logger.error(e)
204
+ raise e
205
+ end
206
+ end
207
+ end
208
+ end