Commit ebf9004f authored by Maxwell Salzberg's avatar Maxwell Salzberg

update messagebus to latest version of their api

parent bbfb47b6
......@@ -26,7 +26,7 @@ gem 'twitter', '2.0.2'
gem 'cloudfiles', '1.4.10', :require => false
# mail
gem 'messagebus_ruby_api', '0.4.8'
gem 'messagebus_ruby_api', '1.0.1'
# web sockets
......
......@@ -241,7 +241,7 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
messagebus_ruby_api (0.4.8)
messagebus_ruby_api (1.0.1)
mime-types (1.17.2)
mini_magick (3.3)
subexec (~> 0.1.0)
......@@ -479,7 +479,7 @@ DEPENDENCIES
json (= 1.5.2)
jwt (= 0.1.3)
linecache (= 0.46)
messagebus_ruby_api (= 0.4.8)
messagebus_ruby_api (= 1.0.1)
mini_magick (= 3.3)
mobile-fu
mock_redis
......
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib/messagebus/mailer')
Diaspora::Application.configure do
config.action_mailer.default_url_options = {:protocol => AppConfig[:pod_uri].scheme,
:host => AppConfig[:pod_uri].authority }
unless Rails.env == 'test' || AppConfig[:mailer_on] != true
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
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
......
module Messagebus
class Mailer
unless defined?(MessagebusRubyApi::VERSION)
MessagebusRubyApi::VERSION = '0.4.8'
end
def initialize(api_key)
@client = MessagebusRubyApi::Client.new(api_key)
end
@client = MessagebusApi::Messagebus.new(api_key)
end
attr_accessor :settings
def new(*settings)
self
self
end
def deliver!(message)
deliver(message)
end
def from_header_parse(string)
string.split('<')[0].delete('"')
end
def message_parse(string)
string.split('<')[0]
end
def deliver!(message)
msg = {:toEmail => message.to.first, :subject => message.subject, :fromEmail =>message.from.first, :fromName => from_header_parse(message[:from].to_s)}
def from_header_parse(message)
AppConfig[:smtp_sender_address]
'no-reply@joindiaspora.com'
if message.multipart?
msg[:plaintextBody] = message.text_part.body.to_s if message.text_part
msg[:htmlBody] = message.html_part.body.to_s if message.html_part
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?
m[:plaintextBody] = message.text_part.body.to_s if message.text_part
m[: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
@client.add_message(m)
@things << m
end
begin
status = @client.flush
rescue Exception => e
raise "message bus failures: #{e.message} #{@things.map{|x| x[:fromEmail]}.inspect}, #{message['from']}"
end
if status[:failureCount] && status[:failureCount] > 0
raise "Messagebus failure. failureCount=#{status[:failureCount]}, message=#{message.inspect}"
end
begin
@client.add_message(msg, true)
rescue => message_bus_api_error
raise "Messagebus API error=#{message_bus_api_error}, message=#{msg.inspect}"
end
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment