Class: Mailersend::BulkEmail

Inherits:
Object
  • Object
show all
Defined in:
lib/mailersend/bulk_email/bulk_email.rb

Overview

Send an email through MailerSend API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = Mailersend::Client.new) ⇒ BulkEmail

Returns a new instance of BulkEmail.



11
12
13
14
# File 'lib/mailersend/bulk_email/bulk_email.rb', line 11

def initialize(client = Mailersend::Client.new)
  @client = client
  @messages = []
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/mailersend/bulk_email/bulk_email.rb', line 8

def client
  @client
end

#messagesObject

Returns the value of attribute messages.



8
9
10
# File 'lib/mailersend/bulk_email/bulk_email.rb', line 8

def messages
  @messages
end

Instance Method Details

#add_attachment(content:, filename:, disposition:) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/mailersend/bulk_email/bulk_email.rb', line 16

def add_attachment(content:, filename:, disposition:)
  data = File.read(content.to_s)
  encoded = Base64.strict_encode64(data)
  @attachments << {
    'content' => encoded,
    'filename' => filename,
    'disposition' => disposition
  }
end

#get_bulk_status(bulk_email_id:) ⇒ Object



30
31
32
# File 'lib/mailersend/bulk_email/bulk_email.rb', line 30

def get_bulk_status(bulk_email_id:)
  client.http.get(URI::HTTPS.build(host: MAILERSEND_API_BASE_HOST, path: "/v1/bulk-email/#{bulk_email_id}"))
end

#sendObject



26
27
28
# File 'lib/mailersend/bulk_email/bulk_email.rb', line 26

def send
  client.http.post("#{MAILERSEND_API_URL}/bulk-email", json: @messages)
end