Class: UnisenderRails::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/unisender-rails/sender.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Sender

Returns a new instance of Sender.



7
8
9
10
11
12
# File 'lib/unisender-rails/sender.rb', line 7

def initialize(args)
  @settings = {:api_key => nil}
   args.each do |arg_name, arg_value|
    @settings[arg_name.to_sym] = arg_value
   end
end

Instance Method Details

#deliver!(mail) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/unisender-rails/sender.rb', line 18

def deliver!(mail)
   mail_to = [*(mail.to)]
   client = UniSender::Client.new(@settings[:api_key])
   list_id = @settings[:list_id]
   result = client.subscribe :fields => {:email => mail_to.join(',')},
                             :list_ids => list_id,
                             :double_optin => 3 
   log_event(result)
   result = client.activateContacts :contact_type => 'email',
                                    :contacts => mail_to.join(',')
   log_event(result)                                       
   result = client.sendEmail :subject => mail.subject,
                             :body => mail.body,
                             :sender_email => mail.from,
                             :email => mail_to,
                             :sender_name => @settings[:sender_name] || mail.from.split('@').first,
                             :list_id => list_id,
                             :lang => @settings[:lang] || 'ru'
   log_event(result)
end

#settingsObject



14
15
16
# File 'lib/unisender-rails/sender.rb', line 14

def settings
  @settings
end