mass_mandrill 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +44 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/lib/mass_mandrill.rb +13 -0
- data/lib/mass_mandrill/config.rb +8 -0
- data/lib/mass_mandrill/mandrill_mail.rb +21 -0
- data/lib/mass_mandrill/mandrill_mailer.rb +59 -0
- data/spec/mass_mandrill/config_spec.rb +11 -0
- data/spec/mass_mandrill/mandrill_mailer_spec.rb +25 -0
- data/spec/spec_helper.rb +11 -0
- metadata +131 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
columnize (0.3.6)
|
5
|
+
debugger (1.5.0)
|
6
|
+
columnize (>= 0.3.1)
|
7
|
+
debugger-linecache (~> 1.2.0)
|
8
|
+
debugger-ruby_core_source (~> 1.2.0)
|
9
|
+
debugger-linecache (1.2.0)
|
10
|
+
debugger-ruby_core_source (1.2.0)
|
11
|
+
diff-lcs (1.2.1)
|
12
|
+
excon (0.16.10)
|
13
|
+
git (1.2.5)
|
14
|
+
jeweler (1.8.4)
|
15
|
+
bundler (~> 1.0)
|
16
|
+
git (>= 1.2.5)
|
17
|
+
rake
|
18
|
+
rdoc
|
19
|
+
json (1.7.7)
|
20
|
+
mandrill-api (1.0.17)
|
21
|
+
excon (~> 0.16.0)
|
22
|
+
json (~> 1.7.7)
|
23
|
+
rake (10.0.3)
|
24
|
+
rdoc (4.0.0)
|
25
|
+
json (~> 1.4)
|
26
|
+
rspec (2.13.0)
|
27
|
+
rspec-core (~> 2.13.0)
|
28
|
+
rspec-expectations (~> 2.13.0)
|
29
|
+
rspec-mocks (~> 2.13.0)
|
30
|
+
rspec-core (2.13.1)
|
31
|
+
rspec-expectations (2.13.0)
|
32
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
33
|
+
rspec-mocks (2.13.0)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bundler (~> 1.3.3)
|
40
|
+
debugger (~> 1.5.0)
|
41
|
+
jeweler (~> 1.8.4)
|
42
|
+
mandrill-api (~> 1.0.16)
|
43
|
+
rdoc (~> 4.0.0)
|
44
|
+
rspec (~> 2.13.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Nebojša Stričević
|
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,19 @@
|
|
1
|
+
= mandrill_template
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to mandrill_template
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* 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.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2013 Nebojša Stričević. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
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.name = "mass_mandrill"
|
17
|
+
gem.homepage = "https://github.com/trisignia/mass_mandrill"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %Q{Send Mandrill emails}
|
20
|
+
gem.description = %Q{Send Mandrill template emails}
|
21
|
+
gem.email = "nebojsa.stricevic@gmail.com"
|
22
|
+
gem.authors = ["Trisignia", "Nebojša Stričević"]
|
23
|
+
# dependencies defined in Gemfile
|
24
|
+
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
require 'rspec/core'
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
30
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
require 'rdoc/task'
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
38
|
+
|
39
|
+
rdoc.rdoc_dir = 'rdoc'
|
40
|
+
rdoc.title = "mass_mandrill #{version}"
|
41
|
+
rdoc.rdoc_files.include('README*')
|
42
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
43
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'mandrill'
|
2
|
+
|
3
|
+
module MassMandrill
|
4
|
+
class MandrillMail
|
5
|
+
attr_reader :message
|
6
|
+
|
7
|
+
def initialize(template_name, template_content, message)
|
8
|
+
@template_name = template_name
|
9
|
+
@template_content = template_content
|
10
|
+
@message = message
|
11
|
+
|
12
|
+
@mandrill = ::Mandrill::API.new(MassMandrill.config.api_key)
|
13
|
+
end
|
14
|
+
|
15
|
+
def deliver
|
16
|
+
@mandrill.messages.send_template(@template_name,
|
17
|
+
@template_content,
|
18
|
+
@message)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path('lib/mass_mandrill/mandrill_mail')
|
2
|
+
|
3
|
+
module MassMandrill
|
4
|
+
class MandrillMailer
|
5
|
+
attr_reader :message
|
6
|
+
|
7
|
+
def initialize(template_name)
|
8
|
+
@template_name = template_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.method_missing(method_name, *args)
|
12
|
+
new(method_name).send(method_name, *args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def mail(options)
|
16
|
+
@message = build_message(options)
|
17
|
+
@template_content = []
|
18
|
+
@template_name = options[:template] if options[:template]
|
19
|
+
|
20
|
+
MandrillMail.new(@template_name, @template_content, @message)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def build_message(options)
|
26
|
+
{
|
27
|
+
:subject => options[:subject],
|
28
|
+
:from_email => from_email(options[:from]),
|
29
|
+
:from_name => from_name(options[:from]),
|
30
|
+
:to => to(options[:to]),
|
31
|
+
:global_merge_vars => options[:global_merge_vars],
|
32
|
+
:merge_vars => options[:merge_vars]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def to(addresses)
|
37
|
+
if addresses.is_a?(Array)
|
38
|
+
addresses.map { |address| { :email => address } }
|
39
|
+
else
|
40
|
+
{ :email => addresses }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def from_email(from)
|
45
|
+
scan = scan_email(from)
|
46
|
+
scan.empty? ? from : scan.first[1..-2]
|
47
|
+
end
|
48
|
+
|
49
|
+
def from_name(from)
|
50
|
+
unless scan_email(from).empty?
|
51
|
+
from.split(/\</).first.strip
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def scan_email(from)
|
56
|
+
from.scan(/\<.*\>/)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MassMandrill::MandrillMailer do
|
4
|
+
class DummyMailer < MassMandrill::MandrillMailer
|
5
|
+
def dummy_notification
|
6
|
+
mail(:from => "Example Company <example.company@example.com>",
|
7
|
+
:global_merge_vars => { :name => 'var1', :content => 'var1_value' })
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
::Mandrill::API.stub(:new)
|
13
|
+
@mailer = DummyMailer.dummy_notification
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "message" do
|
17
|
+
before do
|
18
|
+
@message = @mailer.message
|
19
|
+
end
|
20
|
+
|
21
|
+
specify { @message[:from_email].should == "example.company@example.com" }
|
22
|
+
specify { @message[:from_name].should == "Example Company" }
|
23
|
+
specify { @message[:global_merge_vars].should == { :name => 'var1', :content => 'var1_value' } }
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'mass_mandrill'
|
3
|
+
|
4
|
+
# Requires supporting files with custom matchers and macros, etc,
|
5
|
+
# in ./support/ and its subdirectories.
|
6
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.before(:each) do
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mass_mandrill
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Trisignia
|
9
|
+
- Nebojša Stričević
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-03-16 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mandrill-api
|
17
|
+
requirement: &19551200 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.16
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *19551200
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &19549780 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.13.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *19549780
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: debugger
|
39
|
+
requirement: &19548720 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.5.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *19548720
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rdoc
|
50
|
+
requirement: &19547540 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 4.0.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *19547540
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: jeweler
|
61
|
+
requirement: &19546540 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.8.4
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *19546540
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
requirement: &19545500 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.3.3
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *19545500
|
81
|
+
description: Send Mandrill template emails
|
82
|
+
email: nebojsa.stricevic@gmail.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files:
|
86
|
+
- LICENSE.txt
|
87
|
+
- README.rdoc
|
88
|
+
files:
|
89
|
+
- .document
|
90
|
+
- Gemfile
|
91
|
+
- Gemfile.lock
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.rdoc
|
94
|
+
- Rakefile
|
95
|
+
- VERSION
|
96
|
+
- lib/mass_mandrill.rb
|
97
|
+
- lib/mass_mandrill/config.rb
|
98
|
+
- lib/mass_mandrill/mandrill_mail.rb
|
99
|
+
- lib/mass_mandrill/mandrill_mailer.rb
|
100
|
+
- spec/mass_mandrill/config_spec.rb
|
101
|
+
- spec/mass_mandrill/mandrill_mailer_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/trisignia/mass_mandrill
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: 3296246128007628353
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.11
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Send Mandrill emails
|
131
|
+
test_files: []
|