Class: MessageMediaMessages::DeliveryReportsController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/message_media_messages/controllers/delivery_reports_controller.rb

Overview

DeliveryReportsController

Class Attribute Summary collapse

Attributes inherited from BaseController

#http_call_back, #http_client

Instance Method Summary collapse

Methods inherited from BaseController

#execute_request, #initialize, #validate_parameters, #validate_response

Constructor Details

This class inherits a constructor from MessageMediaMessages::BaseController

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



12
13
14
# File 'lib/message_media_messages/controllers/delivery_reports_controller.rb', line 12

def instance
  @instance
end

Instance Method Details

#check_delivery_reportsObject

Check for any delivery reports that have been received. Delivery reports are a notification of the change in status of a message as it is being processed. Each request to the check delivery reports endpoint will return any delivery reports received that have not yet been confirmed using the confirm delivery reports endpoint. A response from the check delivery reports endpoint will have the following structure: “‘json {

"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"
        }
    }
]

} “‘ Each delivery report will contain details about the message, including any metadata specified and the new status of the message (as each delivery report indicates a change in status of a message) and the timestamp at which the status changed. Every delivery report will have a unique delivery report ID for use with the confirm delivery reports endpoint. *Note: The source number and destination number properties in a delivery report are the inverse of those specified in the message that the delivery report relates to. The source number of the delivery report is the destination number of the original message.* Subsequent requests to the check delivery reports endpoint will return the same delivery reports and a maximum of 100 delivery reports will be returned in each request. Applications should use the confirm delivery reports endpoint in the following pattern so that delivery reports that have been processed are no longer returned in subsequent check delivery reports requests.

  1. Call check delivery reports endpoint

  2. Process each delivery report

  3. Confirm all processed delivery reports using the confirm delivery

reports endpoint *Note: It is recommended to use the Webhooks feature to receive reply messages rather than polling the check delivery reports endpoint.*

Returns:

  • CheckDeliveryReportsResponse response from the API call



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/message_media_messages/controllers/delivery_reports_controller.rb', line 100

def check_delivery_reports
  # Prepare query url.
  _path_url = '/v1/delivery_reports'
  _query_builder = Configuration.base_uri.dup
  _query_builder << _path_url
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = @http_client.get(
    _query_url,
    headers: _headers
  )
  AuthManager.apply(_request, _path_url)
  _context = execute_request(_request)
  validate_response(_context)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
  CheckDeliveryReportsResponse.from_hash(decoded)
end

#confirm_delivery_reports_as_received(body) ⇒ Object

Mark a delivery report as confirmed so it is no longer return in check delivery reports requests. The confirm delivery reports endpoint is intended to be used in conjunction with the check delivery reports endpoint to allow for robust processing of delivery reports. Once one or more delivery reports have been processed, they can then be confirmed using the confirm delivery reports endpoint so they are no longer returned in subsequent check delivery reports requests. The confirm delivery reports endpoint takes a list of delivery report IDs as follows: “‘json

"delivery_report_ids": [
    "011dcead-6988-4ad6-a1c7-6b6c68ea628d",
    "3487b3fa-6586-4979-a233-2d1b095c7718",
    "ba28e94b-c83d-4759-98e7-ff9c7edb87a1"
]

“‘ Up to 100 delivery reports can be confirmed in a single confirm delivery reports request. Example:

Parameters:

Returns:

  • Mixed response from the API call



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/message_media_messages/controllers/delivery_reports_controller.rb', line 151

def confirm_delivery_reports_as_received(body)
  # Prepare query url.
  _path_url = '/v1/delivery_reports/confirmed'
  _query_builder = Configuration.base_uri.dup
  _query_builder << _path_url
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'content-type' => 'application/json; charset=utf-8'
  }

  # Prepare and execute HttpRequest.
  _request = @http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  AuthManager.apply(_request, _path_url, body.to_json)
  _context = execute_request(_request)
  validate_response(_context)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_context.response.raw_body) unless
    _context.response.raw_body.nil? ||
    _context.response.raw_body.to_s.strip.empty?
  decoded
end

#instanceObject



15
16
17
# File 'lib/message_media_messages/controllers/delivery_reports_controller.rb', line 15

def instance
  self.class.instance
end