mailstro 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +42 -7
- data/lib/mailstro.rb +47 -13
- data/lib/mailstro/delivery.rb +16 -10
- data/lib/mailstro/error.rb +0 -2
- data/lib/mailstro/list_delivery.rb +21 -10
- data/lib/mailstro/list_subscribe.rb +9 -9
- data/lib/mailstro/list_unsubscribe.rb +9 -9
- data/lib/mailstro/real_strategy.rb +2 -0
- data/lib/mailstro/rspec.rb +3 -7
- data/lib/mailstro/test_strategy.rb +57 -0
- data/lib/mailstro/version.rb +1 -1
- data/mailstro-ruby.gemspec +5 -5
- data/spec/integration/delivery_spec.rb +14 -6
- data/spec/integration/list_delivery_spec.rb +13 -7
- data/spec/integration/list_subscribe_spec.rb +5 -3
- data/spec/integration/list_unsubscribe_spec.rb +5 -3
- data/spec/mailstro/test_strategy_spec.rb +83 -0
- data/spec/mailstro_spec.rb +2 -14
- data/spec/spec_helper.rb +4 -5
- metadata +12 -9
- data/lib/mailstro/test.rb +0 -41
- data/spec/mailstro/test_spec.rb +0 -71
data/Readme.md
CHANGED
@@ -30,22 +30,57 @@ TODO: Write a gem description
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
-
|
33
|
+
Sending a basic email.
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
Mailstro.deliver(
|
36
|
+
Mailstro.deliver(
|
37
|
+
:to => 'shanon@mailstroapp.com',
|
38
|
+
:template_name => :welcome,
|
39
|
+
:template_data => {
|
40
|
+
:coupon_code => 'THANKS01'
|
41
|
+
}
|
42
|
+
)
|
37
43
|
```
|
38
44
|
|
39
|
-
|
45
|
+
Sending an email to a list of users, with subscription management.
|
40
46
|
|
41
47
|
```ruby
|
42
|
-
Mailstro.
|
43
|
-
Mailstro.list_subscribe(:customers, 'fred@mailstroapp.com')
|
44
|
-
Mailstro.list_unsubscribe(:customers, 'jack@mailstroapp.com')
|
48
|
+
Mailstro.subscribe('jack@mailstroapp.com', :build_watchers, project_id)
|
45
49
|
|
46
|
-
Mailstro.
|
50
|
+
Mailstro.deliver(
|
51
|
+
:to => [:build_watchers, project_id]
|
52
|
+
:template_name => :build_failure,
|
53
|
+
:template_data => {
|
54
|
+
:commit => '575ca555c23eca098202'
|
55
|
+
}
|
56
|
+
)
|
57
|
+
|
58
|
+
Mailstro.unsubscribe('jack@mailstroapp.com', :build_watchers, project_id)
|
47
59
|
```
|
48
60
|
|
61
|
+
## RSpec Test Mode
|
62
|
+
|
63
|
+
Require the mailstro spec helper to automatically enable test mode.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
require 'mailsto/rspec'
|
67
|
+
```
|
68
|
+
|
69
|
+
Verify emails are being sent with simple matchers.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Mailstro.deliver(
|
73
|
+
:to => 'shanon@mailstroapp.com',
|
74
|
+
:template_name => :welcome,
|
75
|
+
)
|
76
|
+
|
77
|
+
Mailstro.should have_delivered(:welcome)
|
78
|
+
|
79
|
+
Mailstro.should have_subscribed('a@a.com', :watchers, 2)
|
80
|
+
Mailstro.should have_unsubscribed('a@a.com', :watchers, 2)
|
81
|
+
```
|
82
|
+
|
83
|
+
|
49
84
|
## Contributing
|
50
85
|
|
51
86
|
1. Fork it
|
data/lib/mailstro.rb
CHANGED
@@ -1,36 +1,70 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
1
3
|
require_relative "mailstro/version"
|
2
4
|
require_relative "mailstro/configuration"
|
3
|
-
require_relative "mailstro/resource"
|
4
5
|
require_relative "mailstro/error"
|
6
|
+
require_relative "mailstro/resource"
|
5
7
|
require_relative "mailstro/delivery"
|
6
8
|
require_relative "mailstro/list_delivery"
|
7
9
|
require_relative "mailstro/list_subscribe"
|
8
10
|
require_relative "mailstro/list_unsubscribe"
|
9
11
|
|
10
12
|
module Mailstro
|
13
|
+
|
14
|
+
# Allows us to remove default behaviour during testing.
|
15
|
+
class RealStrategy
|
16
|
+
class << self
|
17
|
+
def deliver(options)
|
18
|
+
Delivery.new(options).deliver
|
19
|
+
end
|
20
|
+
def list_deliver(options)
|
21
|
+
ListDelivery.new(options).deliver
|
22
|
+
end
|
23
|
+
def subscribe(contact_email, list_type, list_name)
|
24
|
+
ListSubscribe.new(contact_email, list_type, list_name).deliver
|
25
|
+
end
|
26
|
+
def unsubscribe(contact_email, list_type, list_name)
|
27
|
+
ListUnsubscribe.new(contact_email, list_type, list_name).deliver
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
11
32
|
class << self
|
12
|
-
attr_accessor :configuration
|
33
|
+
attr_accessor :configuration, :strategy
|
13
34
|
end
|
14
35
|
|
36
|
+
@strategy = RealStrategy
|
37
|
+
@configuration = Configuration.new
|
38
|
+
|
15
39
|
def self.configure
|
16
|
-
|
17
|
-
|
18
|
-
|
40
|
+
yield(@configuration) && @configuration.validate!
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.deliver(options)
|
44
|
+
if options[:to].is_a?(Array)
|
45
|
+
@strategy.list_deliver(options)
|
46
|
+
else
|
47
|
+
@strategy.deliver(options)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.subscribe(contact_email, list_type, list_name)
|
52
|
+
@strategy.subscribe(contact_email, list_type, list_name)
|
19
53
|
end
|
20
54
|
|
21
|
-
def self.
|
22
|
-
|
55
|
+
def self.unsubscribe(contact_email, list_type, list_name)
|
56
|
+
@strategy.unsubscribe(contact_email, list_type, list_name)
|
23
57
|
end
|
24
58
|
|
25
|
-
def self.
|
26
|
-
|
59
|
+
def self.has_delivered?(template_name)
|
60
|
+
TestStrategy.has_delivered?(template_name)
|
27
61
|
end
|
28
62
|
|
29
|
-
def self.
|
30
|
-
|
63
|
+
def self.has_subscribed?(contact_email, list_type, list_name)
|
64
|
+
TestStrategy.has_subscribed?(contact_email, list_type, list_name)
|
31
65
|
end
|
32
66
|
|
33
|
-
def self.
|
34
|
-
|
67
|
+
def self.has_unsubscribed?(contact_email, list_type, list_name)
|
68
|
+
TestStrategy.has_unsubscribed?(contact_email, list_type, list_name)
|
35
69
|
end
|
36
70
|
end
|
data/lib/mailstro/delivery.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
module Mailstro
|
2
2
|
class Delivery < Resource
|
3
|
-
def
|
4
|
-
|
3
|
+
def initialize(options)
|
4
|
+
@options = options
|
5
5
|
end
|
6
6
|
|
7
|
-
|
7
|
+
def contact_email
|
8
|
+
@options.fetch(:to)
|
9
|
+
end
|
10
|
+
|
11
|
+
def template_name
|
12
|
+
@options.fetch(:template_name)
|
13
|
+
end
|
8
14
|
|
9
|
-
def
|
10
|
-
@
|
11
|
-
@contact_email = contact_email
|
12
|
-
@data = data
|
15
|
+
def template_data
|
16
|
+
@options.fetch(:template_data, nil)
|
13
17
|
end
|
14
18
|
|
15
19
|
def deliver
|
16
|
-
post("deliveries",
|
17
|
-
|
18
|
-
|
20
|
+
post("deliveries",
|
21
|
+
:contact_email => contact_email,
|
22
|
+
:template_name => template_name,
|
23
|
+
:template_data => template_data
|
24
|
+
)
|
19
25
|
end
|
20
26
|
end
|
21
27
|
end
|
data/lib/mailstro/error.rb
CHANGED
@@ -1,21 +1,32 @@
|
|
1
1
|
module Mailstro
|
2
2
|
class ListDelivery < Resource
|
3
|
-
def
|
4
|
-
|
3
|
+
def initialize(options)
|
4
|
+
@options = options
|
5
5
|
end
|
6
6
|
|
7
|
-
|
7
|
+
def list_type
|
8
|
+
@options.fetch(:to)[0]
|
9
|
+
end
|
10
|
+
|
11
|
+
def list_name
|
12
|
+
@options.fetch(:to)[1]
|
13
|
+
end
|
14
|
+
|
15
|
+
def template_name
|
16
|
+
@options.fetch(:template_name)
|
17
|
+
end
|
8
18
|
|
9
|
-
def
|
10
|
-
@
|
11
|
-
@list_name = list_name
|
12
|
-
@data = data
|
19
|
+
def template_data
|
20
|
+
@options.fetch(:template_data, nil)
|
13
21
|
end
|
14
22
|
|
15
23
|
def deliver
|
16
|
-
post("lists/deliveries",
|
17
|
-
|
18
|
-
|
24
|
+
post("lists/deliveries",
|
25
|
+
:list_type => list_type,
|
26
|
+
:list_name => list_name,
|
27
|
+
:template_name => template_name,
|
28
|
+
:template_data => template_data
|
29
|
+
)
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Mailstro
|
2
2
|
class ListSubscribe < Resource
|
3
|
-
|
4
|
-
new(list_name, contact_email).deliver
|
5
|
-
end
|
6
|
-
|
7
|
-
attr_reader :list_name, :contact_email
|
3
|
+
attr_reader :contact_email, :list_type, :list_name
|
8
4
|
|
9
|
-
def initialize(
|
10
|
-
@list_name = list_name
|
5
|
+
def initialize(contact_email, list_type, list_name)
|
11
6
|
@contact_email = contact_email
|
7
|
+
@list_type = list_type
|
8
|
+
@list_name = list_name
|
12
9
|
end
|
13
10
|
|
14
11
|
def deliver
|
15
|
-
post("lists/subscribers",
|
16
|
-
|
12
|
+
post("lists/subscribers",
|
13
|
+
:contact_email => @contact_email,
|
14
|
+
:list_type => @list_type,
|
15
|
+
:list_name => @list_name
|
16
|
+
)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Mailstro
|
2
2
|
class ListUnsubscribe < Resource
|
3
|
-
|
4
|
-
new(list_name, contact_email).deliver
|
5
|
-
end
|
6
|
-
|
7
|
-
attr_reader :list_name, :contact_email
|
3
|
+
attr_reader :contact_email, :list_type, :list_name
|
8
4
|
|
9
|
-
def initialize(
|
10
|
-
@list_name = list_name
|
5
|
+
def initialize(contact_email, list_type, list_name)
|
11
6
|
@contact_email = contact_email
|
7
|
+
@list_type = list_type
|
8
|
+
@list_name = list_name
|
12
9
|
end
|
13
10
|
|
14
11
|
def deliver
|
15
|
-
delete("lists/subscribers",
|
16
|
-
|
12
|
+
delete("lists/subscribers",
|
13
|
+
:contact_email => @contact_email,
|
14
|
+
:list_type => @list_type,
|
15
|
+
:list_name => @list_name
|
16
|
+
)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/mailstro/rspec.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
require 'mailstro/
|
1
|
+
require 'mailstro/test_strategy'
|
2
2
|
|
3
3
|
RSpec.configure do |config|
|
4
4
|
config.before(:suite) do
|
5
|
-
Mailstro::
|
6
|
-
end
|
7
|
-
|
8
|
-
config.after(:suite) do
|
9
|
-
Mailstro::Test.disable
|
5
|
+
Mailstro::TestStrategy.enable
|
10
6
|
end
|
11
7
|
|
12
8
|
config.before(:each) do
|
13
|
-
Mailstro::
|
9
|
+
Mailstro::TestStrategy.clear
|
14
10
|
end
|
15
11
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Mailstro
|
2
|
+
module TestStrategy
|
3
|
+
def self.enable
|
4
|
+
Mailstro.strategy = Mailstro::TestStrategy
|
5
|
+
end
|
6
|
+
|
7
|
+
@@deliveries = []
|
8
|
+
@@subscribes = []
|
9
|
+
@@unsubscribes = []
|
10
|
+
|
11
|
+
def self.deliveries
|
12
|
+
@@deliveries
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.clear
|
16
|
+
@@deliveries = []
|
17
|
+
@@subscribes = []
|
18
|
+
@@unsubscribes = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.deliver(options)
|
22
|
+
@@deliveries << Delivery.new(options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.list_deliver(options)
|
26
|
+
@@deliveries << ListDelivery.new(options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.subscribe(contact_email, list_type, list_name)
|
30
|
+
@@subscribes << ListSubscribe.new(contact_email, list_type, list_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.unsubscribe(contact_email, list_type, list_name)
|
34
|
+
@@unsubscribes << ListUnsubscribe.new(contact_email, list_type, list_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.has_delivered?(template_name)
|
38
|
+
@@deliveries.map(&:template_name).include?(template_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.has_subscribed?(contact_email, list_type, list_name)
|
42
|
+
@@subscribes.any? do |subscribe|
|
43
|
+
subscribe.contact_email == contact_email &&
|
44
|
+
subscribe.list_type == list_type &&
|
45
|
+
subscribe.list_name == list_name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.has_unsubscribed?(contact_email, list_type, list_name)
|
50
|
+
@@unsubscribes.any? do |unsubscribe|
|
51
|
+
unsubscribe.contact_email == contact_email &&
|
52
|
+
unsubscribe.list_type == list_type &&
|
53
|
+
unsubscribe.list_name == list_name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/mailstro/version.rb
CHANGED
data/mailstro-ruby.gemspec
CHANGED
@@ -6,11 +6,11 @@ require 'mailstro/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "mailstro"
|
8
8
|
spec.version = Mailstro::VERSION
|
9
|
-
spec.authors = ["Keith Pitt"]
|
10
|
-
spec.email = ["
|
11
|
-
spec.description = %q{Ruby
|
12
|
-
spec.summary = %q{Ruby
|
13
|
-
spec.homepage = "
|
9
|
+
spec.authors = ["Keith Pitt", "Shanon McQuay"]
|
10
|
+
spec.email = ["keith@mailstroapp.com", "shanon@mailstroapp.com"]
|
11
|
+
spec.description = %q{Ruby wrapper for mailstroapp.com}
|
12
|
+
spec.summary = %q{Ruby wrapper for mailstroapp.com}
|
13
|
+
spec.homepage = "https://www.mailstroapp.com"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'posting a delivery', :integration do
|
4
|
-
let(:template_name) { :test }
|
5
4
|
let(:contact_email) { "test@example.com" }
|
6
|
-
let(:
|
5
|
+
let(:template_name) { :test }
|
6
|
+
let(:template_data) { { :greeting => "Gday!" } }
|
7
7
|
|
8
8
|
before do
|
9
9
|
Mailstro.configure do |config|
|
@@ -13,16 +13,20 @@ describe 'posting a delivery', :integration do
|
|
13
13
|
|
14
14
|
let(:expected_body) {{
|
15
15
|
"api_key" => "lolapi",
|
16
|
-
"template_name" => "test",
|
17
16
|
"contact_email" => "test@example.com",
|
18
|
-
"
|
17
|
+
"template_name" => "test",
|
18
|
+
"template_data" => { "greeting" => "Gday!" }
|
19
19
|
}}
|
20
20
|
|
21
21
|
it "succesfully submits a delivery to mailstro" do
|
22
22
|
stub_request(:post, "https://api.mailstroapp.com/v1/deliveries").
|
23
23
|
with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
|
24
24
|
|
25
|
-
response = Mailstro.deliver(
|
25
|
+
response = Mailstro.deliver(
|
26
|
+
:to => contact_email,
|
27
|
+
:template_name => template_name,
|
28
|
+
:template_data => template_data
|
29
|
+
)
|
26
30
|
response['success'].should == true
|
27
31
|
end
|
28
32
|
|
@@ -31,7 +35,11 @@ describe 'posting a delivery', :integration do
|
|
31
35
|
to_return(:status => 401)
|
32
36
|
|
33
37
|
expect do
|
34
|
-
Mailstro.deliver(
|
38
|
+
Mailstro.deliver(
|
39
|
+
:to => contact_email,
|
40
|
+
:template_name => template_name,
|
41
|
+
:template_data => template_data
|
42
|
+
)
|
35
43
|
end.to raise_error(Mailstro::Error::AuthorisationError, "api_key not authorised")
|
36
44
|
end
|
37
45
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'posting a list delivery', :integration do
|
4
|
-
let(:template_name) { :
|
5
|
-
let(:
|
6
|
-
let(:
|
4
|
+
let(:template_name) { :build_failure }
|
5
|
+
let(:list_type) { :build_watchers }
|
6
|
+
let(:list_name) { 12 }
|
7
|
+
let(:template_data) { { :commit => "Ooops" } }
|
7
8
|
|
8
9
|
before do
|
9
10
|
Mailstro.configure do |config|
|
@@ -13,16 +14,21 @@ describe 'posting a list delivery', :integration do
|
|
13
14
|
|
14
15
|
let(:expected_body) {{
|
15
16
|
"api_key" => "lolapi",
|
16
|
-
"template_name" => "
|
17
|
-
"
|
18
|
-
"
|
17
|
+
"template_name" => "build_failure",
|
18
|
+
"list_type" => "build_watchers",
|
19
|
+
"list_name" => 12,
|
20
|
+
"template_data" => { "commit" => "Ooops" }
|
19
21
|
}}
|
20
22
|
|
21
23
|
it "succesfully submits a list delivery to mailstro" do
|
22
24
|
stub_request(:post, "https://api.mailstroapp.com/v1/lists/deliveries").
|
23
25
|
with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
|
24
26
|
|
25
|
-
response = Mailstro.
|
27
|
+
response = Mailstro.deliver(
|
28
|
+
:to => [list_type, list_name],
|
29
|
+
:template_name => template_name,
|
30
|
+
:template_data => template_data
|
31
|
+
)
|
26
32
|
|
27
33
|
response[:success].should == true
|
28
34
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'posting a subscription to a list', :integration do
|
4
|
-
let(:
|
4
|
+
let(:list_type) { :build_watchers }
|
5
|
+
let(:list_name) { 12 }
|
5
6
|
let(:contact_email) { "test@example.com" }
|
6
7
|
|
7
8
|
before do
|
@@ -12,7 +13,8 @@ describe 'posting a subscription to a list', :integration do
|
|
12
13
|
|
13
14
|
let(:expected_body) {{
|
14
15
|
"api_key" => "lolapi",
|
15
|
-
"
|
16
|
+
"list_type" => "build_watchers",
|
17
|
+
"list_name" => 12,
|
16
18
|
"contact_email" => "test@example.com",
|
17
19
|
}}
|
18
20
|
|
@@ -20,7 +22,7 @@ describe 'posting a subscription to a list', :integration do
|
|
20
22
|
stub_request(:post, "https://api.mailstroapp.com/v1/lists/subscribers").
|
21
23
|
with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
|
22
24
|
|
23
|
-
response = Mailstro.
|
25
|
+
response = Mailstro.subscribe(contact_email, list_type, list_name)
|
24
26
|
response['success'].should == true
|
25
27
|
end
|
26
28
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'deleting a subscription from a list', :integration do
|
4
|
-
let(:list_name) { :test }
|
5
4
|
let(:contact_email) { "test@example.com" }
|
5
|
+
let(:list_type) { :build_watchers }
|
6
|
+
let(:list_name) { 12 }
|
6
7
|
|
7
8
|
before do
|
8
9
|
Mailstro.configure do |config|
|
@@ -12,7 +13,8 @@ describe 'deleting a subscription from a list', :integration do
|
|
12
13
|
|
13
14
|
let(:expected_body) {{
|
14
15
|
"api_key" => "lolapi",
|
15
|
-
"
|
16
|
+
"list_type" => "build_watchers",
|
17
|
+
"list_name" => 12,
|
16
18
|
"contact_email" => "test@example.com",
|
17
19
|
}}
|
18
20
|
|
@@ -20,7 +22,7 @@ describe 'deleting a subscription from a list', :integration do
|
|
20
22
|
stub_request(:delete, "https://api.mailstroapp.com/v1/lists/subscribers").
|
21
23
|
with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
|
22
24
|
|
23
|
-
response = Mailstro.
|
25
|
+
response = Mailstro.unsubscribe(contact_email, list_type, list_name)
|
24
26
|
response['success'].should == true
|
25
27
|
end
|
26
28
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailstro/test_strategy'
|
3
|
+
|
4
|
+
describe Mailstro::TestStrategy do
|
5
|
+
before do
|
6
|
+
Mailstro::TestStrategy.enable
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '.enable' do
|
10
|
+
it "doesn't send anything when enabled" do
|
11
|
+
Mailstro::Delivery.should_not_receive(:deliver)
|
12
|
+
Mailstro::ListDelivery.should_not_receive(:deliver)
|
13
|
+
Mailstro::ListSubscribe.should_not_receive(:deliver)
|
14
|
+
Mailstro::ListUnsubscribe.should_not_receive(:deliver)
|
15
|
+
|
16
|
+
Mailstro.deliver(
|
17
|
+
:to => 'a@a.com',
|
18
|
+
:template_name => :welcome
|
19
|
+
)
|
20
|
+
|
21
|
+
Mailstro.subscribe('a@a.com', :watchers, 12)
|
22
|
+
|
23
|
+
Mailstro.deliver(
|
24
|
+
:to => [:watchers, 12],
|
25
|
+
:template_name => :welcome
|
26
|
+
)
|
27
|
+
|
28
|
+
Mailstro.unsubscribe('a@a.com', :watchers, 12)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.clear' do
|
33
|
+
before do
|
34
|
+
Mailstro.deliver(
|
35
|
+
:to => 'a@a.com',
|
36
|
+
:template_name => :welcome
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'empties out the .deliveries array' do
|
41
|
+
Mailstro::TestStrategy.deliveries.should_not be_empty
|
42
|
+
Mailstro::TestStrategy.clear
|
43
|
+
|
44
|
+
Mailstro::TestStrategy.deliveries.should be_empty
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '.has_delivered?' do
|
49
|
+
it 'keeps a record of deliveries' do
|
50
|
+
Mailstro.deliver(
|
51
|
+
:to => 'a@a.com',
|
52
|
+
:template_name => :welcome
|
53
|
+
)
|
54
|
+
|
55
|
+
Mailstro.should have_delivered(:welcome)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'keeps a record of list deliveries' do
|
59
|
+
Mailstro.deliver(
|
60
|
+
:to => [:list_type, 10],
|
61
|
+
:template_name => :welcome
|
62
|
+
)
|
63
|
+
|
64
|
+
Mailstro.should have_delivered(:welcome)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '.has_subsribed?' do
|
69
|
+
it 'keeps a record of subscribes' do
|
70
|
+
Mailstro.subscribe('a@a.com', :watchers, 2)
|
71
|
+
|
72
|
+
Mailstro.should have_subscribed('a@a.com', :watchers, 2)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.has_unsubsribed?' do
|
77
|
+
it 'keeps a record of unsubscribes' do
|
78
|
+
Mailstro.unsubscribe('a@a.com', :watchers, 2)
|
79
|
+
|
80
|
+
Mailstro.should have_unsubscribed('a@a.com', :watchers, 2)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/spec/mailstro_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mailstro do
|
4
4
|
|
5
|
-
|
6
|
-
Mailstro.configuration =
|
5
|
+
after do
|
6
|
+
Mailstro.configuration = Mailstro::Configuration.new
|
7
7
|
end
|
8
8
|
|
9
9
|
describe ".configure" do
|
@@ -16,16 +16,4 @@ describe Mailstro do
|
|
16
16
|
Mailstro.configuration.api_endpoint.should == 'mailstro.dev'
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
20
|
-
describe ".delivery" do
|
21
|
-
let(:template) { "name" }
|
22
|
-
let(:contact) { { :email => "foo@bar.com" } }
|
23
|
-
let(:data) { { :data => "here" } }
|
24
|
-
|
25
|
-
it "creates a delivery object and delivers it" do
|
26
|
-
Mailstro::Delivery.should_receive(:deliver).with(template, contact, data)
|
27
|
-
|
28
|
-
Mailstro.deliver(template, contact, data)
|
29
|
-
end
|
30
|
-
end
|
31
19
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,11 +6,10 @@ FIXTURES_PATH = SPEC_PATH.join('fixtures')
|
|
6
6
|
Dir[SPEC_PATH.join("support/**/*.rb")].each { |f| require f }
|
7
7
|
|
8
8
|
RSpec.configure do |config|
|
9
|
-
config.
|
9
|
+
config.after(:each) do
|
10
|
+
Mailstro.strategy = Mailstro::RealStrategy
|
11
|
+
end
|
10
12
|
|
11
|
-
# Run specs in random order to surface order dependencies. If you find an
|
12
|
-
# order dependency and want to debug it, you can fix the order by providing
|
13
|
-
# the seed, which is printed after each run.
|
14
|
-
# --seed 1234
|
15
13
|
config.order = "random"
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
16
15
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailstro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Keith Pitt
|
9
|
+
- Shanon McQuay
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
13
|
+
date: 2013-09-21 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: faraday
|
@@ -123,9 +124,10 @@ dependencies:
|
|
123
124
|
- - ! '>='
|
124
125
|
- !ruby/object:Gem::Version
|
125
126
|
version: '0'
|
126
|
-
description: Ruby
|
127
|
+
description: Ruby wrapper for mailstroapp.com
|
127
128
|
email:
|
128
|
-
-
|
129
|
+
- keith@mailstroapp.com
|
130
|
+
- shanon@mailstroapp.com
|
129
131
|
executables: []
|
130
132
|
extensions: []
|
131
133
|
extra_rdoc_files: []
|
@@ -144,9 +146,10 @@ files:
|
|
144
146
|
- lib/mailstro/list_subscribe.rb
|
145
147
|
- lib/mailstro/list_unsubscribe.rb
|
146
148
|
- lib/mailstro/middleware/response/raise_error.rb
|
149
|
+
- lib/mailstro/real_strategy.rb
|
147
150
|
- lib/mailstro/resource.rb
|
148
151
|
- lib/mailstro/rspec.rb
|
149
|
-
- lib/mailstro/
|
152
|
+
- lib/mailstro/test_strategy.rb
|
150
153
|
- lib/mailstro/version.rb
|
151
154
|
- mailstro-ruby.gemspec
|
152
155
|
- spec/fixtures/response.json
|
@@ -155,13 +158,13 @@ files:
|
|
155
158
|
- spec/integration/list_subscribe_spec.rb
|
156
159
|
- spec/integration/list_unsubscribe_spec.rb
|
157
160
|
- spec/mailstro/configuration_spec.rb
|
158
|
-
- spec/mailstro/
|
161
|
+
- spec/mailstro/test_strategy_spec.rb
|
159
162
|
- spec/mailstro/version_spec.rb
|
160
163
|
- spec/mailstro_spec.rb
|
161
164
|
- spec/spec_helper.rb
|
162
165
|
- spec/support/fixtures.rb
|
163
166
|
- spec/support/webmock.rb
|
164
|
-
homepage:
|
167
|
+
homepage: https://www.mailstroapp.com
|
165
168
|
licenses:
|
166
169
|
- MIT
|
167
170
|
post_install_message:
|
@@ -185,7 +188,7 @@ rubyforge_project:
|
|
185
188
|
rubygems_version: 1.8.23
|
186
189
|
signing_key:
|
187
190
|
specification_version: 3
|
188
|
-
summary: Ruby
|
191
|
+
summary: Ruby wrapper for mailstroapp.com
|
189
192
|
test_files:
|
190
193
|
- spec/fixtures/response.json
|
191
194
|
- spec/integration/delivery_spec.rb
|
@@ -193,7 +196,7 @@ test_files:
|
|
193
196
|
- spec/integration/list_subscribe_spec.rb
|
194
197
|
- spec/integration/list_unsubscribe_spec.rb
|
195
198
|
- spec/mailstro/configuration_spec.rb
|
196
|
-
- spec/mailstro/
|
199
|
+
- spec/mailstro/test_strategy_spec.rb
|
197
200
|
- spec/mailstro/version_spec.rb
|
198
201
|
- spec/mailstro_spec.rb
|
199
202
|
- spec/spec_helper.rb
|
data/lib/mailstro/test.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Mailstro
|
2
|
-
module Test
|
3
|
-
@@enabled = false
|
4
|
-
@@deliveries = []
|
5
|
-
|
6
|
-
def self.deliveries
|
7
|
-
@@deliveries
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.clear_deliveries
|
11
|
-
@@deliveries = []
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.enable
|
15
|
-
def Mailstro.deliver(template_name, contact_email, data = {})
|
16
|
-
Mailstro::Test.deliveries << Mailstro::Delivery.new(template_name, contact_email, data)
|
17
|
-
true # insert response here
|
18
|
-
end
|
19
|
-
|
20
|
-
def Mailstro.has_delivered?(template_name)
|
21
|
-
Mailstro::Test.has_delivered?(template_name)
|
22
|
-
end
|
23
|
-
|
24
|
-
@@enabled = true
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.disable
|
28
|
-
def Mailstro.deliver(template_name, contact_email, data = {})
|
29
|
-
Mailstro::Delivery.deliver(template_name, contact_email, data)
|
30
|
-
end
|
31
|
-
|
32
|
-
@@enabled = false
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.has_delivered?(template_name)
|
36
|
-
templates = @@deliveries.map(&:template_name)
|
37
|
-
|
38
|
-
templates.include?(template_name)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/spec/mailstro/test_spec.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'mailstro/test'
|
3
|
-
|
4
|
-
describe Mailstro::Test do
|
5
|
-
describe '.enable' do
|
6
|
-
before do
|
7
|
-
Mailstro::Test.enable
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
Mailstro::Test.disable
|
12
|
-
end
|
13
|
-
|
14
|
-
it "doesn't send deliveries when enabled" do
|
15
|
-
Mailstro::Delivery.should_not_receive(:deliver).with(:template_name, 'a@a.com', {})
|
16
|
-
|
17
|
-
Mailstro.deliver(:template_name, 'a@a.com')
|
18
|
-
end
|
19
|
-
|
20
|
-
it "adds the delivery to the deliveries array" do
|
21
|
-
Mailstro.deliver(:template_name, 'a@a.com')
|
22
|
-
|
23
|
-
Mailstro::Test.deliveries.should_not be_empty
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '.disable' do
|
28
|
-
it 'restores the previous behaviour of .deliver' do
|
29
|
-
Mailstro::Test.enable
|
30
|
-
Mailstro::Test.disable
|
31
|
-
Mailstro::Delivery.should_receive(:deliver).with(:template_name, 'a@a.com', {})
|
32
|
-
|
33
|
-
Mailstro.deliver(:template_name, 'a@a.com')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '.clear_deliveries' do
|
38
|
-
before do
|
39
|
-
Mailstro::Test.enable
|
40
|
-
|
41
|
-
Mailstro.deliver(:template_name, 'a@a.com')
|
42
|
-
end
|
43
|
-
|
44
|
-
after do
|
45
|
-
Mailstro::Test.disable
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'empties out the .deliveries array' do
|
49
|
-
Mailstro::Test.deliveries.should_not be_empty
|
50
|
-
Mailstro::Test.clear_deliveries
|
51
|
-
|
52
|
-
Mailstro::Test.deliveries.should be_empty
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '.has_delivered?' do
|
57
|
-
before do
|
58
|
-
Mailstro::Test.enable
|
59
|
-
end
|
60
|
-
|
61
|
-
after do
|
62
|
-
Mailstro::Test.disable
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'returns true if there was a delivery matching the template name give' do
|
66
|
-
Mailstro.deliver(:template_name, 'a@a.com')
|
67
|
-
|
68
|
-
Mailstro.has_delivered?(:template => :template_name)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|