Class: KlaviyoRails::DeliveryMethod
- Inherits:
-
Object
- Object
- KlaviyoRails::DeliveryMethod
- Defined in:
- lib/klaviyo-rails/delivery_method.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(options = {}) ⇒ DeliveryMethod
constructor
A new instance of DeliveryMethod.
Constructor Details
#initialize(options = {}) ⇒ DeliveryMethod
Returns a new instance of DeliveryMethod.
6 7 8 9 10 11 |
# File 'lib/klaviyo-rails/delivery_method.rb', line 6 def initialize( = {}) self.settings = { secret_key: ENV['KLAVIYO_SECRET_KEY'], token: ENV['KLAVIYO_TOKEN'] }.merge() end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
5 6 7 |
# File 'lib/klaviyo-rails/delivery_method.rb', line 5 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/klaviyo-rails/delivery_method.rb', line 13 def deliver!(mail) if mail['as_event'] && mail['as_event'].value.to_s == 'true' response = client.event.track( event_name: mail['event_name'].value, customer_properties: { '$email': mail['to'].to_s }, properties: { email: mail['to'].to_s, '$event_id': mail.object_id, date: Time.current, context: JSON.load(mail['context'].value), subject: mail['subject'].to_s, to: mail['to'].to_s, from:{ name: from_name(mail), email: from_email(mail) } } ) else response = client.templates.render_and_send((mail)) end if settings[:return_response] response else self end end |