Class: Emailfuse::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/emailfuse/models/email.rb

Class Method Summary collapse

Methods inherited from Object

#initialize, #to_ostruct

Constructor Details

This class inherits a constructor from Emailfuse::Object

Class Method Details

.create(to:, from:, subject:, html: nil, text: nil, **attributes) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/emailfuse/models/email.rb', line 4

def create(to:, from:, subject:, html: nil, text: nil, **attributes)
  raise ArgumentError, "You must provide either html or text" if html.nil? && text.nil?

  attrs = attributes.merge!(
    to: to,
    from: from,
    subject: subject,
    html: html,
    text: text
  )

  response = Client.post_request("emails", body: attrs)

  Email.new(response.body) if response.success?
end