messagemedia_messages_sdk 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,105 +1,166 @@
1
- # This file was automatically generated for MessageMedia by APIMATIC v2.0 ( https://apimatic.io ).
2
-
3
- require_relative 'controller_test_base'
4
-
5
- class MessagesControllerTests < ControllerTestBase
6
- # Called only once for the class before any test has executed
7
- def self.startup
8
- self.controller = @@api_client.messages
9
- end
10
-
1
+ # This file was automatically generated for MessageMedia by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ require_relative 'controller_test_base'
4
+
5
+ # noinspection RubyClassVariableUsageInspection,RubyInstanceMethodNamingConvention
6
+ class MessagesControllerTests < ControllerTestBase
7
+ # Called only once for the class before any test has executed
8
+ def self.startup
9
+ self.controller = @@api_client.messages
10
+ end
11
+
11
12
  # Submit one or more (up to 100 per request) SMS or text to voice messages for delivery.
12
- #The most basic message has the following structure:
13
- #```json
14
- #{
15
- # "messages": [
16
- # {
17
- # "content": "My first message!",
18
- # "destination_number": "+61491570156"
19
- # }
20
- # ]
21
- #}
22
- #```
23
- #More advanced delivery features can be specified by setting the following properties in a message:
24
- #- ```callback_url``` A URL can be included with each message to which Webhooks will be pushed to
25
- # via a HTTP POST request. Webhooks will be sent if and when the status of the message changes as
26
- # it is processed (if the delivery report property of the request is set to ```true```) and when replies
27
- # are received. Specifying a callback URL is optional.
28
- #- ```content``` The content of the message. This can be a Unicode string, up to 5,000 characters long.
29
- # Message content is required.
30
- #- ```delivery_report``` Delivery reports can be requested with each message. If delivery reports are requested, a webhook
31
- # will be submitted to the ```callback_url``` property specified for the message (or to the webhooks)
32
- # specified for the account every time the status of the message changes as it is processed. The
33
- # current status of the message can also be retrieved via the Delivery Reports endpoint of the
34
- # Messages API. Delivery reports are optional and by default will not be requested.
35
- #- ```destination_number``` The destination number the message should be delivered to. This should be specified in E.164
36
- # international format. For information on E.164, please refer to http://en.wikipedia.org/wiki/E.164.
37
- # A destination number is required.
38
- #- ```format``` The format specifies which format the message will be sent as, ```SMS``` (text message)
39
- # or ```TTS``` (text to speech). With ```TTS``` format, we will call the destination number and read out the
40
- # message using a computer generated voice. Specifying a format is optional, by default ```SMS``` will be used.
41
- #- ```source_number``` A source number may be specified for the message, this will be the number that
42
- # the message appears from on the handset. By default this feature is _not_ available and will be ignored
43
- # in the request. Please contact <support@messagemeda.com> for more information. Specifying a source
44
- # number is optional and a by default a source number will be assigned to the message.
45
- #- ```source_number_type``` If a source number is specified, the type of source number may also be
46
- # specified. This is recommended when using a source address type that is not an internationally
47
- # formatted number, available options are ```INTERNATIONAL```, ```ALPHANUMERIC``` or ```SHORTCODE```. Specifying a
48
- # source number type is only valid when the ```source_number``` parameter is specified and is optional.
49
- # If a source number is specified and no source number type is specified, the source number type will be
50
- # inferred from the source number, however this may be inaccurate.
51
- #- ```scheduled``` A message can be scheduled for delivery in the future by setting the scheduled property.
52
- # The scheduled property expects a date time specified in ISO 8601 format. The scheduled time must be
53
- # provided in UTC and is optional. If no scheduled property is set, the message will be delivered immediately.
54
- #- ```message_expiry_timestamp``` A message expiry timestamp can be provided to specify the latest time
55
- # at which the message should be delivered. If the message cannot be delivered before the specified
56
- # message expiry timestamp elapses, the message will be discarded. Specifying a message expiry
57
- # timestamp is optional.
58
- #- ```metadata``` Metadata can be included with the message which will then be included with any delivery
59
- # reports or replies matched to the message. This can be used to create powerful two-way messaging
60
- # applications without having to store persistent data in the application. Up to 10 key / value metadata data
61
- # pairs can be specified in a message. Each key can be up to 100 characters long, and each value up to
62
- # 256 characters long. Specifying metadata for a message is optional.
63
- #The response body of a successful POST request to the messages endpoint will include a ```messages```
64
- #property which contains a list of all messages submitted. The list of messages submitted will
65
- #reflect the list of messages included in the request, but each message will also contain two new
66
- #properties, ```message_id``` and ```status```. The returned message ID will be a 36 character UUID
67
- #which can be used to check the status of the message via the Get Message Status endpoint. The status
68
- #of the message which reflect the status of the message at submission time which will always be
69
- #```queued```. See the Delivery Reports section of this documentation for more information on message
70
- #statues.
71
- #*Note: when sending multiple messages in a request, all messages must be valid for the request to be successful.
72
- #If any messages in the request are invalid, no messages will be sent.*
73
- def test_send_messages_1()
74
- # Parameters for the API call
75
- body = SendMessagesRequest.from_hash(JSON.parse(
76
- '{"messages":[{"callback_url":"https://my.callback.url.com","content":"My fi'\
77
- 'rst message","destination_number":"+61491570156","delivery_report":true,"fo'\
78
- 'rmat":"SMS","message_expiry_timestamp":"2016-11-03T11:49:02.807Z","metadata'\
79
- '":{"key1":"value1","key2":"value2"},"scheduled":"2016-11-03T11:49:02.807Z",'\
80
- '"source_number":"+61491570157","source_number_type":"INTERNATIONAL"},{"call'\
81
- 'back_url":"https://my.callback.url.com","content":"My second message","dest'\
82
- 'ination_number":"+61491570158","delivery_report":true,"format":"SMS","messa'\
83
- 'ge_expiry_timestamp":"2016-11-03T11:49:02.807Z","metadata":{"key1":"value1"'\
84
- ',"key2":"value2"},"scheduled":"2016-11-03T11:49:02.807Z","source_number":"+'\
85
- '61491570159","source_number_type":"INTERNATIONAL"}]}'
86
- ))
87
-
88
- # Perform the API call through the SDK function
89
- result = self.class.controller.create_send_messages(body)
90
-
91
- # Test response code
92
- assert_equal(@response_catcher.response.status_code, 202)
93
-
94
- # Test headers
95
- expected_headers = {}
96
- expected_headers['content-type'] = nil
97
-
98
- assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
99
-
100
- # Test whether the captured response is as we expected
101
- assert_not_nil(result)
102
- assert_equal('{ "messages": [ { "message_id": "04fe9a97-a579-43c5-bb1a-58ed29bf0a6a", "callback_url": "https://my.url.com", "status": "delivered", "content": "My first message", "destination_number": "+61491570156", "delivery_report": true, "format": "SMS", "message_expiry_timestamp": "2016-11-03T11:49:02.807Z", "metadata": { "key1": "value1", "key2": "value2" }, "scheduled": "2016-11-03T11:49:02.807Z", "source_number": "+61491570157", "source_number_type": "INTERNATIONAL" } ]}', @response_catcher.response.raw_body)
103
- end
104
-
105
- end
13
+ # The most basic message has the following structure:
14
+ # ```json
15
+ # {
16
+ # "messages": [
17
+ # {
18
+ # "content": "My first message!",
19
+ # "destination_number": "+61491570156"
20
+ # }
21
+ # ]
22
+ # }
23
+ # ```
24
+ # More advanced delivery features can be specified by setting the following properties in a message:
25
+ # - ```callback_url``` A URL can be included with each message to which Webhooks will be pushed to
26
+ # via a HTTP POST request. Webhooks will be sent if and when the status of the message changes as
27
+ # it is processed (if the delivery report property of the request is set to ```true```) and when replies
28
+ # are received. Specifying a callback URL is optional.
29
+ # - ```content``` The content of the message. This can be a Unicode string, up to 5,000 characters long.
30
+ # Message content is required.
31
+ # - ```delivery_report``` Delivery reports can be requested with each message. If delivery reports are requested, a webhook
32
+ # will be submitted to the ```callback_url``` property specified for the message (or to the webhooks)
33
+ # specified for the account every time the status of the message changes as it is processed. The
34
+ # current status of the message can also be retrieved via the Delivery Reports endpoint of the
35
+ # Messages API. Delivery reports are optional and by default will not be requested.
36
+ # - ```destination_number``` The destination number the message should be delivered to. This should be specified in E.164
37
+ # international format. For information on E.164, please refer to http://en.wikipedia.org/wiki/E.164.
38
+ # A destination number is required.
39
+ # - ```format``` The format specifies which format the message will be sent as, ```SMS``` (text message)
40
+ # or ```TTS``` (text to speech). With ```TTS``` format, we will call the destination number and read out the
41
+ # message using a computer generated voice. Specifying a format is optional, by default ```SMS``` will be used.
42
+ # - ```source_number``` A source number may be specified for the message, this will be the number that
43
+ # the message appears from on the handset. By default this feature is _not_ available and will be ignored
44
+ # in the request. Please contact <support@messagemeda.com> for more information. Specifying a source
45
+ # number is optional and a by default a source number will be assigned to the message.
46
+ # - ```source_number_type``` If a source number is specified, the type of source number may also be
47
+ # specified. This is recommended when using a source address type that is not an internationally
48
+ # formatted number, available options are ```INTERNATIONAL```, ```ALPHANUMERIC``` or ```SHORTCODE```. Specifying a
49
+ # source number type is only valid when the ```source_number``` parameter is specified and is optional.
50
+ # If a source number is specified and no source number type is specified, the source number type will be
51
+ # inferred from the source number, however this may be inaccurate.
52
+ # - ```scheduled``` A message can be scheduled for delivery in the future by setting the scheduled property.
53
+ # The scheduled property expects a date time specified in ISO 8601 format. The scheduled time must be
54
+ # provided in UTC and is optional. If no scheduled property is set, the message will be delivered immediately.
55
+ # - ```message_expiry_timestamp``` A message expiry timestamp can be provided to specify the latest time
56
+ # at which the message should be delivered. If the message cannot be delivered before the specified
57
+ # message expiry timestamp elapses, the message will be discarded. Specifying a message expiry
58
+ # timestamp is optional.
59
+ # - ```metadata``` Metadata can be included with the message which will then be included with any delivery
60
+ # reports or replies matched to the message. This can be used to create powerful two-way messaging
61
+ # applications without having to store persistent data in the application. Up to 10 key / value metadata data
62
+ # pairs can be specified in a message. Each key can be up to 100 characters long, and each value up to
63
+ # 256 characters long. Specifying metadata for a message is optional.
64
+ # The response body of a successful POST request to the messages endpoint will include a ```messages```
65
+ # property which contains a list of all messages submitted. The list of messages submitted will
66
+ # reflect the list of messages included in the request, but each message will also contain two new
67
+ # properties, ```message_id``` and ```status```. The returned message ID will be a 36 character UUID
68
+ # which can be used to check the status of the message via the Get Message Status endpoint. The status
69
+ # of the message which reflect the status of the message at submission time which will always be
70
+ # ```queued```. See the Delivery Reports section of this documentation for more information on message
71
+ # statues.
72
+ # *Note: when sending multiple messages in a request, all messages must be valid for the request to be successful.
73
+ # If any messages in the request are invalid, no messages will be sent.*
74
+ def test_send_messages_1
75
+ # Parameters for the API call
76
+ body = SendMessagesRequest.from_hash(JSON.parse(
77
+ '{"messages":[{"callback_url":"https://my.callback.url.com","content":"My fi'\
78
+ 'rst message","destination_number":"+61491570156","delivery_report":true,"fo'\
79
+ 'rmat":"SMS","message_expiry_timestamp":"2016-11-03T11:49:02.807Z","metadata'\
80
+ '":{"key1":"value1","key2":"value2"},"scheduled":"2016-11-03T11:49:02.807Z",'\
81
+ '"source_number":"+61491570157","source_number_type":"INTERNATIONAL"},{"call'\
82
+ 'back_url":"https://my.callback.url.com","content":"My second message","dest'\
83
+ 'ination_number":"+61491570158","delivery_report":true,"format":"SMS","messa'\
84
+ 'ge_expiry_timestamp":"2016-11-03T11:49:02.807Z","metadata":{"key1":"value1"'\
85
+ ',"key2":"value2"},"scheduled":"2016-11-03T11:49:02.807Z","source_number":"+'\
86
+ '61491570159","source_number_type":"INTERNATIONAL"}]}'
87
+ ))
88
+
89
+ # Perform the API call through the SDK function
90
+ result = self.class.controller.create_send_messages(body)
91
+
92
+ # Test response code
93
+ assert_equal(@response_catcher.response.status_code, 202)
94
+
95
+ # Test headers
96
+ expected_headers = {}
97
+ expected_headers['content-type'] = nil
98
+
99
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
100
+
101
+ # Test whether the captured response is as we expected
102
+ assert_not_nil(result)
103
+
104
+ assert_equal(body.messages[0]['callback_url'], result.messages[0]['callback_url'],
105
+ 'Callback URL should match exactly (string literal match)')
106
+ assert_equal(body.messages[0]['content'], result.messages[0]['content'],
107
+ 'Content should match exactly (string literal match)')
108
+ assert_equal(body.messages[0]['format'], result.messages[0]['format'],
109
+ 'Format should match exactly (string literal match)')
110
+ assert_equal(body.messages[0]['delivery_report'], result.messages[0]['delivery_report'],
111
+ 'Delivery Report should match exactly (boolean match)')
112
+ assert_equal(body.messages[0]['destination_number'], result.messages[0]['destination_number'],
113
+ 'Destination Number should match exactly (string literal match)')
114
+ assert_equal(body.messages[0]['source_number'], result.messages[0]['source_number'],
115
+ 'Source Number should match exactly (string literal match)')
116
+
117
+ assert_not_nil(result.messages[0]['message_id'], 'Message ID should not be empty')
118
+ assert_not_nil(result.messages[0]['message_expiry_timestamp'], 'Message Expiry should not be empty')
119
+ assert_not_nil(result.messages[0]['scheduled'], 'Scheduled time should not be empty')
120
+
121
+ assert_equal(body.messages[1]['callback_url'], result.messages[1]['callback_url'],
122
+ 'Callback URL should match exactly (string literal match)')
123
+ assert_equal(body.messages[1]['content'], result.messages[1]['content'],
124
+ 'Content should match exactly (string literal match)')
125
+ assert_equal(body.messages[1]['format'], result.messages[1]['format'],
126
+ 'Format should match exactly (string literal match)')
127
+ assert_equal(body.messages[1]['delivery_report'], result.messages[1]['delivery_report'],
128
+ 'Delivery Report should match exactly (boolean match)')
129
+ assert_equal(body.messages[1]['destination_number'], result.messages[1]['destination_number'],
130
+ 'Destination Number should match exactly (string literal match)')
131
+ assert_equal(body.messages[1]['source_number'], result.messages[1]['source_number'],
132
+ 'Source Number should match exactly (string literal match)')
133
+
134
+ assert_not_nil(result.messages[1]['message_id'], 'Message ID should not be empty')
135
+ assert_not_nil(result.messages[1]['message_expiry_timestamp'], 'Message Expiry should not be empty')
136
+ assert_not_nil(result.messages[1]['scheduled'], 'Scheduled time should not be empty')
137
+ end
138
+
139
+ # Make sure our SDK fails when passed an invalid account id
140
+ def test_send_messages_with_invalid_account
141
+ begin
142
+ # Parameters for the API call
143
+ body = SendMessagesRequest.from_hash(JSON.parse(
144
+ '{"messages":[{"callback_url":"https://my.callback.url.com","content":"My fi'\
145
+ 'rst message","destination_number":"+61491570156","delivery_report":true,"fo'\
146
+ 'rmat":"SMS","message_expiry_timestamp":"2016-11-03T11:49:02.807Z","metadata'\
147
+ '":{"key1":"value1","key2":"value2"},"scheduled":"2016-11-03T11:49:02.807Z",'\
148
+ '"source_number":"+61491570157","source_number_type":"INTERNATIONAL"},{"call'\
149
+ 'back_url":"https://my.callback.url.com","content":"My second message","dest'\
150
+ 'ination_number":"+61491570158","delivery_report":true,"format":"SMS","messa'\
151
+ 'ge_expiry_timestamp":"2016-11-03T11:49:02.807Z","metadata":{"key1":"value1"'\
152
+ ',"key2":"value2"},"scheduled":"2016-11-03T11:49:02.807Z","source_number":"+'\
153
+ '61491570159","source_number_type":"INTERNATIONAL"}]}'
154
+ ))
155
+
156
+ # Perform the API call through the SDK function
157
+ self.class.controller.create_send_messages(body, 'INVALID ACCOUNT')
158
+ rescue APIException => api_exception
159
+ assert_equal('HTTP Response Not OK. {"message":"Invalid account \'INVALID ACCOUNT\' in header Account"}' + "\n",
160
+ api_exception.message,'Make sure we''ve got our error message')
161
+ # Test response code
162
+ assert_equal(@response_catcher.response.status_code, 403)
163
+ end
164
+ end
165
+
166
+ end
@@ -1,132 +1,164 @@
1
- # This file was automatically generated for MessageMedia by APIMATIC v2.0 ( https://apimatic.io ).
2
-
3
- require_relative 'controller_test_base'
4
-
5
- class RepliesControllerTests < ControllerTestBase
6
- # Called only once for the class before any test has executed
7
- def self.startup
8
- self.controller = @@api_client.replies
9
- end
10
-
1
+ # This file was automatically generated for MessageMedia by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ require 'message_media_messages/exceptions/api_exception'
4
+ require_relative 'controller_test_base'
5
+
6
+ # noinspection RubyClassVariableUsageInspection,RubyInstanceMethodNamingConvention
7
+ class RepliesControllerTests < ControllerTestBase
8
+ # Called only once for the class before any test has executed
9
+ def self.startup
10
+ self.controller = @@api_client.replies
11
+ end
12
+
11
13
  # Mark a reply message as confirmed so it is no longer returned in check replies requests.
12
- #The confirm replies endpoint is intended to be used in conjunction with the check replies endpoint
13
- #to allow for robust processing of reply messages. Once one or more reply messages have been processed
14
- #they can then be confirmed using the confirm replies endpoint so they are no longer returned in
15
- #subsequent check replies requests.
16
- #The confirm replies endpoint takes a list of reply IDs as follows:
17
- #```json
18
- #{
19
- # "reply_ids": [
20
- # "011dcead-6988-4ad6-a1c7-6b6c68ea628d",
21
- # "3487b3fa-6586-4979-a233-2d1b095c7718",
22
- # "ba28e94b-c83d-4759-98e7-ff9c7edb87a1"
23
- # ]
24
- #}
25
- #```
26
- #Up to 100 replies can be confirmed in a single confirm replies request.
27
- def test_confirm_replies_as_received_1()
28
- # Parameters for the API call
29
- body = ConfirmRepliesAsReceivedRequest.from_hash(JSON.parse(
30
- '{"reply_ids":["011dcead-6988-4ad6-a1c7-6b6c68ea628d","3487b3fa-6586-4979-a2'\
31
- '33-2d1b095c7718","ba28e94b-c83d-4759-98e7-ff9c7edb87a1"]}'
32
- ))
33
-
34
- # Perform the API call through the SDK function
35
- result = self.class.controller.create_confirm_replies_as_received(body)
36
-
37
- # Test response code
38
- assert_equal(@response_catcher.response.status_code, 202)
39
-
40
- # Test headers
41
- expected_headers = {}
42
- expected_headers['content-type'] = nil
43
-
44
- assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
45
- end
46
-
14
+ # The confirm replies endpoint is intended to be used in conjunction with the check replies endpoint
15
+ # to allow for robust processing of reply messages. Once one or more reply messages have been processed
16
+ # they can then be confirmed using the confirm replies endpoint so they are no longer returned in
17
+ # subsequent check replies requests.
18
+ # The confirm replies endpoint takes a list of reply IDs as follows:
19
+ # ```json
20
+ # {
21
+ # "reply_ids": [
22
+ # "011dcead-6988-4ad6-a1c7-6b6c68ea628d",
23
+ # "3487b3fa-6586-4979-a233-2d1b095c7718",
24
+ # "ba28e94b-c83d-4759-98e7-ff9c7edb87a1"
25
+ # ]
26
+ # }
27
+ # ```
28
+ # Up to 100 replies can be confirmed in a single confirm replies request.
29
+ def test_confirm_replies_as_received_1
30
+ # Parameters for the API call
31
+ body = ConfirmRepliesAsReceivedRequest.from_hash(JSON.parse(
32
+ '{"reply_ids":["011dcead-6988-4ad6-a1c7-6b6c68ea628d","3487b3fa-6586-4979-a2'\
33
+ '33-2d1b095c7718","ba28e94b-c83d-4759-98e7-ff9c7edb87a1"]}'))
34
+
35
+ # Perform the API call through the SDK function
36
+ self.class.controller.create_confirm_replies_as_received(body)
37
+
38
+ # Test response code
39
+ assert_equal(@response_catcher.response.status_code, 202)
40
+
41
+ # Test headers
42
+ expected_headers = {}
43
+ expected_headers['content-type'] = nil
44
+
45
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
46
+ end
47
+
48
+ # Make sure our SDK fails when passed an invalid account id
49
+ def test_confirm_replies_as_received_invalid_account
50
+ begin
51
+ # Parameters for the API call
52
+ body = ConfirmRepliesAsReceivedRequest.from_hash(JSON.parse(
53
+ '{"reply_ids":["011dcead-6988-4ad6-a1c7-6b6c68ea628d","3487b3fa-6586-4979-a2'\
54
+ '33-2d1b095c7718","ba28e94b-c83d-4759-98e7-ff9c7edb87a1"]}'))
55
+
56
+ # Perform the API call through the SDK function
57
+ self.class.controller.create_confirm_replies_as_received(body, 'INVALID ACCOUNT')
58
+ rescue APIException => api_exception
59
+ assert_equal('HTTP Response Not OK. {"message":"Invalid account \'INVALID ACCOUNT\' in header Account"}' + "\n",
60
+ api_exception.message,'Make sure we''ve got our error message')
61
+
62
+ # Test response code
63
+ assert_equal(@response_catcher.response.status_code, 403)
64
+ end
65
+ end
66
+
47
67
  # Check for any replies that have been received.
48
- #Replies are messages that have been sent from a handset in response to a message sent by an
49
- #application or messages that have been sent from a handset to a inbound number associated with
50
- #an account, known as a dedicated inbound number (contact <support@messagemedia.com> for more
51
- #information on dedicated inbound numbers).
52
- #Each request to the check replies endpoint will return any replies received that have not yet
53
- #been confirmed using the confirm replies endpoint. A response from the check replies endpoint
54
- #will have the following structure:
55
- #```json
56
- #{
57
- # "replies": [
58
- # {
59
- # "metadata": {
60
- # "key1": "value1",
61
- # "key2": "value2"
62
- # },
63
- # "message_id": "877c19ef-fa2e-4cec-827a-e1df9b5509f7",
64
- # "reply_id": "a175e797-2b54-468b-9850-41a3eab32f74",
65
- # "date_received": "2016-12-07T08:43:00.850Z",
66
- # "callback_url": "https://my.callback.url.com",
67
- # "destination_number": "+61491570156",
68
- # "source_number": "+61491570157",
69
- # "vendor_account_id": {
70
- # "vendor_id": "MessageMedia",
71
- # "account_id": "MyAccount"
72
- # },
73
- # "content": "My first reply!"
74
- # },
75
- # {
76
- # "metadata": {
77
- # "key1": "value1",
78
- # "key2": "value2"
79
- # },
80
- # "message_id": "8f2f5927-2e16-4f1c-bd43-47dbe2a77ae4",
81
- # "reply_id": "3d8d53d8-01d3-45dd-8cfa-4dfc81600f7f",
82
- # "date_received": "2016-12-07T08:43:00.850Z",
83
- # "callback_url": "https://my.callback.url.com",
84
- # "destination_number": "+61491570157",
85
- # "source_number": "+61491570158",
86
- # "vendor_account_id": {
87
- # "vendor_id": "MessageMedia",
88
- # "account_id": "MyAccount"
89
- # },
90
- # "content": "My second reply!"
91
- # }
92
- # ]
93
- #}
94
- #```
95
- #Each reply will contain details about the reply message, as well as details of the message the reply was sent
96
- #in response to, including any metadata specified. Every reply will have a reply ID to be used with the
97
- #confirm replies endpoint.
98
- #*Note: The source number and destination number properties in a reply are the inverse of those
99
- #specified in the message the reply is in response to. The source number of the reply message is the
100
- #same as the destination number of the original message, and the destination number of the reply
101
- #message is the same as the source number of the original message. If a source number
102
- #wasn't specified in the original message, then the destination number property will not be present
103
- #in the reply message.*
104
- #Subsequent requests to the check replies endpoint will return the same reply messages and a maximum
105
- #of 100 replies will be returned in each request. Applications should use the confirm replies endpoint
106
- #in the following pattern so that replies that have been processed are no longer returned in
107
- #subsequent check replies requests.
108
- #1. Call check replies endpoint
109
- #2. Process each reply message
110
- #3. Confirm all processed reply messages using the confirm replies endpoint
111
- #*Note: It is recommended to use the Webhooks feature to receive reply messages rather than polling
112
- #the check replies endpoint.*
113
- def test_check_replies_1()
114
-
115
- # Perform the API call through the SDK function
116
- result = self.class.controller.get_check_replies()
117
-
118
- # Test response code
119
- assert_equal(@response_catcher.response.status_code, 200)
120
-
121
- # Test headers
122
- expected_headers = {}
123
- expected_headers['content-type'] = nil
124
-
125
- assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
126
-
127
- # Test whether the captured response is as we expected
128
- assert_not_nil(result)
129
- assert_equal('{ "replies": [ { "metadata": { "key1": "value1", "key2": "value2" }, "message_id": "877c19ef-fa2e-4cec-827a-e1df9b5509f7", "reply_id": "a175e797-2b54-468b-9850-41a3eab32f74", "date_received": "2016-12-07T08:43:00.850Z", "callback_url": "https://my.callback.url.com", "destination_number": "+61491570156", "source_number": "+61491570157", "vendor_account_id": { "vendor_id": "MessageMedia", "account_id": "MyAccount" }, "content": "My first reply!" }, { "metadata": { "key1": "value1", "key2": "value2" }, "message_id": "8f2f5927-2e16-4f1c-bd43-47dbe2a77ae4", "reply_id": "3d8d53d8-01d3-45dd-8cfa-4dfc81600f7f", "date_received": "2016-12-07T08:43:00.850Z", "callback_url": "https://my.callback.url.com", "destination_number": "+61491570157", "source_number": "+61491570158", "vendor_account_id": { "vendor_id": "MessageMedia", "account_id": "MyAccount" }, "content": "My second reply!" } ]}', @response_catcher.response.raw_body)
130
- end
131
-
132
- end
68
+ # Replies are messages that have been sent from a handset in response to a message sent by an
69
+ # application or messages that have been sent from a handset to a inbound number associated with
70
+ # an account, known as a dedicated inbound number (contact <support@messagemedia.com> for more
71
+ # information on dedicated inbound numbers).
72
+ # Each request to the check replies endpoint will return any replies received that have not yet
73
+ # been confirmed using the confirm replies endpoint. A response from the check replies endpoint
74
+ # will have the following structure:
75
+ # ```json
76
+ # {
77
+ # "replies": [
78
+ # {
79
+ # "metadata": {
80
+ # "key1": "value1",
81
+ # "key2": "value2"
82
+ # },
83
+ # "message_id": "877c19ef-fa2e-4cec-827a-e1df9b5509f7",
84
+ # "reply_id": "a175e797-2b54-468b-9850-41a3eab32f74",
85
+ # "date_received": "2016-12-07T08:43:00.850Z",
86
+ # "callback_url": "https://my.callback.url.com",
87
+ # "destination_number": "+61491570156",
88
+ # "source_number": "+61491570157",
89
+ # "vendor_account_id": {
90
+ # "vendor_id": "MessageMedia",
91
+ # "account_id": "MyAccount"
92
+ # },
93
+ # "content": "My first reply!"
94
+ # },
95
+ # {
96
+ # "metadata": {
97
+ # "key1": "value1",
98
+ # "key2": "value2"
99
+ # },
100
+ # "message_id": "8f2f5927-2e16-4f1c-bd43-47dbe2a77ae4",
101
+ # "reply_id": "3d8d53d8-01d3-45dd-8cfa-4dfc81600f7f",
102
+ # "date_received": "2016-12-07T08:43:00.850Z",
103
+ # "callback_url": "https://my.callback.url.com",
104
+ # "destination_number": "+61491570157",
105
+ # "source_number": "+61491570158",
106
+ # "vendor_account_id": {
107
+ # "vendor_id": "MessageMedia",
108
+ # "account_id": "MyAccount"
109
+ # },
110
+ # "content": "My second reply!"
111
+ # }
112
+ # ]
113
+ # }
114
+ # ```
115
+ # Each reply will contain details about the reply message, as well as details of the message the reply was sent
116
+ # in response to, including any metadata specified. Every reply will have a reply ID to be used with the
117
+ # confirm replies endpoint.
118
+ # *Note: The source number and destination number properties in a reply are the inverse of those
119
+ # specified in the message the reply is in response to. The source number of the reply message is the
120
+ # same as the destination number of the original message, and the destination number of the reply
121
+ # message is the same as the source number of the original message. If a source number
122
+ # wasn't specified in the original message, then the destination number property will not be present
123
+ # in the reply message.*
124
+ # Subsequent requests to the check replies endpoint will return the same reply messages and a maximum
125
+ # of 100 replies will be returned in each request. Applications should use the confirm replies endpoint
126
+ # in the following pattern so that replies that have been processed are no longer returned in
127
+ # subsequent check replies requests.
128
+ # 1. Call check replies endpoint
129
+ # 2. Process each reply message
130
+ # 3. Confirm all processed reply messages using the confirm replies endpoint
131
+ # *Note: It is recommended to use the Webhooks feature to receive reply messages rather than polling
132
+ # the check replies endpoint.*
133
+ def test_check_replies_1
134
+ # Perform the API call through the SDK function
135
+ result = self.class.controller.get_check_replies
136
+
137
+ # Test response code
138
+ assert_equal(@response_catcher.response.status_code, 200)
139
+
140
+ # Test headers
141
+ expected_headers = {}
142
+ expected_headers['content-type'] = nil
143
+
144
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
145
+
146
+ # Test whether the captured response is as we expected
147
+ assert_not_nil(result)
148
+ assert_true(@response_catcher.response.raw_body.index('{"replies":[') >= 0)
149
+ end
150
+
151
+ # Make sure our SDK fails when passed an invalid account id
152
+ def test_check_replies_with_invalid_account
153
+ begin
154
+ # Perform the API call through the SDK function
155
+ self.class.controller.get_check_replies('INVALID ACCOUNT')
156
+ rescue APIException => api_exception
157
+ assert_equal('HTTP Response Not OK. {"message":"Invalid account \'INVALID ACCOUNT\' in header Account"}' + "\n",
158
+ api_exception.message,'Make sure we''ve got our error message')
159
+ # Test response code
160
+ assert_equal(@response_catcher.response.status_code, 403)
161
+ end
162
+ end
163
+
164
+ end