Class: Mailkube::Resources::ScheduledEmails
- Inherits:
-
Object
- Object
- Mailkube::Resources::ScheduledEmails
- Defined in:
- lib/mailkube/resources/scheduled_emails.rb,
sig/mailkube/resources/scheduled_emails.rbs
Overview
The scheduled_emails namespace, reached as client.scheduled_emails.
Sends made with scheduled_at: are manageable here until they are due. A sent email has left
the collection, so status: "sent" is a validation error rather than an empty result.
Instance Attribute Summary collapse
-
#batches ⇒ ScheduledEmailBatches
readonly
The batch operations.
Instance Method Summary collapse
-
#cancel(email_id) ⇒ CanceledScheduledEmail
Cancel one scheduled email before it is sent.
-
#fetch_page(spec) ⇒ ScheduledEmailPage
The parsed page.
-
#get(email_id) ⇒ ScheduledEmail
Retrieve one scheduled email.
-
#initialize(transport) ⇒ ScheduledEmails
constructor
A new instance of ScheduledEmails.
-
#iter_all(status: nil, batch_id: nil, scheduled_at_gte: nil, scheduled_at_lte: nil, page: nil) ⇒ Object
A lazy
Enumerator, so abandoning the walk early costs nothing. -
#list(status: nil, batch_id: nil, scheduled_at_gte: nil, scheduled_at_lte: nil, page: nil) ⇒ ScheduledEmailPage
List one page of scheduled emails.
-
#update(email_id, scheduled_at:, batch_id: nil) ⇒ ScheduledEmail
Reschedule one scheduled email, optionally moving it into or out of a batch.
Constructor Details
#initialize(transport) ⇒ ScheduledEmails
Returns a new instance of ScheduledEmails.
51 52 53 54 55 |
# File 'lib/mailkube/resources/scheduled_emails.rb', line 51 def initialize(transport) @transport = transport @batches = ScheduledEmailBatches.new(transport) freeze end |
Instance Attribute Details
#batches ⇒ ScheduledEmailBatches (readonly)
Returns the batch operations.
48 49 50 |
# File 'lib/mailkube/resources/scheduled_emails.rb', line 48 def batches @batches end |
Instance Method Details
#cancel(email_id) ⇒ CanceledScheduledEmail
Cancel one scheduled email before it is sent.
131 132 133 |
# File 'lib/mailkube/resources/scheduled_emails.rb', line 131 def cancel(email_id) CanceledScheduledEmail.from(@transport.request_json(ScheduledEmailRequests.cancel(email_id))) end |
#fetch_page(spec) ⇒ ScheduledEmailPage
Returns the parsed page.
139 |
# File 'lib/mailkube/resources/scheduled_emails.rb', line 139 def fetch_page(spec) = ScheduledEmailPage.from(@transport.request_json(spec)) |
#get(email_id) ⇒ ScheduledEmail
Retrieve one scheduled email.
108 109 110 |
# File 'lib/mailkube/resources/scheduled_emails.rb', line 108 def get(email_id) ScheduledEmail.from(@transport.request_json(ScheduledEmailRequests.get(email_id))) end |
#iter_all(status: nil, batch_id: nil, scheduled_at_gte: nil, scheduled_at_lte: nil, page: nil) ⇒ Object
A lazy Enumerator, so abandoning the walk early costs nothing.
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/mailkube/resources/scheduled_emails.rb', line 88 def iter_all(status: nil, batch_id: nil, scheduled_at_gte: nil, scheduled_at_lte: nil, page: nil) Enumerator.new do |yielder| current = list(status: status, batch_id: batch_id, scheduled_at_gte: scheduled_at_gte, scheduled_at_lte: scheduled_at_lte, page: page) loop do current.data.each { |item| yielder << item } link = current.pagination.steps.next break if link.nil? current = fetch_page(ScheduledEmailRequests.page(link)) end end end |
#list(status: nil, batch_id: nil, scheduled_at_gte: nil, scheduled_at_lte: nil, page: nil) ⇒ ScheduledEmailPage
List one page of scheduled emails.
Every filter is optional and an omitted one never reaches the wire. A list of statuses becomes one comma-joined parameter rather than a repeated one. The listing is scoped server-side to a rolling window around now, so a bound in the direction that can never match is rejected rather than silently returning nothing.
72 73 74 75 76 |
# File 'lib/mailkube/resources/scheduled_emails.rb', line 72 def list(status: nil, batch_id: nil, scheduled_at_gte: nil, scheduled_at_lte: nil, page: nil) fetch_page(ScheduledEmailRequests.list(status: status, batch_id: batch_id, scheduled_at_gte: scheduled_at_gte, scheduled_at_lte: scheduled_at_lte, page: page)) end |
#update(email_id, scheduled_at:, batch_id: nil) ⇒ ScheduledEmail
Reschedule one scheduled email, optionally moving it into or out of a batch.
The content of a scheduled email is immutable; only its due time and batch can change.
121 122 123 124 |
# File 'lib/mailkube/resources/scheduled_emails.rb', line 121 def update(email_id, scheduled_at:, batch_id: nil) body = { "scheduled_at" => Serialization.to_iso(scheduled_at), "batch_id" => batch_id }.compact ScheduledEmail.from(@transport.request_json(ScheduledEmailRequests.update(email_id, body))) end |