Class: Courier::MessagesClient
- Inherits:
-
Object
- Object
- Courier::MessagesClient
- Defined in:
- lib/trycourier/messages/client.rb
Instance Attribute Summary collapse
-
#request_client ⇒ Object
readonly
Returns the value of attribute request_client.
Instance Method Summary collapse
- #archive(request_id:, request_options: nil) ⇒ Void
-
#cancel(message_id:, request_options: nil) ⇒ Messages::MessageDetails
Cancel a message that is currently in the process of being delivered.
-
#get(message_id:, request_options: nil) ⇒ Messages::MessageDetails
Fetch the status of a message you’ve previously sent.
- #get_content(message_id:, request_options: nil) ⇒ Messages::RenderOutputResponse
-
#get_history(message_id:, type: nil, request_options: nil) ⇒ Messages::MessageHistoryResponse
Fetch the array of events of a message you’ve previously sent.
- #initialize(request_client:) ⇒ MessagesClient constructor
-
#list(archived: nil, cursor: nil, event: nil, list: nil, message_id: nil, notification: nil, recipient: nil, status: nil, tags: nil, enqueued_after: nil, trace_id: nil, request_options: nil) ⇒ Messages::ListMessagesResponse
Fetch the statuses of messages you’ve previously sent.
Constructor Details
#initialize(request_client:) ⇒ MessagesClient
16 17 18 19 |
# File 'lib/trycourier/messages/client.rb', line 16 def initialize(request_client:) # @type [RequestClient] @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Object (readonly)
Returns the value of attribute request_client.
12 13 14 |
# File 'lib/trycourier/messages/client.rb', line 12 def request_client @request_client end |
Instance Method Details
#archive(request_id:, request_options: nil) ⇒ Void
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/trycourier/messages/client.rb', line 138 def archive(request_id:, request_options: nil) @request_client.conn.put("/requests/#{request_id}/archive") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end end |
#cancel(message_id:, request_options: nil) ⇒ Messages::MessageDetails
Cancel a message that is currently in the process of being delivered. A well-formatted API call to the cancel message API will return either ‘200` status code for a successful cancellation or `409` status code for an unsuccessful cancellation. Both cases will include the actual message record in the response body (see details below).
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/trycourier/messages/client.rb', line 85 def cancel(message_id:, request_options: nil) response = @request_client.conn.post("/messages/#{}/cancel") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers["Idempotency-Key"] = .idempotency_key unless &.idempotency_key.nil? unless &.idempotency_expiry.nil? req.headers["X-Idempotency-Expiration"] = .idempotency_expiry end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end Messages::MessageDetails.from_json(json_object: response.body) end |
#get(message_id:, request_options: nil) ⇒ Messages::MessageDetails
Fetch the status of a message you’ve previously sent.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/trycourier/messages/client.rb', line 68 def get(message_id:, request_options: nil) response = @request_client.conn.get("/messages/#{}") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end Messages::MessageDetails.from_json(json_object: response.body) end |
#get_content(message_id:, request_options: nil) ⇒ Messages::RenderOutputResponse
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/trycourier/messages/client.rb', line 123 def get_content(message_id:, request_options: nil) response = @request_client.conn.get("/messages/#{}/output") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end Messages::RenderOutputResponse.from_json(json_object: response.body) end |
#get_history(message_id:, type: nil, request_options: nil) ⇒ Messages::MessageHistoryResponse
Fetch the array of events of a message you’ve previously sent.
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/trycourier/messages/client.rb', line 107 def get_history(message_id:, type: nil, request_options: nil) response = @request_client.conn.get("/messages/#{}/history") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "type": type }.compact end Messages::MessageHistoryResponse.from_json(json_object: response.body) end |
#list(archived: nil, cursor: nil, event: nil, list: nil, message_id: nil, notification: nil, recipient: nil, status: nil, tags: nil, enqueued_after: nil, trace_id: nil, request_options: nil) ⇒ Messages::ListMessagesResponse
Fetch the statuses of messages you’ve previously sent.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/trycourier/messages/client.rb', line 36 def list(archived: nil, cursor: nil, event: nil, list: nil, message_id: nil, notification: nil, recipient: nil, status: nil, tags: nil, enqueued_after: nil, trace_id: nil, request_options: nil) response = @request_client.conn.get("/messages") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "archived": archived, "cursor": cursor, "event": event, "list": list, "messageId": , "notification": notification, "recipient": recipient, "status": status, "tags": , "enqueued_after": enqueued_after, "traceId": trace_id }.compact end Messages::ListMessagesResponse.from_json(json_object: response.body) end |