Class: Silverpop::Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/silverpop/mailer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mailer

Returns a new instance of Mailer.



7
8
9
10
11
12
13
14
15
16
# File 'lib/silverpop/mailer.rb', line 7

def initialize(options = {})
  # config
  self.config = options
  
  # logger
  Silverpop.logger.level = self.config[:log_level] || Logger::ERROR
  
  # logging
  Silverpop.logger.debug "Mailer init: #{self.config[:server]}"
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/silverpop/mailer.rb', line 5

def config
  @config
end

#requestObject

Returns the value of attribute request.



5
6
7
# File 'lib/silverpop/mailer.rb', line 5

def request
  @request
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/silverpop/mailer.rb', line 5

def response
  @response
end

Instance Method Details

#mail(campaign_id, email, options = {}) ⇒ Object



18
19
20
21
# File 'lib/silverpop/mailer.rb', line 18

def mail(campaign_id, email, options = {})
  self.request = Silverpop::Request.new(campaign_id, email, options)
  self.response = Silverpop::Response.new(self.send(self.request.generate))
end

#send(request) ⇒ Object

Submits the request.



25
26
27
28
29
# File 'lib/silverpop/mailer.rb', line 25

def send(request)
  # TODO: implement into Silverpop::Transact
  res = Net::HTTP.post_form(URI.parse(self.config[:server]), :xml => request)
  res.body
end