Class: LetMeSendEmail::Resources::Emails

Inherits:
Base
  • Object
show all
Defined in:
lib/letmesendemail/resources/emails.rb

Overview

Emails API operations.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from LetMeSendEmail::Resources::Base

Instance Method Details

#get(id) ⇒ Models::Model

Retrieves detailed information for an email.

Parameters:

  • id (String)

Returns:



71
72
73
# File 'lib/letmesendemail/resources/emails.rb', line 71

def get(id)
  @client.request(:get, path_for('emails', id))
end

#list(per_page: nil, after: nil, before: nil) ⇒ Models::Model

Lists one cursor page of emails.

Returns:



64
65
66
# File 'lib/letmesendemail/resources/emails.rb', line 64

def list(per_page: nil, after: nil, before: nil)
  @client.request(:get, list_path('emails', per_page: per_page, after: after, before: before))
end

#send(from:, to:, subject:, html: nil, text: nil, type: nil, event_name: nil, email_topic_id: nil, reply_to: nil, cc: nil, bcc: nil, headers: nil, attachments: nil, idempotency_key: nil) ⇒ Models::Model

Sends a regular email.

Returns:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/letmesendemail/resources/emails.rb', line 9

def send(from:, to:, subject:, html: nil, text: nil, type: nil,
         event_name: nil, email_topic_id: nil, reply_to: nil,
         cc: nil, bcc: nil, headers: nil, attachments: nil,
         idempotency_key: nil)
  body = { from: from, to: to, subject: subject }
  body[:html] = html if html
  body[:text] = text if text
  body[:type] = type if type
  body[:event_name] = event_name if event_name
  body[:email_topic_id] = email_topic_id if email_topic_id
  body[:reply_to] = reply_to if reply_to
  body[:cc] = cc if cc
  body[:bcc] = bcc if bcc
  body[:headers] = headers if headers
  body[:attachments] = attachments if attachments

  extra = idempotency_key ? { 'Idempotency-Key' => idempotency_key } : {}

  @client.request(:post, '/emails', body: body, extra_headers: extra)
end

#send_with_template(from:, to:, template_id:, subject: nil, template_variables: nil, type: nil, event_name: nil, email_topic_id: nil, reply_to: nil, cc: nil, bcc: nil, headers: nil, attachments: nil, idempotency_key: nil) ⇒ Models::Model

Sends an email using a template.

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/letmesendemail/resources/emails.rb', line 32

def send_with_template(from:, to:, template_id:, subject: nil,
                       template_variables: nil, type: nil,
                       event_name: nil, email_topic_id: nil,
                       reply_to: nil, cc: nil, bcc: nil,
                       headers: nil, attachments: nil,
                       idempotency_key: nil)
  body = { from: from, to: to, template_id: template_id }
  body[:subject] = subject if subject
  body[:template_variables] = template_variables if template_variables
  body[:type] = type if type
  body[:event_name] = event_name if event_name
  body[:email_topic_id] = email_topic_id if email_topic_id
  body[:reply_to] = reply_to if reply_to
  body[:cc] = cc if cc
  body[:bcc] = bcc if bcc
  body[:headers] = headers if headers
  body[:attachments] = attachments if attachments

  extra = idempotency_key ? { 'Idempotency-Key' => idempotency_key } : {}

  @client.request(:post, '/emails', body: body, extra_headers: extra)
end

#verify(email) ⇒ Models::Model

Verifies an email address.

Parameters:

  • email (String)

Returns:



58
59
60
# File 'lib/letmesendemail/resources/emails.rb', line 58

def verify(email)
  @client.request(:post, '/emails/verify', body: { email: email })
end