sailthru_mailer 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +3 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +72 -0
- data/Guardfile +21 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +93 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/sailthru_mailer/base.rb +156 -0
- data/lib/sailthru_mailer/connection.rb +18 -0
- data/lib/sailthru_mailer.rb +13 -0
- data/sailthru_mailer.gemspec +82 -0
- data/spec/lib/sailthru_mailer/base_spec.rb +102 -0
- data/spec/lib/sailthru_mailer_spec.rb +14 -0
- data/spec/spec_helper.rb +28 -0
- metadata +176 -0
data/.document
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
|
9
|
+
gem "activesupport", "< 3.0.0"
|
10
|
+
gem "i18n"
|
11
|
+
gem "sailthru-client", :git => "https://github.com/sailthru/sailthru-ruby-client.git"
|
12
|
+
|
13
|
+
group :development do
|
14
|
+
gem "ruby-debug19"
|
15
|
+
gem "rspec"
|
16
|
+
gem "guard-rspec"
|
17
|
+
gem "bundler", "~> 1.0.0"
|
18
|
+
gem "jeweler", "~> 1.6.4"
|
19
|
+
gem "simplecov"
|
20
|
+
gem "mocha"
|
21
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/sailthru/sailthru-ruby-client.git
|
3
|
+
revision: 98fda4d1ef1445aa70a545cc97239dbafdb3aeb2
|
4
|
+
specs:
|
5
|
+
sailthru-client (1.13)
|
6
|
+
json
|
7
|
+
multipart-post
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (2.3.14)
|
13
|
+
archive-tar-minitar (0.5.2)
|
14
|
+
columnize (0.3.4)
|
15
|
+
diff-lcs (1.1.3)
|
16
|
+
git (1.2.5)
|
17
|
+
guard (0.8.4)
|
18
|
+
thor (~> 0.14.6)
|
19
|
+
guard-rspec (0.5.0)
|
20
|
+
guard (>= 0.8.4)
|
21
|
+
i18n (0.6.0)
|
22
|
+
jeweler (1.6.4)
|
23
|
+
bundler (~> 1.0)
|
24
|
+
git (>= 1.2.5)
|
25
|
+
rake
|
26
|
+
json (1.6.1)
|
27
|
+
linecache19 (0.5.12)
|
28
|
+
ruby_core_source (>= 0.1.4)
|
29
|
+
metaclass (0.0.1)
|
30
|
+
mocha (0.10.0)
|
31
|
+
metaclass (~> 0.0.1)
|
32
|
+
multi_json (1.0.3)
|
33
|
+
multipart-post (1.1.3)
|
34
|
+
rake (0.9.2)
|
35
|
+
rspec (2.6.0)
|
36
|
+
rspec-core (~> 2.6.0)
|
37
|
+
rspec-expectations (~> 2.6.0)
|
38
|
+
rspec-mocks (~> 2.6.0)
|
39
|
+
rspec-core (2.6.4)
|
40
|
+
rspec-expectations (2.6.0)
|
41
|
+
diff-lcs (~> 1.1.2)
|
42
|
+
rspec-mocks (2.6.0)
|
43
|
+
ruby-debug-base19 (0.11.25)
|
44
|
+
columnize (>= 0.3.1)
|
45
|
+
linecache19 (>= 0.5.11)
|
46
|
+
ruby_core_source (>= 0.1.4)
|
47
|
+
ruby-debug19 (0.11.6)
|
48
|
+
columnize (>= 0.3.1)
|
49
|
+
linecache19 (>= 0.5.11)
|
50
|
+
ruby-debug-base19 (>= 0.11.19)
|
51
|
+
ruby_core_source (0.1.5)
|
52
|
+
archive-tar-minitar (>= 0.5.2)
|
53
|
+
simplecov (0.5.3)
|
54
|
+
multi_json (~> 1.0.3)
|
55
|
+
simplecov-html (~> 0.5.3)
|
56
|
+
simplecov-html (0.5.3)
|
57
|
+
thor (0.14.6)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
activesupport (< 3.0.0)
|
64
|
+
bundler (~> 1.0.0)
|
65
|
+
guard-rspec
|
66
|
+
i18n
|
67
|
+
jeweler (~> 1.6.4)
|
68
|
+
mocha
|
69
|
+
rspec
|
70
|
+
ruby-debug19
|
71
|
+
sailthru-client!
|
72
|
+
simplecov
|
data/Guardfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2, :cli => "--color --format nested" do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^spec/.+_spec\.rb$})
|
11
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
14
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
15
|
+
watch('spec/spec_helper.rb') { "spec" }
|
16
|
+
watch('config/routes.rb') { "spec/routing" }
|
17
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
18
|
+
# Capybara request specs
|
19
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
20
|
+
end
|
21
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Dan Langevin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
= Sailthru Mailer
|
2
|
+
|
3
|
+
An adapter that allows the usage of ActionMailer 3 syntax with Sailthru's Ruby Client Library
|
4
|
+
|
5
|
+
|
6
|
+
== Installation
|
7
|
+
|
8
|
+
gem install sailthru_mailer
|
9
|
+
rails g sailthru_mailer
|
10
|
+
|
11
|
+
This will generate an initializer in which you can put your api_key and api_secret. E.g.
|
12
|
+
|
13
|
+
# Rails.root/config/initializers/sailthru_mailer.rb
|
14
|
+
SailthruMailer.settings = {
|
15
|
+
:api_key => "MYKEY",
|
16
|
+
:api_secret => "MYSECRET",
|
17
|
+
:api_url => "https://api.sailthru.com"
|
18
|
+
}
|
19
|
+
|
20
|
+
== Setting Defaults
|
21
|
+
|
22
|
+
SailthruMailer supports the per-mailer configuration that ActionMailer provides.
|
23
|
+
|
24
|
+
class MyMailer < SailthruMailer::Base
|
25
|
+
defaults(:from => "lifebooker@lifebooker.com", :reply_to => "no-reply@lifebooker.com")
|
26
|
+
end
|
27
|
+
|
28
|
+
We also provide a (nicer) interface within a defaults block
|
29
|
+
|
30
|
+
class MyMailer < SailthruMailer::Base
|
31
|
+
defaults do
|
32
|
+
from("lifebooker@lifebooker.com")
|
33
|
+
reply_to("no-reply@lifebooker.com")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Or even outside of the defaults block (the block is just syntactic sugar)
|
38
|
+
|
39
|
+
class MyMailer < SailthruMailer::Base
|
40
|
+
from("lifebooker@lifebooker.com")
|
41
|
+
reply_to("no-reply@lifebooker.com")
|
42
|
+
end
|
43
|
+
|
44
|
+
== Usage
|
45
|
+
|
46
|
+
This gem is designed as a drop-in replacement for ActionMailer. You should be able to just replace all instances
|
47
|
+
of ActionMailer::Base with SailthruMailer::Base
|
48
|
+
|
49
|
+
== Under the Hood
|
50
|
+
|
51
|
+
There are some differences between the way ActionMailer and Sailthru work. ActionMailer provides use a Mail::Message, which is
|
52
|
+
basically just an email (headers and body) that has been through AbstractController's rendering engine.
|
53
|
+
|
54
|
+
== Examples
|
55
|
+
|
56
|
+
Sailthru has us place templates within their system and provide a template name, email address(es) and variables that go within the email.
|
57
|
+
We account for this by allowing you to name each method after a template and supply the variables within the body hash. #to_hash is called
|
58
|
+
on any objects in the body
|
59
|
+
|
60
|
+
# Rails.root/app/models/user.rb
|
61
|
+
class User < ActiveRecord::Base
|
62
|
+
# attributes: first_name, last_name, email
|
63
|
+
end
|
64
|
+
|
65
|
+
# Rails.root/app/mailers/my_mailer.rb
|
66
|
+
class MyMailer < SailthruMailer::Base
|
67
|
+
def sailthru_template_name(user)
|
68
|
+
to(user.email) # aliased as recipients(user.email)
|
69
|
+
body[:user] = user
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
MyMailer.sailthru_template_name(User.first).deliver
|
74
|
+
|
75
|
+
This will send a request to Sailthru:
|
76
|
+
|
77
|
+
sailthru.send(:sailthru_template_name, "dan@lifebooker.com", {:user => {:first_name => "Dan", :last_name => "Langevin", :email => "dan.langevin@lifebooker.com"}}, {} #additional options, Time.now.utc.to_s #send date)
|
78
|
+
|
79
|
+
== Contributing to Sailthru Mailer
|
80
|
+
|
81
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
82
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
83
|
+
* Fork the project
|
84
|
+
* Start a feature/bugfix branch
|
85
|
+
* Commit and push until you are happy with your contribution
|
86
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
87
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
88
|
+
|
89
|
+
== Copyright
|
90
|
+
|
91
|
+
Copyright (c) 2011 Dan Langevin. See LICENSE.txt for
|
92
|
+
further details.
|
93
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "sailthru_mailer"
|
18
|
+
gem.homepage = "http://github.com/dlangevin/sailthru_mailer"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Wrapper for Sailthru ruby gem}
|
21
|
+
gem.description = %Q{Implements ActionMailer compatible syntax}
|
22
|
+
gem.email = "dan.langevin@lifebooker.com"
|
23
|
+
gem.authors = ["Dan Langevin"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "sailthru_mailer #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,156 @@
|
|
1
|
+
module SailthruMailer
|
2
|
+
class Base
|
3
|
+
VALID_CONFIGURATION_METHODS = [:to, :from, :cc, :bcc, :reply_to, :date]
|
4
|
+
DEPRECATED_CONFIGURATION_METHODS = [:subject]
|
5
|
+
CONFIGURATION_METHODS = VALID_CONFIGURATION_METHODS + DEPRECATED_CONFIGURATION_METHODS
|
6
|
+
|
7
|
+
# we have accessors for
|
8
|
+
attr_accessor :template
|
9
|
+
|
10
|
+
private_class_method :new #nodoc
|
11
|
+
|
12
|
+
# private initializer
|
13
|
+
def initialize(name, *args)
|
14
|
+
self.template = name
|
15
|
+
self.send(name, *args)
|
16
|
+
end
|
17
|
+
|
18
|
+
# setter/getter method for each config method
|
19
|
+
# falls back to the class method
|
20
|
+
CONFIGURATION_METHODS.each do |m|
|
21
|
+
class_eval <<-EOF, __FILE__, __LINE__ +1
|
22
|
+
def #{m}(val = nil)
|
23
|
+
@#{m} = val unless val.nil?
|
24
|
+
@#{m} ||= self.class.#{m}
|
25
|
+
end
|
26
|
+
EOF
|
27
|
+
end
|
28
|
+
DEPRECATED_CONFIGURATION_METHODS.each do |m|
|
29
|
+
class_eval <<-EOF, __FILE__, __LINE__ +1
|
30
|
+
def #{m}(val = nil)
|
31
|
+
::ActiveSupport::Deprecation.warn("#{m} has no effect with Sailthru - please specify it in the Sailthru admin", caller(1))
|
32
|
+
@#{m} = val unless val.nil?
|
33
|
+
@#{m} ||= self.class.#{m}
|
34
|
+
end
|
35
|
+
EOF
|
36
|
+
end
|
37
|
+
|
38
|
+
# alias to as recipients for AM2 compatibility
|
39
|
+
alias_method :recipients, :to
|
40
|
+
|
41
|
+
# variables for the template
|
42
|
+
def vars(val = nil)
|
43
|
+
@vars = val unless val.nil?
|
44
|
+
@vars ||= {}
|
45
|
+
end
|
46
|
+
def vars=(val)
|
47
|
+
vars(val)
|
48
|
+
end
|
49
|
+
# we want to actually call it body for backwards compatibility
|
50
|
+
alias_method :body, :vars
|
51
|
+
alias_method :body=, :vars=
|
52
|
+
|
53
|
+
# send the mail
|
54
|
+
def deliver
|
55
|
+
# handle test mode
|
56
|
+
return SailthruMailer.deliveries << self if SailthruMailer.test
|
57
|
+
# response = sailthru.send(template_name, email, vars, options, schedule_time)
|
58
|
+
self.class.connection.deliver(
|
59
|
+
self.template,
|
60
|
+
self.all_recipients,
|
61
|
+
self.formatted_vars,
|
62
|
+
self.formatted_options,
|
63
|
+
(self.date || Time.now).utc.to_s
|
64
|
+
)
|
65
|
+
end
|
66
|
+
# formatted variable hash, ready for JSON encoding
|
67
|
+
def formatted_vars
|
68
|
+
{}.tap do |ret|
|
69
|
+
self.vars.each_pair do |k,v|
|
70
|
+
ret[k] = self.prep_for_json(v)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
protected
|
75
|
+
# prepare a value to be converted to JSON
|
76
|
+
def prep_for_json(val)
|
77
|
+
val = val.collect{|v| self.prep_for_json(v)} if val.is_a?(Array)
|
78
|
+
# recursive call for hashes
|
79
|
+
if val.is_a?(Hash)
|
80
|
+
val.each_pair{|k,v| val[k] = self.prep_for_json(v)}
|
81
|
+
# otherwise try to convert to a hash (e.g. ActiveModel)
|
82
|
+
elsif val.respond_to?(:to_hash)
|
83
|
+
val = self.prep_for_json(val.to_hash)
|
84
|
+
end
|
85
|
+
val
|
86
|
+
end
|
87
|
+
# get the options for this send
|
88
|
+
def formatted_options
|
89
|
+
{}.tap do |ret|
|
90
|
+
ret[:replyto] = self.reply_to unless self.reply_to.blank?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
# list of all email addresses
|
94
|
+
# emails can be specified as follows
|
95
|
+
# to ["email1@test.com", "email2@test.com"]
|
96
|
+
# to "email1@test.com, email2@test.com; email3@test.com"
|
97
|
+
# to ["email1@test.com; email2@test.com"]
|
98
|
+
def all_recipients
|
99
|
+
[:to, :cc, :bcc].collect{|type| Array.wrap(self.send(type)).collect{|email| email.split(/;,/)}}.flatten.uniq.join(", ")
|
100
|
+
end
|
101
|
+
|
102
|
+
class << self
|
103
|
+
# called when someone inherits from us
|
104
|
+
def inherited(klass)
|
105
|
+
VALID_CONFIGURATION_METHODS.each do |m|
|
106
|
+
klass.send(m, self.send(m))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def connection(reload = false)
|
111
|
+
@connection = nil if reload
|
112
|
+
@connection ||= SailthruMailer::Connection.new
|
113
|
+
end
|
114
|
+
# configuration options that can be set if a value is provided or gotten otherwise
|
115
|
+
VALID_CONFIGURATION_METHODS.each do |m|
|
116
|
+
class_eval <<-EOF, __FILE__, __LINE__ +1
|
117
|
+
def #{m}(val = nil)
|
118
|
+
@#{m} = val unless val.nil?
|
119
|
+
@#{m}
|
120
|
+
end
|
121
|
+
EOF
|
122
|
+
end
|
123
|
+
DEPRECATED_CONFIGURATION_METHODS.each do |m|
|
124
|
+
class_eval <<-EOF, __FILE__, __LINE__ +1
|
125
|
+
def #{m}(val = nil)
|
126
|
+
::ActiveSupport::Deprecation.warn("#{m} has no effect with Sailthru - please specify it in the Sailthru admin", caller(5))
|
127
|
+
@#{m} = val unless val.nil?
|
128
|
+
@#{m}
|
129
|
+
end
|
130
|
+
EOF
|
131
|
+
end
|
132
|
+
# alias to as recipients for AM2 compatibility
|
133
|
+
alias_method :recipients, :to
|
134
|
+
|
135
|
+
protected
|
136
|
+
# just here to give us nicer syntax
|
137
|
+
def defaults(vals = nil, &block)
|
138
|
+
return instance_exec(&block) if block_given?
|
139
|
+
vals.each_pair{|k,v| self.send(k, v)}
|
140
|
+
end
|
141
|
+
# if this is a valid public instance method, we proceed
|
142
|
+
def method_missing(m, *args, &block)
|
143
|
+
if self.action_defined?(m)
|
144
|
+
return new(m, *args)
|
145
|
+
else
|
146
|
+
return super
|
147
|
+
end
|
148
|
+
end
|
149
|
+
#
|
150
|
+
def action_defined?(m)
|
151
|
+
self.public_instance_methods.include?(m.to_sym)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SailthruMailer
|
2
|
+
class Connection
|
3
|
+
def initialize
|
4
|
+
@client = Sailthru::SailthruClient.new(
|
5
|
+
SailthruMailer.settings[:api_key],
|
6
|
+
SailthruMailer.settings[:api_secret],
|
7
|
+
SailthruMailer.settings[:api_url]
|
8
|
+
)
|
9
|
+
end
|
10
|
+
def deliver(*args)
|
11
|
+
@client.send(*args)
|
12
|
+
end
|
13
|
+
# proxy all methods to @client
|
14
|
+
def method_missing(m, *args, &block)
|
15
|
+
@client.__send__(m, *args, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext"
|
3
|
+
require "sailthru"
|
4
|
+
require 'sailthru_mailer/base'
|
5
|
+
require 'sailthru_mailer/connection'
|
6
|
+
|
7
|
+
module SailthruMailer
|
8
|
+
|
9
|
+
mattr_accessor :settings; self.settings = {}
|
10
|
+
mattr_accessor :test; self.test = false
|
11
|
+
mattr_accessor :deliveries; self.deliveries = []
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "sailthru_mailer"
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dan Langevin"]
|
12
|
+
s.date = "2011-12-14"
|
13
|
+
s.description = "Implements ActionMailer compatible syntax"
|
14
|
+
s.email = "dan.langevin@lifebooker.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"Guardfile",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"lib/sailthru_mailer.rb",
|
30
|
+
"lib/sailthru_mailer/base.rb",
|
31
|
+
"lib/sailthru_mailer/connection.rb",
|
32
|
+
"sailthru_mailer.gemspec",
|
33
|
+
"spec/lib/sailthru_mailer/base_spec.rb",
|
34
|
+
"spec/lib/sailthru_mailer_spec.rb",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = "http://github.com/dlangevin/sailthru_mailer"
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = "1.8.10"
|
41
|
+
s.summary = "Wrapper for Sailthru ruby gem"
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<activesupport>, ["< 3.0.0"])
|
48
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
49
|
+
s.add_runtime_dependency(%q<sailthru-client>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<guard-rspec>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
55
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<activesupport>, ["< 3.0.0"])
|
59
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
60
|
+
s.add_dependency(%q<sailthru-client>, [">= 0"])
|
61
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
63
|
+
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
66
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
67
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<activesupport>, ["< 3.0.0"])
|
71
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
72
|
+
s.add_dependency(%q<sailthru-client>, [">= 0"])
|
73
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
75
|
+
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
76
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
77
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
78
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
79
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe SailthruMailer::Base do
|
4
|
+
context "Sending Mail With Stubs" do
|
5
|
+
before(:all) do
|
6
|
+
TestMailer = Class.new(SailthruMailer::Base)
|
7
|
+
TestMailer.class_eval do
|
8
|
+
def my_mail(opts = {})
|
9
|
+
body[:x] = "y"
|
10
|
+
body.merge!(opts)
|
11
|
+
end
|
12
|
+
def complex_mail(addr)
|
13
|
+
to(addr)
|
14
|
+
from("super-secret-address@test.net")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
it "should proxy deliver methods to templates named after the method" do
|
19
|
+
m = TestMailer.my_mail(:abc => "123")
|
20
|
+
m.template.to_s.should eql "my_mail"
|
21
|
+
end
|
22
|
+
it "should include any data set for the body of the email in the feed" do
|
23
|
+
m = TestMailer.my_mail(:abc => "123")
|
24
|
+
m.formatted_vars.should eql({:x => "y", :abc => "123"})
|
25
|
+
end
|
26
|
+
it "should call to_hash on objects in the body if necessary" do
|
27
|
+
MyObject = Class.new do
|
28
|
+
def to_hash
|
29
|
+
{
|
30
|
+
:k => "v",
|
31
|
+
:arr => ["one", "two", "three"]
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
m = TestMailer.my_mail(:user => MyObject.new)
|
36
|
+
m.formatted_vars.should eql({:x => "y", :user => {:k => "v", :arr => ["one", "two", "three"]}})
|
37
|
+
end
|
38
|
+
it "should include default to/from addresses" do
|
39
|
+
TestMailer.class_eval do
|
40
|
+
defaults do
|
41
|
+
from("test@tester.com")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
TestMailer.my_mail.from.should eql("test@tester.com")
|
45
|
+
TestMailer.complex_mail("dan@lifebooker.com").from.should eql("super-secret-address@test.net")
|
46
|
+
|
47
|
+
TestMailer.class_eval do
|
48
|
+
defaults(:from => "test2@tester.com")
|
49
|
+
end
|
50
|
+
TestMailer.my_mail.from.should eql("test2@tester.com")
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should inherit default options" do
|
55
|
+
ParentMailer = Class.new(SailthruMailer::Base) do
|
56
|
+
defaults do
|
57
|
+
from("test@tester.com")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
ChildMailer = Class.new(ParentMailer)
|
61
|
+
GrandChildMailer = Class.new(ChildMailer)
|
62
|
+
ChildMailer.from.should eql "test@tester.com"
|
63
|
+
GrandChildMailer.from.should eql "test@tester.com"
|
64
|
+
end
|
65
|
+
it "should send a request to sailthru" do
|
66
|
+
t = Time.now.utc
|
67
|
+
Time.stubs(:now).returns(t)
|
68
|
+
SailthruMailer::Connection.any_instance.expects(:deliver).with(:complex_mail, 'dan@lifebooker.com', {}, {}, t.to_s)
|
69
|
+
TestMailer.complex_mail("dan@lifebooker.com").deliver
|
70
|
+
end
|
71
|
+
context "Send options" do
|
72
|
+
|
73
|
+
before(:all) do
|
74
|
+
TestMailer.class_eval do
|
75
|
+
def options_mail
|
76
|
+
reply_to("myreplyaddress@test.com")
|
77
|
+
date(Time.now + 10.days)
|
78
|
+
to("dan@lifebooker.com")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should allow the user to specify send options" do
|
84
|
+
t = Time.now
|
85
|
+
Time.stubs(:now).returns(t)
|
86
|
+
SailthruMailer::Connection.any_instance.expects(:deliver).with(:options_mail, 'dan@lifebooker.com', {}, {:replyto => "myreplyaddress@test.com"}, (t + 10.days).utc.to_s)
|
87
|
+
TestMailer.options_mail.deliver
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should allow us to specify test mode" do
|
91
|
+
SailthruMailer.test = true
|
92
|
+
TestMailer.options_mail.deliver
|
93
|
+
SailthruMailer.deliveries.length.should eql 1
|
94
|
+
SailthruMailer.deliveries.last.template.should eql(:options_mail)
|
95
|
+
SailthruMailer.deliveries.last.vars.should eql({})
|
96
|
+
SailthruMailer.test = false
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "SailthruMailer" do
|
4
|
+
context "Setup" do
|
5
|
+
it "should allow for configuration" do
|
6
|
+
SailthruMailer.settings = {
|
7
|
+
:api_key => "XYZ",
|
8
|
+
:api_secret => "ABC",
|
9
|
+
:api_url => "https://api.sailthru.com"
|
10
|
+
}
|
11
|
+
SailthruMailer.settings[:api_key].should eql "XYZ"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
require 'rspec'
|
6
|
+
require 'sailthru_mailer'
|
7
|
+
require 'ruby-debug'
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Bundler.require(:default, :test)
|
12
|
+
Debugger.start
|
13
|
+
|
14
|
+
SimpleCov.start do
|
15
|
+
add_filter "/spec/"
|
16
|
+
end
|
17
|
+
|
18
|
+
SimpleCov.at_exit do
|
19
|
+
SimpleCov.result.format!
|
20
|
+
end
|
21
|
+
|
22
|
+
# Requires supporting files with custom matchers and macros, etc,
|
23
|
+
# in ./support/ and its subdirectories.
|
24
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.mock_with :mocha
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sailthru_mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Langevin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &70263943152500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - <
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70263943152500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: i18n
|
27
|
+
requirement: &70263943151000 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70263943151000
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: sailthru-client
|
38
|
+
requirement: &70263943146200 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70263943146200
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: ruby-debug19
|
49
|
+
requirement: &70263943144840 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70263943144840
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rspec
|
60
|
+
requirement: &70263943143300 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70263943143300
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: &70263943140880 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70263943140880
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: bundler
|
82
|
+
requirement: &70263943131960 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.0.0
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70263943131960
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: jeweler
|
93
|
+
requirement: &70263943130060 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.6.4
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70263943130060
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: simplecov
|
104
|
+
requirement: &70263943127320 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *70263943127320
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: mocha
|
115
|
+
requirement: &70263943122320 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *70263943122320
|
124
|
+
description: Implements ActionMailer compatible syntax
|
125
|
+
email: dan.langevin@lifebooker.com
|
126
|
+
executables: []
|
127
|
+
extensions: []
|
128
|
+
extra_rdoc_files:
|
129
|
+
- LICENSE.txt
|
130
|
+
- README.rdoc
|
131
|
+
files:
|
132
|
+
- .document
|
133
|
+
- .rspec
|
134
|
+
- Gemfile
|
135
|
+
- Gemfile.lock
|
136
|
+
- Guardfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.rdoc
|
139
|
+
- Rakefile
|
140
|
+
- VERSION
|
141
|
+
- lib/sailthru_mailer.rb
|
142
|
+
- lib/sailthru_mailer/base.rb
|
143
|
+
- lib/sailthru_mailer/connection.rb
|
144
|
+
- sailthru_mailer.gemspec
|
145
|
+
- spec/lib/sailthru_mailer/base_spec.rb
|
146
|
+
- spec/lib/sailthru_mailer_spec.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
homepage: http://github.com/dlangevin/sailthru_mailer
|
149
|
+
licenses:
|
150
|
+
- MIT
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ! '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
segments:
|
162
|
+
- 0
|
163
|
+
hash: -2881211978847989942
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
none: false
|
166
|
+
requirements:
|
167
|
+
- - ! '>='
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 1.8.10
|
173
|
+
signing_key:
|
174
|
+
specification_version: 3
|
175
|
+
summary: Wrapper for Sailthru ruby gem
|
176
|
+
test_files: []
|