class Griddler::Postmark::Adapter
Attributes
params[R]
Public Class Methods
new(params)
click to toggle source
# File lib/griddler/postmark/adapter.rb, line 6 def initialize(params) @params = params end
normalize_params(params)
click to toggle source
# File lib/griddler/postmark/adapter.rb, line 10 def self.normalize_params(params) adapter = new(params) adapter.normalize_params end
Public Instance Methods
normalize_params()
click to toggle source
# File lib/griddler/postmark/adapter.rb, line 15 def normalize_params { to: extract_recipients(:ToFull), cc: extract_recipients(:CcFull), from: full_email(params[:FromFull]), subject: params[:Subject], text: params[:TextBody], html: params[:HtmlBody], attachments: attachment_files, } end
Private Instance Methods
attachment_files()
click to toggle source
# File lib/griddler/postmark/adapter.rb, line 44 def attachment_files attachments = Array(params[:Attachments]) attachments.map do |attachment| ActionDispatch::Http::UploadedFile.new({ filename: attachment[:Name], type: attachment[:ContentType], tempfile: create_tempfile(attachment) }) end end
create_tempfile(attachment)
click to toggle source
# File lib/griddler/postmark/adapter.rb, line 56 def create_tempfile(attachment) filename = attachment[:Name] tempfile = Tempfile.new(filename, Dir::tmpdir, encoding: 'ascii-8bit') tempfile.write(Base64.decode64(attachment[:Content])) tempfile.rewind tempfile end
extract_recipients(key)
click to toggle source
# File lib/griddler/postmark/adapter.rb, line 31 def extract_recipients(key) params[key].to_a.map { |recipient| full_email(recipient) } end
full_email(contact_info)
click to toggle source
# File lib/griddler/postmark/adapter.rb, line 35 def full_email(contact_info) email = contact_info[:Email] if contact_info[:Name].present? "#{contact_info[:Name]} <#{email}>" else email end end