Class: Jangomail::Mailer
- Inherits:
-
Object
- Object
- Jangomail::Mailer
- Defined in:
- lib/jangomail-mailer.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(values = {}) ⇒ Mailer
constructor
A new instance of Mailer.
- #new(*args) ⇒ Object
Constructor Details
#initialize(values = {}) ⇒ Mailer
Returns a new instance of Mailer.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jangomail-mailer.rb', line 9 def initialize(values = {}) self.settings = { :api_url => 'http://api.jangomail.com/api.asmx/SendTransactionalEmail', :options => {}, :logger => defined?(Rails) && Rails.logger, :log_level => :debug, :user_name => nil, :password => nil, }.merge!(values) raise ArgumentError, 'User Name needed' unless settings[:user_name] raise ArgumentError, 'Password needed' unless settings[:password] end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
21 22 23 |
# File 'lib/jangomail-mailer.rb', line 21 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jangomail-mailer.rb', line 27 def deliver!(mail) uri = URI.parse(settings[:api_url]) if uri.scheme == 'https' http = Net::HTTP.new(uri.host, 443) http.use_ssl = true else http = Net::HTTP.new(uri.host) end destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations if destinations.blank? raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message') end destinations.each do |destination| data = request_data(mail, destination) http.post(uri.path, data).body.tap do |response| settings[:logger].send(settings[:log_level], "Jangomail: #{response}") if settings[:logger] end end end |
#new(*args) ⇒ Object
23 24 25 |
# File 'lib/jangomail-mailer.rb', line 23 def new(*args) self end |