Class: Sendhub::Rails

Inherits:
Object
  • Object
show all
Defined in:
lib/sendhub/plugins/rails3.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Rails

Returns a new instance of Rails.



3
4
5
6
7
8
9
10
11
# File 'lib/sendhub/plugins/rails3.rb', line 3

def initialize(options)
  @client = Sendhub::Client.new(
    :host => options[:host],
    :protocol => options[:protocol],
    :api_key => options[:api_key],
    :secret_key => options[:secret_key],
    :notification_url => options[:notification_url]
  )
end

Instance Method Details

#collect_parts(message) ⇒ Object



32
33
34
# File 'lib/sendhub/plugins/rails3.rb', line 32

def collect_parts(message)
  message.parts.inject("\n\n\n") {|x, part| x << "--#{message.boundary}\n"; x << "#{part.to_s}\n\n"}
end

#collect_sendhub_headers(message) ⇒ Object



36
37
38
# File 'lib/sendhub/plugins/rails3.rb', line 36

def collect_sendhub_headers(message)
  message.header.fields.find_all{|x| x.name =~ /X-SendHub/}.collect{|x| {x.name => x.value}}
end

#deliver!(message) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sendhub/plugins/rails3.rb', line 13

def deliver!(message)
  body = message.body
  body = collect_parts(message) if message.multipart?
  headers = collect_sendhub_headers(message)

  res = @client.send_email(
    :from => message.from,
    :to => message.to,
    :reply_to => message.reply_to,
    :subject => message.subject,
    :body => body,
    :content_type => message.content_type,
    :content_transfer_encoding => message.content_transfer_encoding,
    :headers => headers
  )

  puts res.inspect
end