Module: Mailkube::Resources::ScheduledEmailRequests

Defined in:
lib/mailkube/resources/scheduled_email_requests.rb,
sig/mailkube/resources/scheduled_email_requests.rbs

Overview

The request builders for the scheduled-emails routes.

Standalone builders, one per verb, exactly as the contract requires — and here they earn their keep twice over. Eight verbs across two collections differ only in a path constant and a method string; written inline they would be eight near-identical bodies and the duplication gate would say so. Funnelled through ScheduledEmailRequests.item they are one-liners, and the escaping rule is applied in exactly one place.

Constant Summary collapse

COLLECTION =

The collection path.

Returns:

  • (String)
"scheduled-emails"
BATCHES =

The batch sub-collection path. Sub-resources mirror sub-paths, so this is a path rather than a suffix bolted onto a verb name.

Returns:

  • (String)
"scheduled-emails/batches"

Class Method Summary collapse

Class Method Details

.batch_cancel(batch_id) ⇒ RequestSpec

Returns the batch cancellation request.

Parameters:

  • batch_id (String)

    the batch label.

  • (String)

Returns:



75
# File 'lib/mailkube/resources/scheduled_email_requests.rb', line 75

def self.batch_cancel(batch_id) = item(BATCHES, batch_id, "DELETE")

.batch_update(batch_id, body) ⇒ RequestSpec

Returns the batch reschedule request.

Parameters:

  • batch_id (String)

    the batch label.

  • body (Hash)

    the new due time. There is deliberately no batch_id in it: the batch is identified by the path, and the server rejects a second one in the body rather than let it decide which batch actually moves.

  • (String)
  • (Hash[String, untyped])

Returns:



71
# File 'lib/mailkube/resources/scheduled_email_requests.rb', line 71

def self.batch_update(batch_id, body) = item(BATCHES, batch_id, "PATCH", body)

.cancel(email_id) ⇒ RequestSpec

Returns the cancellation request.

Parameters:

  • email_id (String)

    the scheduled email's id.

  • (String)

Returns:



64
# File 'lib/mailkube/resources/scheduled_email_requests.rb', line 64

def self.cancel(email_id) = item(COLLECTION, email_id, "DELETE")

.get(email_id) ⇒ RequestSpec

Returns the retrieval request.

Parameters:

  • email_id (String)

    the scheduled email's id.

  • (String)

Returns:



55
# File 'lib/mailkube/resources/scheduled_email_requests.rb', line 55

def self.get(email_id) = item(COLLECTION, email_id, "GET")

.list(status: nil, batch_id: nil, scheduled_at_gte: nil, scheduled_at_lte: nil, page: nil) ⇒ RequestSpec

Build the listing request.

Filters are named here rather than splatted so the five the API supports exist in exactly one place. An omitted filter is dropped by Serialization.query, and no filters at all yields no query string rather than a bare ?.

Parameters:

  • status (String, Array<String>, nil) (defaults to: nil)

    one status, or several.

  • batch_id (String, nil) (defaults to: nil)

    only emails grouped under this batch label.

  • scheduled_at_gte (Time, String, nil) (defaults to: nil)

    only emails due at or after this instant.

  • scheduled_at_lte (Time, String, nil) (defaults to: nil)

    only emails due at or before this instant.

  • page (Integer, nil) (defaults to: nil)

    the 1-based page number.

Returns:



43
44
45
46
47
# File 'lib/mailkube/resources/scheduled_email_requests.rb', line 43

def self.list(status: nil, batch_id: nil, scheduled_at_gte: nil, scheduled_at_lte: nil, page: nil)
  filters = { status: status, batch_id: batch_id, scheduled_at_gte: scheduled_at_gte,
              scheduled_at_lte: scheduled_at_lte, page: page }
  RequestSpec.new(path: COLLECTION, method: "GET", params: Serialization.query(filters))
end

.page(url) ⇒ RequestSpec

Returns the request for that page.

Parameters:

  • url (String)

    an absolute page link the API issued; it carries its own query.

  • (String)

Returns:



51
# File 'lib/mailkube/resources/scheduled_email_requests.rb', line 51

def self.page(url) = RequestSpec.new(path: url, method: "GET")

.update(email_id, body) ⇒ RequestSpec

Returns the reschedule request.

Parameters:

  • email_id (String)

    the scheduled email's id.

  • body (Hash)

    the new due time, and optionally a batch to move the email into.

  • (String)
  • (Hash[String, untyped])

Returns:



60
# File 'lib/mailkube/resources/scheduled_email_requests.rb', line 60

def self.update(email_id, body) = item(COLLECTION, email_id, "PATCH", body)