Module: Millionsend::Emails

Defined in:
lib/millionsend/emails.rb

Overview

Transactional email: send one, look it up, reschedule or cancel a scheduled one, list what was sent. Params hashes go on the wire as-is (from, to, cc, bcc, reply_to, subject, html, text, headers, tags, attachments, scheduled_at, topic_id, template), so nothing a caller passes is dropped.

Class Method Summary collapse

Class Method Details

.cancel(id) ⇒ Object

POST /emails/:id/cancel — scheduled, unsent emails only.



52
53
54
# File 'lib/millionsend/emails.rb', line 52

def cancel(id)
  Millionsend::Request.new(method: :post, path: "#{member_path(id)}/cancel").perform
end

.get(id) ⇒ Object

GET /emails/:id



24
25
26
# File 'lib/millionsend/emails.rb', line 24

def get(id)
  Millionsend::Request.new(method: :get, path: member_path(id)).perform
end

.get_insights(id) ⇒ Object

GET /emails/:id/insights — the pre-send best-practice report computed when the email was sent. 404 when the email is unknown or has no insights yet. Check ids and band/severity/status values are an open set that grows across score versions; they arrive as plain strings.



47
48
49
# File 'lib/millionsend/emails.rb', line 47

def get_insights(id)
  Millionsend::Request.new(method: :get, path: "#{member_path(id)}/insights").perform
end

.list(options = {}) ⇒ Object

GET /emails — accepts limit:/after:/before:.



29
30
31
# File 'lib/millionsend/emails.rb', line 29

def list(options = {})
  Millionsend::Request.new(method: :get, path: "/emails", query: Millionsend::Util.list_query(options)).perform
end

.remove(id) ⇒ Object

DELETE /emails/:id



57
58
59
# File 'lib/millionsend/emails.rb', line 57

def remove(id)
  Millionsend::Request.new(method: :delete, path: member_path(id)).perform
end

.send(params = {}, options = {}) ⇒ Object Also known as: create

POST /emails. Accepts a params hash or bare keywords (Emails.send(from: ..., to: ...)); a trailing hash carries the request options as either idempotency_key: "k" or resend-ruby's options: { idempotency_key: "k" }. No keyword parameters are declared on purpose — Ruby 3 keyword separation would otherwise reject the bare-keyword call shape.



16
17
18
19
20
# File 'lib/millionsend/emails.rb', line 16

def send(params = {}, options = {})
  Millionsend::Request.new(
    method: :post, path: "/emails", body: params, **Millionsend::Util.request_options(options)
  ).perform
end

.update(id, params = nil) ⇒ Object

PATCH /emails/:id — reschedule a scheduled, unsent email. Takes (id, { scheduled_at: }) or resend-ruby's single hash with :email_id.



35
36
37
38
39
40
41
# File 'lib/millionsend/emails.rb', line 35

def update(id, params = nil)
  if id.is_a?(Hash)
    params = id.reject { |k, _| k == :email_id }
    id = id[:email_id]
  end
  Millionsend::Request.new(method: :patch, path: member_path(id), body: params).perform
end