Class: Courier::AsyncNotificationsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/notifications/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ AsyncNotificationsClient

Parameters:



190
191
192
193
# File 'lib/trycourier/notifications/client.rb', line 190

def initialize(request_client:)
  # @type [AsyncRequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



186
187
188
# File 'lib/trycourier/notifications/client.rb', line 186

def request_client
  @request_client
end

Instance Method Details

#cancel_submission(id:, submission_id:, request_options: nil) ⇒ Void

Parameters:

  • id (String)
  • submission_id (String)
  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/trycourier/notifications/client.rb', line 366

def cancel_submission(id:, submission_id:, request_options: nil)
  Async do
    @request_client.conn.delete("/notifications/#{id}/#{submission_id}/checks") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
  end
end

#get_content(id:, request_options: nil) ⇒ Notifications::NotificationGetContentResponse

Parameters:

Returns:



216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/trycourier/notifications/client.rb', line 216

def get_content(id:, request_options: nil)
  Async do
    response = @request_client.conn.get("/notifications/#{id}/content") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
    Notifications::NotificationGetContentResponse.from_json(json_object: response.body)
  end
end

#get_draft_content(id:, request_options: nil) ⇒ Notifications::NotificationGetContentResponse

Parameters:

Returns:



233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/trycourier/notifications/client.rb', line 233

def get_draft_content(id:, request_options: nil)
  Async do
    response = @request_client.conn.get("/notifications/#{id}/draft/content") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
    Notifications::NotificationGetContentResponse.from_json(json_object: response.body)
  end
end

#get_submission_checks(id:, submission_id:, request_options: nil) ⇒ Notifications::SubmissionChecksGetResponse

Parameters:

  • id (String)
  • submission_id (String)
  • request_options (RequestOptions) (defaults to: nil)

Returns:



325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/trycourier/notifications/client.rb', line 325

def get_submission_checks(id:, submission_id:, request_options: nil)
  Async do
    response = @request_client.conn.get("/notifications/#{id}/#{submission_id}/checks") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
    Notifications::SubmissionChecksGetResponse.from_json(json_object: response.body)
  end
end

#list(cursor: nil, request_options: nil) ⇒ Notifications::NotificationListResponse

Parameters:

  • cursor (String) (defaults to: nil)
  • request_options (RequestOptions) (defaults to: nil)

Returns:



198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/trycourier/notifications/client.rb', line 198

def list(cursor: nil, request_options: nil)
  Async do
    response = @request_client.conn.get("/notifications") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.params = { **(request_options&.additional_query_parameters || {}), "cursor": cursor }.compact
    end
    Notifications::NotificationListResponse.from_json(json_object: response.body)
  end
end

#replace_submission_checks(id:, submission_id:, checks:, request_options: nil) ⇒ Notifications::SubmissionChecksReplaceResponse

Parameters:

  • id (String)
  • submission_id (String)
  • checks (Array<Hash>)

    Request of type Array<Notifications::BaseCheck>, as a Hash

    • :id (String)

    • :status (Notifications::CheckStatus)

    • :type (String)

  • request_options (RequestOptions) (defaults to: nil)

Returns:



347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/trycourier/notifications/client.rb', line 347

def replace_submission_checks(id:, submission_id:, checks:, request_options: nil)
  Async do
    response = @request_client.conn.put("/notifications/#{id}/#{submission_id}/checks") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = { **(request_options&.additional_body_parameters || {}), checks: checks }.compact
    end
    Notifications::SubmissionChecksReplaceResponse.from_json(json_object: response.body)
  end
end

#update_draft_variations(id:, blocks: nil, channels: nil, request_options: nil) ⇒ Void

Parameters:

  • id (String)
  • blocks (Array<Hash>) (defaults to: nil)

    Request of type Array<Notifications::NotificationBlock>, as a Hash

    • :alias_ (String)

    • :context (String)

    • :id (String)

    • :type (Notifications::BlockType)

    • :content (Hash)

    • :locales (Hash=> String)

    • :checksum (String)

  • channels (Array<Hash>) (defaults to: nil)

    Request of type Array<Notifications::NotificationChannel>, as a Hash

    • :id (String)

    • :type (String)

    • :content (Hash)

      • :subject (String)

      • :title (String)

    • :locales (Hash=> String)

    • :checksum (String)

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/trycourier/notifications/client.rb', line 303

def update_draft_variations(id:, blocks: nil, channels: nil, request_options: nil)
  Async do
    @request_client.conn.post("/notifications/#{id}/draft/variations") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        blocks: blocks,
        channels: channels
      }.compact
    end
  end
end

#update_variations(id:, blocks: nil, channels: nil, request_options: nil) ⇒ Void

Parameters:

  • id (String)
  • blocks (Array<Hash>) (defaults to: nil)

    Request of type Array<Notifications::NotificationBlock>, as a Hash

    • :alias_ (String)

    • :context (String)

    • :id (String)

    • :type (Notifications::BlockType)

    • :content (Hash)

    • :locales (Hash=> String)

    • :checksum (String)

  • channels (Array<Hash>) (defaults to: nil)

    Request of type Array<Notifications::NotificationChannel>, as a Hash

    • :id (String)

    • :type (String)

    • :content (Hash)

      • :subject (String)

      • :title (String)

    • :locales (Hash=> String)

    • :checksum (String)

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/trycourier/notifications/client.rb', line 266

def update_variations(id:, blocks: nil, channels: nil, request_options: nil)
  Async do
    @request_client.conn.post("/notifications/#{id}/variations") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        blocks: blocks,
        channels: channels
      }.compact
    end
  end
end