update messagebus to latest version of their api

This commit is contained in:
Maxwell Salzberg 2011-12-19 12:24:25 -08:00
parent bbfb47b6a3
commit ebf9004f91
4 changed files with 28 additions and 56 deletions

View file

@ -26,7 +26,7 @@ gem 'twitter', '2.0.2'
gem 'cloudfiles', '1.4.10', :require => false gem 'cloudfiles', '1.4.10', :require => false
# mail # mail
gem 'messagebus_ruby_api', '0.4.8' gem 'messagebus_ruby_api', '1.0.1'
# web sockets # web sockets

View file

@ -241,7 +241,7 @@ GEM
i18n (>= 0.4.0) i18n (>= 0.4.0)
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
messagebus_ruby_api (0.4.8) messagebus_ruby_api (1.0.1)
mime-types (1.17.2) mime-types (1.17.2)
mini_magick (3.3) mini_magick (3.3)
subexec (~> 0.1.0) subexec (~> 0.1.0)
@ -479,7 +479,7 @@ DEPENDENCIES
json (= 1.5.2) json (= 1.5.2)
jwt (= 0.1.3) jwt (= 0.1.3)
linecache (= 0.46) linecache (= 0.46)
messagebus_ruby_api (= 0.4.8) messagebus_ruby_api (= 1.0.1)
mini_magick (= 3.3) mini_magick (= 3.3)
mobile-fu mobile-fu
mock_redis mock_redis

View file

@ -1,16 +1,19 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is # Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
require File.join(Rails.root, 'lib/messagebus/mailer') require File.join(Rails.root, 'lib/messagebus/mailer')
Diaspora::Application.configure do Diaspora::Application.configure do
config.action_mailer.default_url_options = {:protocol => AppConfig[:pod_uri].scheme, config.action_mailer.default_url_options = {:protocol => AppConfig[:pod_uri].scheme,
:host => AppConfig[:pod_uri].authority } :host => AppConfig[:pod_uri].authority }
unless Rails.env == 'test' || AppConfig[:mailer_on] != true unless Rails.env == 'test' || AppConfig[:mailer_on] != true
if AppConfig[:mailer_method] == 'messagebus' if AppConfig[:mailer_method] == 'messagebus'
if AppConfig[:messagebus_api_key].present?
config.action_mailer.delivery_method = Messagebus::Mailer.new(AppConfig[:messagebus_api_key]) if AppConfig[:message_bus_api_key].present?
config.action_mailer.delivery_method = Messagebus::Mailer.new(AppConfig[:message_bus_api_key])
config.action_mailer.raise_delivery_errors = true
else else
puts "You need to set your messagebus api key if you are going to use the message bus service. no mailer is now configured" puts "You need to set your messagebus api key if you are going to use the message bus service. no mailer is now configured"
end end

View file

@ -1,11 +1,7 @@
module Messagebus module Messagebus
class Mailer class Mailer
unless defined?(MessagebusRubyApi::VERSION)
MessagebusRubyApi::VERSION = '0.4.8'
end
def initialize(api_key) def initialize(api_key)
@client = MessagebusRubyApi::Client.new(api_key) @client = MessagebusApi::Messagebus.new(api_key)
end end
attr_accessor :settings attr_accessor :settings
@ -14,50 +10,23 @@ module Messagebus
self self
end end
def from_header_parse(string)
string.split('<')[0].delete('"')
end
def deliver!(message) def deliver!(message)
deliver(message) msg = {:toEmail => message.to.first, :subject => message.subject, :fromEmail =>message.from.first, :fromName => from_header_parse(message[:from].to_s)}
end
def message_parse(string)
string.split('<')[0]
end
def from_header_parse(message)
AppConfig[:smtp_sender_address]
'no-reply@joindiaspora.com'
end
private
def deliver(message)
# here we want = {:fromEmail => message['from'].to_s}
#this is required due to weird bug in action mailer
from_header = from_header_parse(message)
@client.send_common_info = {:fromEmail => from_header, :customHeaders => {"sender"=> from_header}}
message.to.each do |addressee|
m = {:toEmail => addressee, :fromEmail => from_header, :subject => message.subject, :fromName => message_parse(from_header)}
@things = []
if message.multipart? if message.multipart?
m[:plaintextBody] = message.text_part.body.to_s if message.text_part msg[:plaintextBody] = message.text_part.body.to_s if message.text_part
m[:htmlBody] = message.html_part.body.to_s if message.html_part msg[:htmlBody] = message.html_part.body.to_s if message.html_part
else
m[:plaintextBody] = message.body.to_s
m[:htmlBody] = message.body.to_s
end end
@client.add_message(m)
@things << m
end
begin begin
status = @client.flush @client.add_message(msg, true)
rescue Exception => e rescue => message_bus_api_error
raise "message bus failures: #{e.message} #{@things.map{|x| x[:fromEmail]}.inspect}, #{message['from']}" raise "Messagebus API error=#{message_bus_api_error}, message=#{msg.inspect}"
end
if status[:failureCount] && status[:failureCount] > 0
raise "Messagebus failure. failureCount=#{status[:failureCount]}, message=#{message.inspect}"
end
end end
end end
end end
end