class Leadersend::Mail
Public Class Methods
new(to: nil, from: nil, fromname: nil, subject: "System", template_path: nil, locals: {})
click to toggle source
# File lib/leadersend/mailer.rb, line 3 def initialize to: nil, from: nil, fromname: nil, subject: "System", template_path: nil, locals: {}, title: "System", template: "" @api_email_url = Leadersend.config.api_url @api_user = Leadersend.config.username @api_key = Leadersend.config.api_key @to = to @subject = subject @template_path = template_path @locals = locals @title = title @from = from @fromname = fromname @template_path = template_path @template = template if @template_path @template = ApplicationController.new.render_to_string(:partial => @template_path, :locals => @locals ) end end
Public Instance Methods
call_api()
click to toggle source
# File lib/leadersend/mailer.rb, line 35 def call_api subject = @subject fromname = @fromname options = {method: "messagesSend", apikey: @api_key, to: {email: @to}, subject: @subject, html: @template, from: {name: @fromname, email: @from}, auto_plain: true} resp = post_api @api_email_url, options json = JSON.parse(resp) puts json return json rescue => e return [{"status" => "error", "description" => "<#{e.class.name}>: #{e.message}"}] end
send()
click to toggle source
# File lib/leadersend/mailer.rb, line 22 def send result = call_api status = (result[0] && result[0]["status"]) ? result[0]["status"] : "error" return { title: @title, body: @template, status: status, subject: @subject, to_address: @to, response: result.inspect } end
Private Instance Methods
post_api(url, params)
click to toggle source
# File lib/leadersend/mailer.rb, line 49 def post_api url, params uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = false form_params = params.to_query res = http.post(uri.request_uri, form_params) res.body end