Class: PUNK::SendEmailWorker
- Defined in:
- lib/punk/workers/send_email_worker.rb
Instance Attribute Summary
Attributes included from Validatable
Instance Method Summary collapse
Methods inherited from Worker
Methods inherited from Runnable
args, #method_missing, #respond_to_missing?
Methods included from Validatable
#default_validation_helpers_options, #get_column_value, #valid?, #validates_not_empty
Methods included from Plugins::Validation::InstanceMethods
#validates_email, #validates_event, #validates_phone, #validates_state, #validates_url
Methods inherited from Settings
#method_missing, #respond_to_missing?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class PUNK::Runnable
Instance Method Details
#process ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/punk/workers/send_email_worker.rb', line 19 def process require "mailgun-ruby" client = if !PUNK.env.test? && PUNK.get.mailgun.mock Mailgun::Client.new(PUNK.get.mailgun.api_key, "bin.mailgun.net", PUNK.get.mailgun.postbin, ssl=false) # rubocop:disable Lint/UselessAssignment,Layout/SpaceAroundOperators else Mailgun::Client.new(PUNK.get.mailgun.api_key) end client.enable_test_mode! if PUNK.env.test? = { from: from, to: to, subject: subject, template: template } variables.each { |variable, value| ["v:#{variable}"] = value } if variables.present? .each { |tag| ["o:tag"] = tag } if .present? # TODO: store return value in Message table # TODO: update Message table with events from mailgun webhooks client.(PUNK.get.mailgun.domain, ) return unless !PUNK.env.test? && PUNK.get.mailgun.mock require "launchy" Launchy.open("http://bin.mailgun.net/#{PUNK.get.mailgun.postbin}") end |
#validate ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/punk/workers/send_email_worker.rb', line 7 def validate validates_type String, :from validates_type String, :to validates_email :to validates_includes PUNK.get.mailgun.whitelist, :to if !PUNK.env.test? && !PUNK.get.mailgun.mock && PUNK.get.mailgun.whitelist.present? validates_type String, :subject validates_type String, :template validates_type Hash, :variables, allow_nil: true validates_type Array, :tags, allow_nil: true validates_length_range 0..1, :tags, allow_nil: true end |