class Devise::Models::Mailjet::MailjetWorker

Public Instance Methods

perform(action, list_names, email, config) click to toggle source
# File lib/devise_mailjet/mailjet_worker.rb, line 7
def perform(action, list_names, email, config)
  if config.is_a?(Hash)
    ::Mailjet.configure do |c|
      c.api_version  = 'v3'
      c.api_key      = config['api_key']
      c.secret_key   = config['secret_key']
      c.default_from = config['default_from']
    end
  end

  ## Uncomment to debug
  # RestClient.log = Object.new.tap do |proxy|
  #   def proxy.<<(message)
  #     Sidekiq.logger.info message
  #   end
  # end

  mapper = MailjetListApiMapper.new
  if action == 'subscribe'
    mapper.subscribe_to_lists(list_names, email)
  elsif action == 'unsubscribe'
    mapper.unsubscribe_from_lists(list_names, email)
  end
end