Module: EmailFuse::Emails

Included in:
Client
Defined in:
lib/email_fuse/emails.rb,
lib/email_fuse/emails/receiving.rb,
lib/email_fuse/emails/attachments.rb,
lib/email_fuse/emails/receiving/attachments.rb

Overview

Module responsible for wrapping email sending API

Defined Under Namespace

Modules: Attachments, Receiving

Class Method Summary collapse

Class Method Details

.cancel(email_id) ⇒ EmailFuse::Response

Cancel a scheduled email.

Raises:

  • (ArgumentError)


56
57
58
59
60
61
# File 'lib/email_fuse/emails.rb', line 56

def cancel(email_id)
  raise ArgumentError, "email_id is required" if email_id.nil? || email_id.to_s.empty?

  path = "emails/#{email_id}/cancel"
  EmailFuse::Request.new(path, {}, "post").perform
end

.get(email_id) ⇒ EmailFuse::Response

Retrieve a single email.

Raises:

  • (ArgumentError)


30
31
32
33
34
35
# File 'lib/email_fuse/emails.rb', line 30

def get(email_id)
  raise ArgumentError, "email_id is required" if email_id.nil? || email_id.to_s.empty?

  path = "emails/#{email_id}"
  EmailFuse::Request.new(path, {}, "get").perform
end

.list(options = {}) ⇒ EmailFuse::Response

List emails with optional pagination.

Options Hash (options):

  • :limit (Integer)

    Maximum number of emails to return (1-100, default 20)

  • :after (String)

    Cursor for pagination (newer emails)

  • :before (String)

    Cursor for pagination (older emails)



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/email_fuse/emails.rb', line 71

def list(options = {})
  path = "emails"

  # Build query parameters, filtering out nil values
  query_params = {}
  query_params[:limit] = options[:limit] if options[:limit]
  query_params[:after] = options[:after] if options[:after]
  query_params[:before] = options[:before] if options[:before]

  EmailFuse::Request.new(path, query_params, "get").perform
end

.send(params, options: {}) ⇒ EmailFuse::Response

Sends or schedules an email.

Options Hash (params):

  • :from (String)

    The sender email address (required)

  • :to (Array<String>, String)

    The recipient email address(es) (required)

  • :subject (String)

    The email subject

  • :html (String)

    The HTML content of the email

  • :text (String)

    The plain text content of the email

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/email_fuse/emails.rb', line 17

def send(params, options: {})
  raise ArgumentError, ":from is required" unless params[:from] || params["from"]
  raise ArgumentError, ":to is required" unless params[:to] || params["to"]

  path = "emails"
  EmailFuse::Request.new(path, params, "post", options: options).perform
end

.update(params) ⇒ EmailFuse::Response

Update a scheduled email.

Options Hash (params):

  • :email_id (String)

    The email ID (required)

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
# File 'lib/email_fuse/emails.rb', line 43

def update(params)
  email_id = params[:email_id] || params["email_id"]
  raise ArgumentError, ":email_id is required" if email_id.nil? || email_id.to_s.empty?

  path = "emails/#{email_id}"
  EmailFuse::Request.new(path, params, "patch").perform
end