Class: Devise::Models::Mailjet::MailjetWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/devise_mailjet/mailjet_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(action, list_names, email, config) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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