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.
@@ -3,6 +3,7 @@
3
3
 
4
4
  module MessageMediaMessages
5
5
  # RepliesController
6
+ # noinspection RubyResolve,RubyInstanceMethodNamingConvention,RubyStringKeysInHashInspection
6
7
  class RepliesController < BaseController
7
8
  @instance = RepliesController.new
8
9
 
@@ -36,49 +37,58 @@ module MessageMediaMessages
36
37
  # Up to 100 replies can be confirmed in a single confirm replies request.
37
38
  # @param [ConfirmRepliesAsReceivedRequest] body Required parameter:
38
39
  # Example:
40
+ # @param [Object] account_header_value The account id to pass to the API
39
41
  # @return Mixed response from the API call
40
- def create_confirm_replies_as_received(body)
42
+ def create_confirm_replies_as_received(body, account_header_value=nil)
41
43
  begin
42
44
  @logger.info("create_confirm_replies_as_received called.")
45
+
46
+ request_url = '/v1/replies/confirmed'
47
+
43
48
  # Prepare query url.
44
49
  @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
50
+ query_builder = Configuration.base_uri.dup
51
+ query_builder << request_url
52
+ query_url = APIHelper.clean_url query_builder
48
53
 
49
54
  # Prepare headers.
50
55
  @logger.info("Preparing headers for create_confirm_replies_as_received.")
51
- _headers = {
56
+ headers = {
52
57
  'accept' => 'application/json',
53
58
  'content-type' => 'application/json; charset=utf-8'
54
59
  }
55
-
60
+
61
+ add_account_header(headers, account_header_value)
62
+
63
+ json_body = body.to_json
64
+
56
65
  # Prepare and execute HttpRequest.
57
66
  @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
67
+ request = @http_client.post(
68
+ query_url,
69
+ headers: headers,
70
+ parameters: json_body
62
71
  )
63
- BasicAuth.apply(_request)
64
- _context = execute_request(_request, name: 'create_confirm_replies_as_received')
72
+
73
+ apply_authentication(request, request_url, json_body)
74
+
75
+ context = execute_request(request, name: 'create_confirm_replies_as_received')
65
76
 
66
77
  # Validate response against endpoint and global error codes.
67
78
  @logger.info("Validating response for create_confirm_replies_as_received.")
68
- if _context.response.status_code == 400
79
+ if context.response.status_code == 400
69
80
  raise APIException.new(
70
81
  '',
71
- _context
82
+ context
72
83
  )
73
84
  end
74
- validate_response(_context)
85
+ validate_response(context)
75
86
 
76
87
  # Return appropriate response type.
77
88
  @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
89
+ return APIHelper.json_deserialize(context.response.raw_body) unless
90
+ context.response.raw_body.nil? ||
91
+ context.response.raw_body.to_s.strip.empty?
82
92
 
83
93
  rescue Exception => e
84
94
  @logger.error(e)
@@ -168,35 +178,42 @@ module MessageMediaMessages
168
178
  # *Note: It is recommended to use the Webhooks feature to receive reply
169
179
  # messages rather than polling
170
180
  # the check replies endpoint.*
181
+ # @param [Object] account_header_value The account id to pass to the API
171
182
  # @return CheckRepliesResponse response from the API call
172
- def get_check_replies
183
+ def get_check_replies(account_header_value=nil)
173
184
  begin
174
185
  @logger.info("get_check_replies called.")
186
+
187
+ request_url = '/v1/replies'
175
188
  # Prepare query url.
176
189
  @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
190
+ query_builder = Configuration.base_uri.dup
191
+ query_builder << request_url
192
+ query_url = APIHelper.clean_url query_builder
180
193
 
181
194
  # Prepare headers.
182
195
  @logger.info("Preparing headers for get_check_replies.")
183
- _headers = {
196
+ headers = {
184
197
  'accept' => 'application/json'
185
198
  }
186
-
199
+
200
+ add_account_header(headers, account_header_value)
201
+
187
202
  # Prepare and execute HttpRequest.
188
203
  @logger.info('Preparing and executing HttpRequest for get_check_replies.')
189
- _request = @http_client.get(
190
- _query_url,
191
- headers: _headers
204
+ request = @http_client.get(
205
+ query_url,
206
+ headers: headers
192
207
  )
193
- BasicAuth.apply(_request)
194
- _context = execute_request(_request, name: 'get_check_replies')
195
- validate_response(_context)
208
+
209
+ apply_authentication(request, request_url)
210
+
211
+ context = execute_request(request, name: 'get_check_replies')
212
+ validate_response(context)
196
213
 
197
214
  # Return appropriate response type.
198
215
  @logger.info("Returning response for get_check_replies.")
199
- decoded = APIHelper.json_deserialize(_context.response.raw_body)
216
+ decoded = APIHelper.json_deserialize(context.response.raw_body)
200
217
  CheckRepliesResponse.from_hash(decoded)
201
218
 
202
219
  rescue Exception => e
@@ -7,8 +7,8 @@ module MessageMediaMessages
7
7
  attr_reader :context, :response_code
8
8
 
9
9
  # The constructor.
10
- # @param [String] The reason for raising an exception.
11
- # @param [HttpContext] The HttpContext of the API call.
10
+ # @param [String] reason The reason for raising an exception.
11
+ # @param [HttpContext] context The HttpContext of the API call.
12
12
  def initialize(reason, context)
13
13
  super(reason)
14
14
  @context = context
@@ -9,7 +9,7 @@ module MessageMediaMessages
9
9
  # Add basic authentication to the request.
10
10
  # @param [HttpRequest] The HttpRequest object to which authentication will
11
11
  # be added.
12
- def self.apply(http_request)
12
+ def self.apply(http_request, url=nil, body=nil)
13
13
  username = Configuration.basic_auth_user_name
14
14
  password = Configuration.basic_auth_password
15
15
  value = Base64.strict_encode64("#{username}:#{password}")
@@ -0,0 +1,54 @@
1
+ # This file was automatically generated for MessageMedia by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ require 'base64'
5
+
6
+ module MessageMediaMessages
7
+ # Utility class for basic authorization.
8
+ class HmacAuth
9
+ def self.create_signature(date, content_signature, url, body=nil)
10
+ request_type = "GET"
11
+
12
+ if body != nil
13
+ request_type = "POST"
14
+ end
15
+
16
+ signing_string = "date: #{date}\n#{content_signature}#{request_type} #{url} HTTP/1.1"
17
+ hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), Configuration.hmac_auth_password.encode("ASCII"), signing_string.encode("ASCII"))
18
+
19
+ return Base64.encode64(hmac).chomp
20
+ end
21
+
22
+ # Add basic authentication to the request.
23
+ # @param [HttpRequest] The HttpRequest object to which authentication will
24
+ # be added.
25
+ def self.apply(http_request, url=nil, body=nil)
26
+ username = Configuration.hmac_auth_user_name
27
+
28
+ content_signature = ""
29
+ content_header = ""
30
+
31
+ now = DateTime.now.new_offset(0).to_time.strftime("%a, %d %b %Y %H:%M:%S GMT")
32
+
33
+ date_header = now
34
+
35
+ if body != nil
36
+ md5 = Digest::MD5.new
37
+ md5.update(body)
38
+
39
+ content_hash = md5.hexdigest
40
+ content_signature = "x-Content-MD5: #{content_hash}\n"
41
+ content_header = "x-Content-MD5 "
42
+ http_request.headers["x-Content-MD5"] = content_hash
43
+ end
44
+
45
+ http_request.headers["date"] = date_header
46
+
47
+ hmac_signature = HmacAuth.create_signature(date_header, content_signature, url, body)
48
+
49
+ joined = "username=\"#{username}\", algorithm=\"hmac-sha1\", headers=\"date #{content_header}request-line\", signature=\"#{hmac_signature}\""
50
+ header_value = "hmac #{joined}"
51
+ http_request.headers["Authorization"] = header_value
52
+ end
53
+ end
54
+ end
@@ -5,7 +5,7 @@ module MessageMediaMessages
5
5
  # HttpCallBack allows defining callables for pre and post API calls.
6
6
  class HttpCallBack
7
7
  # A controller will call this method before making an HTTP Request.
8
- # @param [HttpRequest] The HttpRequest object which the HttpClient
8
+ # @param [HttpRequest] _http_request The HttpRequest object which the HttpClient
9
9
  # will execute.
10
10
  def on_before_request(_http_request)
11
11
  raise NotImplementedError, 'This method needs
@@ -13,7 +13,7 @@ module MessageMediaMessages
13
13
  end
14
14
 
15
15
  # A controller will call this method after making an HTTP Request.
16
- # @param [HttpContext] The HttpContext of the API call.
16
+ # @param [HttpContext] _http_context The HttpContext of the API call.
17
17
  def on_after_response(_http_context)
18
18
  raise NotImplementedError, 'This method needs
19
19
  to be implemented in a child class.'
@@ -8,29 +8,29 @@ module MessageMediaMessages
8
8
  # for HTTP Client classes.
9
9
  class HttpClient
10
10
  # Execute an HttpRequest when the response is expected to be a string.
11
- # @param [HttpRequest] The HttpRequest to be executed.
11
+ # @param [HttpRequest] _http_request The HttpRequest to be executed.
12
12
  def execute_as_string(_http_request)
13
13
  raise NotImplementedError, 'This method needs
14
14
  to be implemented in a child class.'
15
15
  end
16
16
 
17
17
  # Execute an HttpRequest when the response is expected to be binary.
18
- # @param [HttpRequest] The HttpRequest to be executed.
18
+ # @param [HttpRequest] _http_request The HttpRequest to be executed.
19
19
  def execute_as_binary(_http_request)
20
20
  raise NotImplementedError, 'This method needs
21
21
  to be implemented in a child class.'
22
22
  end
23
23
 
24
24
  # Converts the HTTP Response from the client to an HttpResponse object.
25
- # @param [Dynamic] The response object received from the client.
25
+ # @param [Dynamic] _response The response object received from the client.
26
26
  def convert_response(_response)
27
27
  raise NotImplementedError, 'This method needs
28
28
  to be implemented in a child class.'
29
29
  end
30
30
 
31
31
  # Get a GET HttpRequest object.
32
- # @param [String] The URL to send the request to.
33
- # @param [Hash, Optional] The headers for the HTTP Request.
32
+ # @param [String] query_url The URL to send the request to.
33
+ # @param [Hash, Optional] headers The headers for the HTTP Request.
34
34
  def get(query_url,
35
35
  headers: {})
36
36
  HttpRequest.new(HttpMethodEnum::GET,
@@ -39,9 +39,9 @@ module MessageMediaMessages
39
39
  end
40
40
 
41
41
  # Get a POST HttpRequest object.
42
- # @param [String] The URL to send the request to.
43
- # @param [Hash, Optional] The headers for the HTTP Request.
44
- # @param [Hash, Optional] The parameters for the HTTP Request.
42
+ # @param [String] query_url The URL to send the request to.
43
+ # @param [Hash, Optional] headers The headers for the HTTP Request.
44
+ # @param [Hash, Optional] parameters The parameters for the HTTP Request.
45
45
  def post(query_url,
46
46
  headers: {},
47
47
  parameters: {})
@@ -52,9 +52,9 @@ module MessageMediaMessages
52
52
  end
53
53
 
54
54
  # Get a PUT HttpRequest object.
55
- # @param [String] The URL to send the request to.
56
- # @param [Hash, Optional] The headers for the HTTP Request.
57
- # @param [Hash, Optional] The parameters for the HTTP Request.
55
+ # @param [String] query_url The URL to send the request to.
56
+ # @param [Hash, Optional] headers The headers for the HTTP Request.
57
+ # @param [Hash, Optional] parameters The parameters for the HTTP Request.
58
58
  def put(query_url,
59
59
  headers: {},
60
60
  parameters: {})
@@ -65,9 +65,9 @@ module MessageMediaMessages
65
65
  end
66
66
 
67
67
  # Get a PATCH HttpRequest object.
68
- # @param [String] The URL to send the request to.
69
- # @param [Hash, Optional] The headers for the HTTP Request.
70
- # @param [Hash, Optional] The parameters for the HTTP Request.
68
+ # @param [String] query_url The URL to send the request to.
69
+ # @param [Hash, Optional] headers The headers for the HTTP Request.
70
+ # @param [Hash, Optional] parameters The parameters for the HTTP Request.
71
71
  def patch(query_url,
72
72
  headers: {},
73
73
  parameters: {})
@@ -78,8 +78,9 @@ module MessageMediaMessages
78
78
  end
79
79
 
80
80
  # Get a DELETE HttpRequest object.
81
- # @param [String] The URL to send the request to.
82
- # @param [Hash, Optional] The headers for the HTTP Request.
81
+ # @param [String] query_url The URL to send the request to.
82
+ # @param [Hash, Optional] headers The headers for the HTTP Request.
83
+ # @param [Hash, Optional] parameters The parameters for the HTTP Request.
83
84
  def delete(query_url,
84
85
  headers: {},
85
86
  parameters: {})
@@ -7,8 +7,8 @@ module MessageMediaMessages
7
7
  attr_accessor :request, :response
8
8
 
9
9
  # The constructor.
10
- # @param [HttpRequest] An HttpRequest object representing the HTTP request.
11
- # @param [HttpResponse] An HttpResponse object representing the HTTP
10
+ # @param [HttpRequest] request An HttpRequest object representing the HTTP request.
11
+ # @param [HttpResponse] response An HttpResponse object representing the HTTP
12
12
  # response.
13
13
  def initialize(request, response)
14
14
  @request = request
@@ -8,10 +8,10 @@ module MessageMediaMessages
8
8
  :parameters, :username, :password
9
9
 
10
10
  # The constructor.
11
- # @param [HttpMethodEnum] The HTTP method.
12
- # @param [String] The URL to send the request to.
13
- # @param [Hash, Optional] The headers for the HTTP Request.
14
- # @param [Hash, Optional] The parameters for the HTTP Request.
11
+ # @param [HttpMethodEnum] http_method The HTTP method.
12
+ # @param [String] query_url The URL to send the request to.
13
+ # @param [Hash, Optional] headers The headers for the HTTP Request.
14
+ # @param [Hash, Optional] parameters The parameters for the HTTP Request.
15
15
  def initialize(http_method,
16
16
  query_url,
17
17
  headers: {},
@@ -23,22 +23,22 @@ module MessageMediaMessages
23
23
  end
24
24
 
25
25
  # Add a header to the HttpRequest.
26
- # @param [String] The name of the header.
27
- # @param [String] The value of the header.
26
+ # @param [String] name The name of the header.
27
+ # @param [String] value The value of the header.
28
28
  def add_header(name, value)
29
29
  @headers[name] = value
30
30
  end
31
31
 
32
32
  # Add a parameter to the HttpRequest.
33
- # @param [String] The name of the parameter.
34
- # @param [String] The value of the parameter.
33
+ # @param [String] name The name of the parameter.
34
+ # @param [String] value The value of the parameter.
35
35
  def add_parameter(name, value)
36
36
  @parameters[name] = value
37
37
  end
38
38
 
39
39
  # Add a query parameter to the HttpRequest.
40
- # @param [String] The name of the query parameter.
41
- # @param [String] The value of the query parameter.
40
+ # @param [String] name The name of the query parameter.
41
+ # @param [String] value The value of the query parameter.
42
42
  def add_query_parameter(name, value)
43
43
  @query_url = APIHelper.append_url_with_query_parameters(@query_url,
44
44
  name => value)
@@ -7,9 +7,9 @@ module MessageMediaMessages
7
7
  attr_accessor :status_code, :headers, :raw_body
8
8
 
9
9
  # The constructor
10
- # @param [Integer] The status code returned by the server.
11
- # @param [Hash] The headers sent by the server in the response.
12
- # @param [String] The raw body of the response.
10
+ # @param [Integer] status_code The status code returned by the server.
11
+ # @param [Hash] headers The headers sent by the server in the response.
12
+ # @param [String] raw_body The raw body of the response.
13
13
  def initialize(status_code,
14
14
  headers,
15
15
  raw_body)
@@ -29,11 +29,14 @@ module MessageMediaMessages
29
29
  end
30
30
 
31
31
  # Initializer with authentication and configuration parameters.
32
- def initialize(basic_auth_user_name: nil, basic_auth_password: nil)
33
- Configuration.basic_auth_user_name = basic_auth_user_name if
34
- basic_auth_user_name
35
- Configuration.basic_auth_password = basic_auth_password if
36
- basic_auth_password
32
+ def initialize(auth_user_name: nil, auth_password: nil, use_hmac: false)
33
+ if (use_hmac == false)
34
+ Configuration.basic_auth_user_name = auth_user_name
35
+ Configuration.basic_auth_password = auth_password
36
+ else
37
+ Configuration.hmac_auth_user_name = auth_user_name
38
+ Configuration.hmac_auth_password = auth_password
39
+ end
37
40
  end
38
41
  end
39
42
  end
@@ -3,9 +3,11 @@
3
3
  require 'json'
4
4
  require 'test/unit'
5
5
  require 'message_media_messages.rb'
6
+ require 'message_media_messages/configuration.rb'
6
7
  require_relative '../test_helper.rb'
7
8
  require_relative '../http_response_catcher.rb'
8
9
 
10
+ # noinspection RubyClassVariableUsageInspection
9
11
  class ControllerTestBase < Test::Unit::TestCase
10
12
  include MessageMediaMessages
11
13
 
@@ -19,7 +21,8 @@ class ControllerTestBase < Test::Unit::TestCase
19
21
  @@request_timeout = 30
20
22
  @@assert_precision = 0.01
21
23
 
22
-
24
+ Configuration.basic_auth_user_name = ENV['MessageMediaApiTestsKey']
25
+ Configuration.basic_auth_password = ENV['MessageMediaApiTestsSecret']
23
26
  end
24
27
 
25
28
  # Called once before every test case.
@@ -1,131 +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 DeliveryReportsControllerTests < ControllerTestBase
6
- # Called only once for the class before any test has executed
7
- def self.startup
8
- self.controller = @@api_client.delivery_reports
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 DeliveryReportsControllerTests < ControllerTestBase
7
+ # Called only once for the class before any test has executed
8
+ def self.startup
9
+ self.controller = @@api_client.delivery_reports
10
+ end
11
+
11
12
  # Check for any delivery reports that have been received.
12
- #Delivery reports are a notification of the change in status of a message as it is being processed.
13
- #Each request to the check delivery reports endpoint will return any delivery reports received that
14
- #have not yet been confirmed using the confirm delivery reports endpoint. A response from the check
15
- #delivery reports endpoint will have the following structure:
16
- #```json
17
- #{
18
- # "delivery_reports": [
19
- # {
20
- # "callback_url": "https://my.callback.url.com",
21
- # "delivery_report_id": "01e1fa0a-6e27-4945-9cdb-18644b4de043",
22
- # "source_number": "+61491570157",
23
- # "date_received": "2017-05-20T06:30:37.642Z",
24
- # "status": "enroute",
25
- # "delay": 0,
26
- # "submitted_date": "2017-05-20T06:30:37.639Z",
27
- # "original_text": "My first message!",
28
- # "message_id": "d781dcab-d9d8-4fb2-9e03-872f07ae94ba",
29
- # "vendor_account_id": {
30
- # "vendor_id": "MessageMedia",
31
- # "account_id": "MyAccount"
32
- # },
33
- # "metadata": {
34
- # "key1": "value1",
35
- # "key2": "value2"
36
- # }
37
- # },
38
- # {
39
- # "callback_url": "https://my.callback.url.com",
40
- # "delivery_report_id": "0edf9022-7ccc-43e6-acab-480e93e98c1b",
41
- # "source_number": "+61491570158",
42
- # "date_received": "2017-05-21T01:46:42.579Z",
43
- # "status": "enroute",
44
- # "delay": 0,
45
- # "submitted_date": "2017-05-21T01:46:42.574Z",
46
- # "original_text": "My second message!",
47
- # "message_id": "fbb3b3f5-b702-4d8b-ab44-65b2ee39a281",
48
- # "vendor_account_id": {
49
- # "vendor_id": "MessageMedia",
50
- # "account_id": "MyAccount"
51
- # },
52
- # "metadata": {
53
- # "key1": "value1",
54
- # "key2": "value2"
55
- # }
56
- # }
57
- # ]
58
- #}
59
- #```
60
- #Each delivery report will contain details about the message, including any metadata specified
61
- #and the new status of the message (as each delivery report indicates a change in status of a
62
- #message) and the timestamp at which the status changed. Every delivery report will have a
63
- #unique delivery report ID for use with the confirm delivery reports endpoint.
64
- #*Note: The source number and destination number properties in a delivery report are the inverse of
65
- #those specified in the message that the delivery report relates to. The source number of the
66
- #delivery report is the destination number of the original message.*
67
- #Subsequent requests to the check delivery reports endpoint will return the same delivery reports
68
- #and a maximum of 100 delivery reports will be returned in each request. Applications should use the
69
- #confirm delivery reports endpoint in the following pattern so that delivery reports that have been
70
- #processed are no longer returned in subsequent check delivery reports requests.
71
- #1. Call check delivery reports endpoint
72
- #2. Process each delivery report
73
- #3. Confirm all processed delivery reports using the confirm delivery reports endpoint
74
- #*Note: It is recommended to use the Webhooks feature to receive reply messages rather than
75
- #polling the check delivery reports endpoint.*
76
- def test_check_delivery_reports_1()
77
-
78
- # Perform the API call through the SDK function
79
- result = self.class.controller.get_check_delivery_reports()
80
-
81
- # Test response code
82
- assert_equal(@response_catcher.response.status_code, 200)
83
-
84
- # Test headers
85
- expected_headers = {}
86
- expected_headers['content-type'] = nil
87
-
88
- assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
89
-
90
- # Test whether the captured response is as we expected
91
- assert_not_nil(result)
92
- assert_equal('{ "delivery_reports": [ { "callback_url": "https://my.callback.url.com", "delivery_report_id": "01e1fa0a-6e27-4945-9cdb-18644b4de043", "source_number": "+61491570157", "date_received": "2017-05-20T06:30:37.642Z", "status": "enroute", "delay": 0, "submitted_date": "2017-05-20T06:30:37.639Z", "original_text": "My first message!", "message_id": "d781dcab-d9d8-4fb2-9e03-872f07ae94ba", "vendor_account_id": { "vendor_id": "MessageMedia", "account_id": "MyAccount" }, "metadata": { "key1": "value1", "key2": "value2" } }, { "callback_url": "https://my.callback.url.com", "delivery_report_id": "0edf9022-7ccc-43e6-acab-480e93e98c1b", "source_number": "+61491570158", "date_received": "2017-05-21T01:46:42.579Z", "status": "enroute", "delay": 0, "submitted_date": "2017-05-21T01:46:42.574Z", "original_text": "My second message!", "message_id": "fbb3b3f5-b702-4d8b-ab44-65b2ee39a281", "vendor_account_id": { "vendor_id": "MessageMedia", "account_id": "MyAccount" }, "metadata": { "key1": "value1", "key2": "value2" } } ]}', @response_catcher.response.raw_body)
93
- end
94
-
13
+ # Delivery reports are a notification of the change in status of a message as it is being processed.
14
+ # Each request to the check delivery reports endpoint will return any delivery reports received that
15
+ # have not yet been confirmed using the confirm delivery reports endpoint. A response from the check
16
+ # delivery reports endpoint will have the following structure:
17
+ # ```json
18
+ # {
19
+ # "delivery_reports": [
20
+ # {
21
+ # "callback_url": "https://my.callback.url.com",
22
+ # "delivery_report_id": "01e1fa0a-6e27-4945-9cdb-18644b4de043",
23
+ # "source_number": "+61491570157",
24
+ # "date_received": "2017-05-20T06:30:37.642Z",
25
+ # "status": "enroute",
26
+ # "delay": 0,
27
+ # "submitted_date": "2017-05-20T06:30:37.639Z",
28
+ # "original_text": "My first message!",
29
+ # "message_id": "d781dcab-d9d8-4fb2-9e03-872f07ae94ba",
30
+ # "vendor_account_id": {
31
+ # "vendor_id": "MessageMedia",
32
+ # "account_id": "MyAccount"
33
+ # },
34
+ # "metadata": {
35
+ # "key1": "value1",
36
+ # "key2": "value2"
37
+ # }
38
+ # },
39
+ # {
40
+ # "callback_url": "https://my.callback.url.com",
41
+ # "delivery_report_id": "0edf9022-7ccc-43e6-acab-480e93e98c1b",
42
+ # "source_number": "+61491570158",
43
+ # "date_received": "2017-05-21T01:46:42.579Z",
44
+ # "status": "enroute",
45
+ # "delay": 0,
46
+ # "submitted_date": "2017-05-21T01:46:42.574Z",
47
+ # "original_text": "My second message!",
48
+ # "message_id": "fbb3b3f5-b702-4d8b-ab44-65b2ee39a281",
49
+ # "vendor_account_id": {
50
+ # "vendor_id": "MessageMedia",
51
+ # "account_id": "MyAccount"
52
+ # },
53
+ # "metadata": {
54
+ # "key1": "value1",
55
+ # "key2": "value2"
56
+ # }
57
+ # }
58
+ # ]
59
+ # }
60
+ # ```
61
+ # Each delivery report will contain details about the message, including any metadata specified
62
+ # and the new status of the message (as each delivery report indicates a change in status of a
63
+ # message) and the timestamp at which the status changed. Every delivery report will have a
64
+ # unique delivery report ID for use with the confirm delivery reports endpoint.
65
+ # *Note: The source number and destination number properties in a delivery report are the inverse of
66
+ # those specified in the message that the delivery report relates to. The source number of the
67
+ # delivery report is the destination number of the original message.*
68
+ # Subsequent requests to the check delivery reports endpoint will return the same delivery reports
69
+ # and a maximum of 100 delivery reports will be returned in each request. Applications should use the
70
+ # confirm delivery reports endpoint in the following pattern so that delivery reports that have been
71
+ # processed are no longer returned in subsequent check delivery reports requests.
72
+ # 1. Call check delivery reports endpoint
73
+ # 2. Process each delivery report
74
+ # 3. Confirm all processed delivery reports using the confirm delivery reports endpoint
75
+ # *Note: It is recommended to use the Webhooks feature to receive reply messages rather than
76
+ # polling the check delivery reports endpoint.*
77
+ def test_check_delivery_reports_1
78
+
79
+ # Perform the API call through the SDK function
80
+ result = self.class.controller.get_check_delivery_reports
81
+
82
+ # Test response code
83
+ assert_equal(@response_catcher.response.status_code, 200)
84
+
85
+ # Test headers
86
+ expected_headers = {}
87
+ expected_headers['content-type'] = nil
88
+
89
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
90
+
91
+ # Test whether the captured response is as we expected
92
+ assert_not_nil(result)
93
+ assert_true(@response_catcher.response.raw_body.index('{"delivery_reports":[') >= 0, "Must get our delivery reports")
94
+ end
95
+
96
+ # Make sure our SDK fails when passed an invalid account id
97
+ def test_check_delivery_reports_with_invalid_account
98
+ begin
99
+ # Perform the API call through the SDK function
100
+ self.class.controller.get_check_delivery_reports('INVALID ACCOUNT')
101
+ rescue APIException => api_exception
102
+ assert_equal('HTTP Response Not OK. {"message":"Invalid account \'INVALID ACCOUNT\' in header Account"}' + "\n",
103
+ api_exception.message,'Make sure we''ve got our error message')
104
+ # Test response code
105
+ assert_equal(@response_catcher.response.status_code, 403)
106
+ end
107
+ end
108
+
95
109
  # Mark a delivery report as confirmed so it is no longer return in check delivery reports requests.
96
- #The confirm delivery reports endpoint is intended to be used in conjunction with the check delivery
97
- #reports endpoint to allow for robust processing of delivery reports. Once one or more delivery
98
- #reports have been processed, they can then be confirmed using the confirm delivery reports endpoint so they
99
- #are no longer returned in subsequent check delivery reports requests.
100
- #The confirm delivery reports endpoint takes a list of delivery report IDs as follows:
101
- #```json
102
- #{
103
- # "delivery_report_ids": [
104
- # "011dcead-6988-4ad6-a1c7-6b6c68ea628d",
105
- # "3487b3fa-6586-4979-a233-2d1b095c7718",
106
- # "ba28e94b-c83d-4759-98e7-ff9c7edb87a1"
107
- # ]
108
- #}
109
- #```
110
- #Up to 100 delivery reports can be confirmed in a single confirm delivery reports request.
111
- def test_confirm_delivery_reports_as_received_1()
112
- # Parameters for the API call
113
- body = ConfirmDeliveryReportsAsReceivedRequest.from_hash(JSON.parse(
114
- '{"delivery_report_ids":["011dcead-6988-4ad6-a1c7-6b6c68ea628d","3487b3fa-65'\
115
- '86-4979-a233-2d1b095c7718","ba28e94b-c83d-4759-98e7-ff9c7edb87a1"]}'
116
- ))
117
-
118
- # Perform the API call through the SDK function
119
- result = self.class.controller.create_confirm_delivery_reports_as_received(body)
120
-
121
- # Test response code
122
- assert_equal(@response_catcher.response.status_code, 202)
123
-
124
- # Test headers
125
- expected_headers = {}
126
- expected_headers['content-type'] = nil
127
-
128
- assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
129
- end
130
-
131
- end
110
+ # The confirm delivery reports endpoint is intended to be used in conjunction with the check delivery
111
+ # reports endpoint to allow for robust processing of delivery reports. Once one or more delivery
112
+ # reports have been processed, they can then be confirmed using the confirm delivery reports endpoint so they
113
+ # are no longer returned in subsequent check delivery reports requests.
114
+ # The confirm delivery reports endpoint takes a list of delivery report IDs as follows:
115
+ # ```json
116
+ # {
117
+ # "delivery_report_ids": [
118
+ # "011dcead-6988-4ad6-a1c7-6b6c68ea628d",
119
+ # "3487b3fa-6586-4979-a233-2d1b095c7718",
120
+ # "ba28e94b-c83d-4759-98e7-ff9c7edb87a1"
121
+ # ]
122
+ # }
123
+ # ```
124
+ # Up to 100 delivery reports can be confirmed in a single confirm delivery reports request.
125
+ def test_confirm_delivery_reports_as_received_1
126
+ # Parameters for the API call
127
+ body = ConfirmDeliveryReportsAsReceivedRequest.from_hash(JSON.parse(
128
+ '{"delivery_report_ids":["011dcead-6988-4ad6-a1c7-6b6c68ea628d","3487b3fa-65'\
129
+ '86-4979-a233-2d1b095c7718","ba28e94b-c83d-4759-98e7-ff9c7edb87a1"]}'
130
+ ))
131
+
132
+ # Perform the API call through the SDK function
133
+ self.class.controller.create_confirm_delivery_reports_as_received(body)
134
+
135
+ # Test response code
136
+ assert_equal(@response_catcher.response.status_code, 202)
137
+
138
+ # Test headers
139
+ expected_headers = {}
140
+ expected_headers['content-type'] = nil
141
+
142
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
143
+ end
144
+
145
+ # Make sure our SDK fails when passed an invalid account id
146
+ def test_confirm_delivery_reports_as_received_with_invalid_account
147
+ begin
148
+ # Perform the API call through the SDK function
149
+ body = ConfirmDeliveryReportsAsReceivedRequest.from_hash(JSON.parse(
150
+ '{"delivery_report_ids":["011dcead-6988-4ad6-a1c7-6b6c68ea628d","3487b3fa-65'\
151
+ '86-4979-a233-2d1b095c7718","ba28e94b-c83d-4759-98e7-ff9c7edb87a1"]}'
152
+ ))
153
+
154
+ # Perform the API call through the SDK function
155
+ self.class.controller.create_confirm_delivery_reports_as_received(body, '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