Class: Mailersend::BulkEmail
- Inherits:
-
Object
- Object
- Mailersend::BulkEmail
- Defined in:
- lib/mailersend/bulk_email/bulk_email.rb
Overview
Send an email through MailerSend API
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#messages ⇒ Object
Returns the value of attribute messages.
Instance Method Summary collapse
- #add_attachment(content:, filename:, disposition:) ⇒ Object
- #get_bulk_status(bulk_email_id:) ⇒ Object
-
#initialize(client = Mailersend::Client.new) ⇒ BulkEmail
constructor
A new instance of BulkEmail.
- #send ⇒ Object
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
#client ⇒ Object
Returns the value of attribute client.
8 9 10 |
# File 'lib/mailersend/bulk_email/bulk_email.rb', line 8 def client @client end |
#messages ⇒ Object
Returns the value of attribute messages.
8 9 10 |
# File 'lib/mailersend/bulk_email/bulk_email.rb', line 8 def @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 (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 |
#send ⇒ Object
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 |