Sha256: e70c9a3eff8ad04cc23340de5d5d81a857837f59bf660e905c107a82846fb31f

Contents?: true

Size: 845 Bytes

Versions: 2

Compression:

Stored size: 845 Bytes

Contents

module Macaco
  class Sendgrid < Sender

    def docs
      'https://sendgrid.com/docs/API_Reference/Web_API/mail.html#-send'
    end

    def api_root
      'api.sendgrid.com'
    end

    def api_path
      '/api/mail.send.json'
    end

    def content_type
      'application/x-www-form-urlencoded'
    end

    def to_hash
      {
        from: @from,
        to: @to,
        subject: @subject,
        html: @body_html,
        text: @body_text
      }
    end

    def send
      data = to_hash
      Macaco::Api.post({
        mail: self,
        data: convert_data_params(data),
        headers: { "Authorization" => "Bearer #{api_key}" }
      })
    end

    private

    def convert_data_params(data)
      URI.encode_www_form(data)
    end

    def api_key
      Macaco.config.api_key || ENV['SENDGRID_API_KEY']
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
macaco-0.0.6 lib/macaco/senders/sendgrid.rb
macaco-0.0.5 lib/macaco/senders/sendgrid.rb