class CourierRails::DeliveryMethod
Attributes
payload[RW]
response[RW]
settings[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/courier_rails/delivery_method.rb, line 8 def initialize(options = {}) @settings = options end
Public Instance Methods
deliver!(mail)
click to toggle source
# File lib/courier_rails/delivery_method.rb, line 12 def deliver!(mail) @payload = {} courier_data = find_courier_data_from mail prepare_event_from courier_data prepare_recipient_from mail, courier_data prepare_profile_from mail, courier_data prepare_data_from courier_data prepare_brand_from courier_data perfom_send_request end
Private Instance Methods
client()
click to toggle source
# File lib/courier_rails/delivery_method.rb, line 28 def client ## TODO: Allow passed in Courier Data? @client = Courier::Client.new CourierRails.configuration.api_key end
find_courier_data_from(mail)
click to toggle source
# File lib/courier_rails/delivery_method.rb, line 33 def find_courier_data_from(mail) mail.courier_data end
perfom_send_request()
click to toggle source
# File lib/courier_rails/delivery_method.rb, line 72 def perfom_send_request client.send(@payload) end
prepare_brand_from(courier_data)
click to toggle source
# File lib/courier_rails/delivery_method.rb, line 68 def prepare_brand_from(courier_data) @payload["brand"] = courier_data[:brand] if courier_data.has_key?(:brand) end
prepare_data_from(courier_data)
click to toggle source
# File lib/courier_rails/delivery_method.rb, line 64 def prepare_data_from(courier_data) @payload["data"] = courier_data[:data] if courier_data.has_key?(:data) end
prepare_event_from(courier_data)
click to toggle source
# File lib/courier_rails/delivery_method.rb, line 37 def prepare_event_from(courier_data) if courier_data.has_key?(:event) @payload["event"] = courier_data[:event] else raise StandardError, "Must specify :event key in courier_data." end end
prepare_profile_from(mail, courier_data)
click to toggle source
# File lib/courier_rails/delivery_method.rb, line 55 def prepare_profile_from(mail, courier_data) profile = {} profile = courier_data[:profile] if courier_data.has_key?(:profile) profile[:email] = mail.to.first unless mail.to.nil? @payload["profile"] = profile unless profile.empty? end
prepare_recipient_from(mail, courier_data)
click to toggle source
# File lib/courier_rails/delivery_method.rb, line 45 def prepare_recipient_from(mail, courier_data) @payload["recipient"] = if courier_data.has_key?(:recipient) courier_data[:recipient].to_s elsif !mail.to.nil? mail.to.first else SecureRandom.uuid end end