Class: Courier::Resources::Notifications
- Inherits:
-
Object
- Object
- Courier::Resources::Notifications
- Defined in:
- lib/courier/resources/notifications.rb,
lib/courier/resources/notifications/checks.rb,
sig/courier/resources/notifications.rbs,
sig/courier/resources/notifications/checks.rbs
Overview
Create, update, version, publish, and localize notification templates and their content.
Defined Under Namespace
Classes: Checks
Instance Attribute Summary collapse
-
#checks ⇒ Courier::Resources::Notifications::Checks
readonly
Create, update, version, publish, and localize notification templates and their content.
Instance Method Summary collapse
-
#archive(id, request_options: {}) ⇒ nil
Archives a notification template, preventing new sends from referencing it.
-
#create(notification:, state: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse
Some parameter documentations has been truncated, see Models::NotificationCreateParams for more details.
-
#duplicate(id, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse
Copies a notification template within the same workspace and environment, appending " COPY" to the title.
-
#initialize(client:) ⇒ Notifications
constructor
private
A new instance of Notifications.
-
#list(cursor: nil, event_id: nil, notes: nil, request_options: {}) ⇒ Courier::Models::NotificationListResponse
Lists the workspace's notification templates.
-
#list_versions(id, cursor: nil, limit: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateVersionListResponse
Returns a notification template's published versions, most recent first, for comparison or rollback.
-
#publish(id, version: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ nil
Some parameter documentations has been truncated, see Models::NotificationPublishParams for more details.
-
#put_content(id, content:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse
Replaces all Elemental content in a template, overwriting every existing element.
-
#put_element(element_id, id:, type:, channels: nil, data: nil, if_: nil, loop_: nil, ref: nil, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse
Replaces one Elemental element in a template, addressed by its element id.
-
#put_locale(locale_id, id:, elements:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse
Sets locale-specific content overrides for a template.
-
#replace(id, notification:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse
Some parameter documentations has been truncated, see Models::NotificationReplaceParams for more details.
-
#retrieve(id, version: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse
Some parameter documentations has been truncated, see Models::NotificationRetrieveParams for more details.
-
#retrieve_content(id, version: nil, request_options: {}) ⇒ Courier::Models::NotificationContentGetResponse, Courier::Models::NotificationGetContent
Some parameter documentations has been truncated, see Models::NotificationRetrieveContentParams for more details.
Constructor Details
#initialize(client:) ⇒ Notifications
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Notifications.
376 377 378 379 |
# File 'lib/courier/resources/notifications.rb', line 376 def initialize(client:) @client = client @checks = Courier::Resources::Notifications::Checks.new(client: client) end |
Instance Attribute Details
#checks ⇒ Courier::Resources::Notifications::Checks (readonly)
Create, update, version, publish, and localize notification templates and their content.
11 12 13 |
# File 'lib/courier/resources/notifications.rb', line 11 def checks @checks end |
Instance Method Details
#archive(id, request_options: {}) ⇒ nil
Archives a notification template, preventing new sends from referencing it. The template stays retrievable for its version history.
117 118 119 120 121 122 123 124 |
# File 'lib/courier/resources/notifications.rb', line 117 def archive(id, params = {}) @client.request( method: :delete, path: ["notifications/%1$s", id], model: NilClass, options: params[:request_options] ) end |
#create(notification:, state: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse
Some parameter documentations has been truncated, see Models::NotificationCreateParams for more details.
Create a notification template. Requires all fields in the notification object. Templates are created in draft state by default.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/courier/resources/notifications.rb', line 34 def create(params) parsed, = Courier::NotificationCreateParams.dump_request(params) header_params = {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"} @client.request( method: :post, path: "notifications", headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: Courier::NotificationTemplateResponse, options: ) end |
#duplicate(id, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse
Copies a notification template within the same workspace and environment, appending " COPY" to the title. The copy is standalone and independently editable.
139 140 141 142 143 144 145 146 |
# File 'lib/courier/resources/notifications.rb', line 139 def duplicate(id, params = {}) @client.request( method: :post, path: ["notifications/%1$s/duplicate", id], model: Courier::NotificationTemplateResponse, options: params[:request_options] ) end |
#list(cursor: nil, event_id: nil, notes: nil, request_options: {}) ⇒ Courier::Models::NotificationListResponse
Lists the workspace's notification templates. Each carries a name, tags, brand, routing, and its draft or published state.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/courier/resources/notifications.rb', line 93 def list(params = {}) parsed, = Courier::NotificationListParams.dump_request(params) query = Courier::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: "notifications", query: query, model: Courier::Models::NotificationListResponse, options: ) end |
#list_versions(id, cursor: nil, limit: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateVersionListResponse
Returns a notification template's published versions, most recent first, for comparison or rollback. Paged.
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/courier/resources/notifications.rb', line 164 def list_versions(id, params = {}) parsed, = Courier::NotificationListVersionsParams.dump_request(params) query = Courier::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: ["notifications/%1$s/versions", id], query: query, model: Courier::NotificationTemplateVersionListResponse, options: ) end |
#publish(id, version: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ nil
Some parameter documentations has been truncated, see Models::NotificationPublishParams for more details.
Publish a notification template. Publishes the current draft by default. Pass a version in the request body to publish a specific historical version.
197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/courier/resources/notifications.rb', line 197 def publish(id, params = {}) parsed, = Courier::NotificationPublishParams.dump_request(params) header_params = {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"} @client.request( method: :post, path: ["notifications/%1$s/publish", id], headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: NilClass, options: ) end |
#put_content(id, content:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse
Replaces all Elemental content in a template, overwriting every existing element. Supported for V2 templates only, not V1 blocks and channels.
227 228 229 230 231 232 233 234 235 236 |
# File 'lib/courier/resources/notifications.rb', line 227 def put_content(id, params) parsed, = Courier::NotificationPutContentParams.dump_request(params) @client.request( method: :put, path: ["notifications/%1$s/content", id], body: parsed, model: Courier::NotificationContentMutationResponse, options: ) end |
#put_element(element_id, id:, type:, channels: nil, data: nil, if_: nil, loop_: nil, ref: nil, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse
Replaces one Elemental element in a template, addressed by its element id. Supported for V2 templates only, not V1 blocks and channels.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/courier/resources/notifications.rb', line 266 def put_element(element_id, params) parsed, = Courier::NotificationPutElementParams.dump_request(params) id = parsed.delete(:id) do raise ArgumentError.new("missing required path argument #{_1}") end @client.request( method: :put, path: ["notifications/%1$s/elements/%2$s", id, element_id], body: parsed, model: Courier::NotificationContentMutationResponse, options: ) end |
#put_locale(locale_id, id:, elements:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse
Sets locale-specific content overrides for a template. Each override must reference an element that already exists in the default content.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/courier/resources/notifications.rb', line 299 def put_locale(locale_id, params) parsed, = Courier::NotificationPutLocaleParams.dump_request(params) id = parsed.delete(:id) do raise ArgumentError.new("missing required path argument #{_1}") end @client.request( method: :put, path: ["notifications/%1$s/locales/%2$s", id, locale_id], body: parsed, model: Courier::NotificationContentMutationResponse, options: ) end |
#replace(id, notification:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse
Some parameter documentations has been truncated, see Models::NotificationReplaceParams for more details.
Replaces a notification template in full, so send every field rather than only the ones you want changed. Publish separately to make it live.
333 334 335 336 337 338 339 340 341 342 |
# File 'lib/courier/resources/notifications.rb', line 333 def replace(id, params) parsed, = Courier::NotificationReplaceParams.dump_request(params) @client.request( method: :put, path: ["notifications/%1$s", id], body: parsed, model: Courier::NotificationTemplateResponse, options: ) end |
#retrieve(id, version: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse
Some parameter documentations has been truncated, see Models::NotificationRetrieveParams for more details.
Retrieve a notification template by ID. Returns the published version by default. Pass version=draft to retrieve an unpublished template.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/courier/resources/notifications.rb', line 65 def retrieve(id, params = {}) parsed, = Courier::NotificationRetrieveParams.dump_request(params) query = Courier::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: ["notifications/%1$s", id], query: query, model: Courier::NotificationTemplateResponse, options: ) end |
#retrieve_content(id, version: nil, request_options: {}) ⇒ Courier::Models::NotificationContentGetResponse, Courier::Models::NotificationGetContent
Some parameter documentations has been truncated, see Models::NotificationRetrieveContentParams for more details.
Returns a template's content and checksum. V2 templates return Elemental elements, while V1 templates return blocks and channels instead.
361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/courier/resources/notifications.rb', line 361 def retrieve_content(id, params = {}) parsed, = Courier::NotificationRetrieveContentParams.dump_request(params) query = Courier::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: ["notifications/%1$s/content", id], query: query, model: Courier::Models::NotificationRetrieveContentResponse, options: ) end |