Merge branch 'messagebus'
This commit is contained in:
commit
db4150de8d
6 changed files with 61 additions and 3 deletions
3
Gemfile
3
Gemfile
|
|
@ -77,6 +77,9 @@ gem 'SystemTimer', '1.2.1', :platforms => :ruby_18
|
|||
gem 'hoptoad_notifier'
|
||||
gem 'newrelic_rpm', :require => false
|
||||
|
||||
#mail
|
||||
gem 'messagebus_ruby_api', '0.4.0'
|
||||
|
||||
# tags
|
||||
|
||||
gem 'acts-as-taggable-on', :git => 'git://github.com/diaspora/acts-as-taggable-on.git'
|
||||
|
|
|
|||
|
|
@ -245,6 +245,7 @@ GEM
|
|||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
messagebus_ruby_api (0.4.0)
|
||||
mime-types (1.16)
|
||||
mini_magick (3.2)
|
||||
subexec (~> 0.0.4)
|
||||
|
|
@ -505,6 +506,7 @@ DEPENDENCIES
|
|||
json (= 1.4.6)
|
||||
jwt (= 0.1.3)
|
||||
linecache (= 0.43)
|
||||
messagebus_ruby_api (= 0.4.0)
|
||||
mini_magick (= 3.2)
|
||||
mobile-fu
|
||||
mock_redis
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ defaults: &defaults
|
|||
smtp_port: '587'
|
||||
|
||||
# This chooses which mailer should be used. 'smtp' for a smtp
|
||||
# connection or 'sendmail' to use the sendmail binary.
|
||||
# connection or 'sendmail' to use the sendmail binary, or messagebus, to use the messagebus service
|
||||
mailer_method: 'smtp'
|
||||
|
||||
# The path to the sendmail binary. Ignored if mailer_method is not set to sendmail
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
Diaspora::Application.configure do
|
||||
# Settings specified here will take precedence over those in config/environment.rb
|
||||
|
||||
|
|
@ -17,6 +16,7 @@ Diaspora::Application.configure do
|
|||
config.consider_all_requests_local = true
|
||||
config.action_controller.perform_caching = false
|
||||
|
||||
|
||||
# Don't care if the mailer can't send
|
||||
config.action_mailer.raise_delivery_errors = false
|
||||
config.active_support.deprecation = :log
|
||||
|
|
|
|||
|
|
@ -2,10 +2,18 @@
|
|||
# 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 = {:host => AppConfig[:pod_uri].authority }
|
||||
|
||||
unless Rails.env == 'test' || AppConfig[:mailer_on] != true
|
||||
if AppConfig[:mailer_method] == "sendmail"
|
||||
if AppConfig[:mailer_method] == 'messagebus'
|
||||
if AppConfig[:messagebus_api_key].present?
|
||||
config.action_mailer.delivery_method = Messagebus::Mailer.new(AppConfig[:messagebus_api_key])
|
||||
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
|
||||
elsif AppConfig[:mailer_method] == "sendmail"
|
||||
config.action_mailer.delivery_method = :sendmail
|
||||
config.action_mailer.sendmail_settings = {
|
||||
:location => AppConfig[:sendmail_location]
|
||||
|
|
@ -34,4 +42,5 @@ Diaspora::Application.configure do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
44
lib/messagebus/mailer.rb
Normal file
44
lib/messagebus/mailer.rb
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
module Messagebus
|
||||
class Mailer
|
||||
|
||||
def initialize(api_key)
|
||||
@client = MessagebusRubyApi::Client.new(AppConfig[:messagebus_api_key])
|
||||
end
|
||||
|
||||
attr_accessor :settings
|
||||
|
||||
def new(*settings)
|
||||
self
|
||||
end
|
||||
|
||||
def deliver!(message)
|
||||
deliver(message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def deliver(message)
|
||||
# here we want = {:fromEmail => message['from'].to_s}
|
||||
@client.common_info = {:fromEmail => message.from.first}
|
||||
message.to.each do |addressee|
|
||||
m = {:toEmail => addressee, :subject => message.subject}
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
@client.add_message(m)
|
||||
end
|
||||
|
||||
status = @client.flush
|
||||
|
||||
if status[:failureCount] && status[:failureCount] > 0
|
||||
raise "Messagebus failure. failureCount=#{failureCount}, message=#{message.inspect}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue