Sha256: 24690c65388ea3de8dc5fd818d56616c9d217e1ec8c3f048837ba33a9ecdf754

Contents?: true

Size: 856 Bytes

Versions: 2

Compression:

Stored size: 856 Bytes

Contents

# frozen_string_literal: true

require 'base64'

module Mailersend
  # Send an email through MailerSend API
  class BulkEmail
    attr_accessor :client,
                  :messages

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

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

    def send
      response = client.http.post("#{API_URL}/bulk-email", json: @messages)
      puts response
      puts response.status.code
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mailersend-ruby-1.0.0 lib/mailersend/bulk_email/bulk_email.rb
mailersend-ruby-0.2.5 lib/mailersend/bulk_email/bulk_email.rb