mailstro 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Readme.md +0 -25
- data/lib/mailstro/test_strategy.rb +2 -40
- data/lib/mailstro/version.rb +1 -1
- data/lib/mailstro.rb +1 -33
- data/spec/mailstro/test_strategy_spec.rb +0 -69
- metadata +2 -12
- data/lib/mailstro/list_delivery.rb +0 -32
- data/lib/mailstro/list_subscribe.rb +0 -19
- data/lib/mailstro/list_unsubscribe.rb +0 -19
- data/lib/mailstro/real_strategy.rb +0 -2
- data/spec/integration/list_delivery_spec.rb +0 -35
- data/spec/integration/list_subscribe_spec.rb +0 -28
- data/spec/integration/list_unsubscribe_spec.rb +0 -28
data/Readme.md
CHANGED
@@ -42,22 +42,6 @@ Mailstro.deliver(
|
|
42
42
|
)
|
43
43
|
```
|
44
44
|
|
45
|
-
Sending an email to a list of users, with subscription management.
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
Mailstro.subscribe('shanon@mailstroapp.com', :build_watchers, project_id)
|
49
|
-
|
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('shanon@mailstroapp.com', :build_watchers, project_id)
|
59
|
-
```
|
60
|
-
|
61
45
|
## RSpec
|
62
46
|
|
63
47
|
Require the mailstro spec helper to automatically enable test mode.
|
@@ -74,19 +58,10 @@ Mailstro.deliver(
|
|
74
58
|
:template_name => :welcome,
|
75
59
|
)
|
76
60
|
|
77
|
-
Mailstro.should have_delivered(:welcome)
|
78
61
|
Mailstro.should have_delivered(
|
79
62
|
:to => 'shanon@mailstroapp.com',
|
80
63
|
:template_name => :welcome
|
81
64
|
)
|
82
|
-
|
83
|
-
Mailstro.should have_subscribed('a@a.com', :watchers, 2)
|
84
|
-
Mailstro.should have_unsubscribed('a@a.com', :watchers, 2)
|
85
|
-
|
86
|
-
Mailstro.should have_delivered(
|
87
|
-
:to => [:build_watchers, project_name],
|
88
|
-
:template_name => :build_failed
|
89
|
-
)
|
90
65
|
```
|
91
66
|
|
92
67
|
## Contributing
|
@@ -4,32 +4,16 @@ module Mailstro
|
|
4
4
|
Mailstro.strategy = Mailstro::TestStrategy
|
5
5
|
end
|
6
6
|
|
7
|
-
@@deliveries
|
8
|
-
@@subscribes = []
|
9
|
-
@@unsubscribes = []
|
7
|
+
@@deliveries = []
|
10
8
|
|
11
9
|
def self.clear
|
12
|
-
@@deliveries
|
13
|
-
@@subscribes = []
|
14
|
-
@@unsubscribes = []
|
10
|
+
@@deliveries = []
|
15
11
|
end
|
16
12
|
|
17
13
|
def self.deliver(options)
|
18
14
|
@@deliveries << Delivery.new(options)
|
19
15
|
end
|
20
16
|
|
21
|
-
def self.list_deliver(options)
|
22
|
-
@@deliveries << ListDelivery.new(options)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.subscribe(contact_email, list_type, list_name)
|
26
|
-
@@subscribes << ListSubscribe.new(contact_email, list_type, list_name)
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.unsubscribe(contact_email, list_type, list_name)
|
30
|
-
@@unsubscribes << ListUnsubscribe.new(contact_email, list_type, list_name)
|
31
|
-
end
|
32
|
-
|
33
17
|
def self.has_delivered?(conditions)
|
34
18
|
@@deliveries.any? do |delivery|
|
35
19
|
result = true
|
@@ -40,33 +24,11 @@ module Mailstro
|
|
40
24
|
if conditions[:to]
|
41
25
|
result = result && delivery.contact_email == conditions[:to]
|
42
26
|
end
|
43
|
-
if conditions[:to_list_type]
|
44
|
-
result = result && delivery.list_type == conditions[:to_list_type]
|
45
|
-
end
|
46
|
-
if conditions[:to_list_name]
|
47
|
-
result = result && delivery.list_name == conditions[:to_list_name]
|
48
|
-
end
|
49
27
|
else
|
50
28
|
result = delivery.template_name == conditions
|
51
29
|
end
|
52
30
|
result
|
53
31
|
end
|
54
32
|
end
|
55
|
-
|
56
|
-
def self.has_subscribed?(contact_email, list_type, list_name)
|
57
|
-
@@subscribes.any? do |subscribe|
|
58
|
-
subscribe.contact_email == contact_email &&
|
59
|
-
subscribe.list_type == list_type &&
|
60
|
-
subscribe.list_name == list_name
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.has_unsubscribed?(contact_email, list_type, list_name)
|
65
|
-
@@unsubscribes.any? do |unsubscribe|
|
66
|
-
unsubscribe.contact_email == contact_email &&
|
67
|
-
unsubscribe.list_type == list_type &&
|
68
|
-
unsubscribe.list_name == list_name
|
69
|
-
end
|
70
|
-
end
|
71
33
|
end
|
72
34
|
end
|
data/lib/mailstro/version.rb
CHANGED
data/lib/mailstro.rb
CHANGED
@@ -5,9 +5,6 @@ require_relative "mailstro/configuration"
|
|
5
5
|
require_relative "mailstro/error"
|
6
6
|
require_relative "mailstro/resource"
|
7
7
|
require_relative "mailstro/delivery"
|
8
|
-
require_relative "mailstro/list_delivery"
|
9
|
-
require_relative "mailstro/list_subscribe"
|
10
|
-
require_relative "mailstro/list_unsubscribe"
|
11
8
|
|
12
9
|
module Mailstro
|
13
10
|
|
@@ -17,15 +14,6 @@ module Mailstro
|
|
17
14
|
def deliver(options)
|
18
15
|
Delivery.new(options).deliver
|
19
16
|
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
17
|
end
|
30
18
|
end
|
31
19
|
|
@@ -41,30 +29,10 @@ module Mailstro
|
|
41
29
|
end
|
42
30
|
|
43
31
|
def self.deliver(options)
|
44
|
-
|
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)
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.unsubscribe(contact_email, list_type, list_name)
|
56
|
-
@strategy.unsubscribe(contact_email, list_type, list_name)
|
32
|
+
@strategy.deliver(options)
|
57
33
|
end
|
58
34
|
|
59
35
|
def self.has_delivered?(template_name)
|
60
36
|
TestStrategy.has_delivered?(template_name)
|
61
37
|
end
|
62
|
-
|
63
|
-
def self.has_subscribed?(contact_email, list_type, list_name)
|
64
|
-
TestStrategy.has_subscribed?(contact_email, list_type, list_name)
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.has_unsubscribed?(contact_email, list_type, list_name)
|
68
|
-
TestStrategy.has_unsubscribed?(contact_email, list_type, list_name)
|
69
|
-
end
|
70
38
|
end
|
@@ -9,23 +9,11 @@ describe Mailstro::TestStrategy do
|
|
9
9
|
describe '.enable' do
|
10
10
|
it "doesn't send anything when enabled" do
|
11
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
12
|
|
16
13
|
Mailstro.deliver(
|
17
14
|
:to => 'a@a.com',
|
18
15
|
:template_name => :welcome
|
19
16
|
)
|
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
17
|
end
|
30
18
|
end
|
31
19
|
|
@@ -60,62 +48,5 @@ describe Mailstro::TestStrategy do
|
|
60
48
|
)
|
61
49
|
end
|
62
50
|
end
|
63
|
-
|
64
|
-
context "with a list delivery" do
|
65
|
-
before do
|
66
|
-
Mailstro.deliver(
|
67
|
-
:to => [:build_watchers, 'mailstro/mailstro-ruby'],
|
68
|
-
:template_name => :build_failed
|
69
|
-
)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "matches against list type, name and template name" do
|
73
|
-
Mailstro.should have_delivered(
|
74
|
-
:to_list_type => :build_watchers,
|
75
|
-
:to_list_name => 'mailstro/mailstro-ruby',
|
76
|
-
:template_name => :build_failed,
|
77
|
-
)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "does not match an invalid list type" do
|
81
|
-
Mailstro.should_not have_delivered(
|
82
|
-
:to_list_type => :customers,
|
83
|
-
:to_list_name => 'mailstro/mailstro-ruby',
|
84
|
-
:template_name => :build_failed,
|
85
|
-
)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "does not match an invalid list name" do
|
89
|
-
Mailstro.should_not have_delivered(
|
90
|
-
:to_list_type => :build_watchers,
|
91
|
-
:to_list_name => 'mailstro/mailstro',
|
92
|
-
:template_name => :build_failed,
|
93
|
-
)
|
94
|
-
end
|
95
|
-
|
96
|
-
it "does not match an invalid template name" do
|
97
|
-
Mailstro.should_not have_delivered(
|
98
|
-
:to_list_type => :build_watchers,
|
99
|
-
:to_list_name => 'mailstro/mailstro-ruby',
|
100
|
-
:template_name => :welcome,
|
101
|
-
)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '.has_subsribed?' do
|
107
|
-
it 'keeps a record of subscribes' do
|
108
|
-
Mailstro.subscribe('a@a.com', :watchers, 2)
|
109
|
-
|
110
|
-
Mailstro.should have_subscribed('a@a.com', :watchers, 2)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe '.has_unsubsribed?' do
|
115
|
-
it 'keeps a record of unsubscribes' do
|
116
|
-
Mailstro.unsubscribe('a@a.com', :watchers, 2)
|
117
|
-
|
118
|
-
Mailstro.should have_unsubscribed('a@a.com', :watchers, 2)
|
119
|
-
end
|
120
51
|
end
|
121
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-10-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -142,11 +142,7 @@ files:
|
|
142
142
|
- lib/mailstro/configuration.rb
|
143
143
|
- lib/mailstro/delivery.rb
|
144
144
|
- lib/mailstro/error.rb
|
145
|
-
- lib/mailstro/list_delivery.rb
|
146
|
-
- lib/mailstro/list_subscribe.rb
|
147
|
-
- lib/mailstro/list_unsubscribe.rb
|
148
145
|
- lib/mailstro/middleware/response/raise_error.rb
|
149
|
-
- lib/mailstro/real_strategy.rb
|
150
146
|
- lib/mailstro/resource.rb
|
151
147
|
- lib/mailstro/rspec.rb
|
152
148
|
- lib/mailstro/test_strategy.rb
|
@@ -154,9 +150,6 @@ files:
|
|
154
150
|
- mailstro-ruby.gemspec
|
155
151
|
- spec/fixtures/response.json
|
156
152
|
- spec/integration/delivery_spec.rb
|
157
|
-
- spec/integration/list_delivery_spec.rb
|
158
|
-
- spec/integration/list_subscribe_spec.rb
|
159
|
-
- spec/integration/list_unsubscribe_spec.rb
|
160
153
|
- spec/mailstro/configuration_spec.rb
|
161
154
|
- spec/mailstro/test_strategy_spec.rb
|
162
155
|
- spec/mailstro/version_spec.rb
|
@@ -191,9 +184,6 @@ summary: Ruby wrapper for mailstroapp.com
|
|
191
184
|
test_files:
|
192
185
|
- spec/fixtures/response.json
|
193
186
|
- spec/integration/delivery_spec.rb
|
194
|
-
- spec/integration/list_delivery_spec.rb
|
195
|
-
- spec/integration/list_subscribe_spec.rb
|
196
|
-
- spec/integration/list_unsubscribe_spec.rb
|
197
187
|
- spec/mailstro/configuration_spec.rb
|
198
188
|
- spec/mailstro/test_strategy_spec.rb
|
199
189
|
- spec/mailstro/version_spec.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Mailstro
|
2
|
-
class ListDelivery < Resource
|
3
|
-
def initialize(options)
|
4
|
-
@options = options
|
5
|
-
end
|
6
|
-
|
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
|
18
|
-
|
19
|
-
def template_data
|
20
|
-
@options.fetch(:template_data, nil)
|
21
|
-
end
|
22
|
-
|
23
|
-
def deliver
|
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
|
-
)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Mailstro
|
2
|
-
class ListSubscribe < Resource
|
3
|
-
attr_reader :contact_email, :list_type, :list_name
|
4
|
-
|
5
|
-
def initialize(contact_email, list_type, list_name)
|
6
|
-
@contact_email = contact_email
|
7
|
-
@list_type = list_type
|
8
|
-
@list_name = list_name
|
9
|
-
end
|
10
|
-
|
11
|
-
def deliver
|
12
|
-
post("lists/subscribers",
|
13
|
-
:contact_email => @contact_email,
|
14
|
-
:list_type => @list_type,
|
15
|
-
:list_name => @list_name
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Mailstro
|
2
|
-
class ListUnsubscribe < Resource
|
3
|
-
attr_reader :contact_email, :list_type, :list_name
|
4
|
-
|
5
|
-
def initialize(contact_email, list_type, list_name)
|
6
|
-
@contact_email = contact_email
|
7
|
-
@list_type = list_type
|
8
|
-
@list_name = list_name
|
9
|
-
end
|
10
|
-
|
11
|
-
def deliver
|
12
|
-
delete("lists/subscribers",
|
13
|
-
:contact_email => @contact_email,
|
14
|
-
:list_type => @list_type,
|
15
|
-
:list_name => @list_name
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'posting a list delivery', :integration do
|
4
|
-
let(:template_name) { :build_failure }
|
5
|
-
let(:list_type) { :build_watchers }
|
6
|
-
let(:list_name) { 12 }
|
7
|
-
let(:template_data) { { :commit => "Ooops" } }
|
8
|
-
|
9
|
-
before do
|
10
|
-
Mailstro.configure do |config|
|
11
|
-
config.api_key = 'lolapi'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
let(:expected_body) {{
|
16
|
-
"api_key" => "lolapi",
|
17
|
-
"template_name" => "build_failure",
|
18
|
-
"list_type" => "build_watchers",
|
19
|
-
"list_name" => 12,
|
20
|
-
"template_data" => { "commit" => "Ooops" }
|
21
|
-
}}
|
22
|
-
|
23
|
-
it "succesfully submits a list delivery to mailstro" do
|
24
|
-
stub_request(:post, "https://api.mailstroapp.com/v1/lists/deliveries").
|
25
|
-
with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
|
26
|
-
|
27
|
-
response = Mailstro.deliver(
|
28
|
-
:to => [list_type, list_name],
|
29
|
-
:template_name => template_name,
|
30
|
-
:template_data => template_data
|
31
|
-
)
|
32
|
-
|
33
|
-
response[:success].should == true
|
34
|
-
end
|
35
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'posting a subscription to a list', :integration do
|
4
|
-
let(:list_type) { :build_watchers }
|
5
|
-
let(:list_name) { 12 }
|
6
|
-
let(:contact_email) { "test@example.com" }
|
7
|
-
|
8
|
-
before do
|
9
|
-
Mailstro.configure do |config|
|
10
|
-
config.api_key = 'lolapi'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:expected_body) {{
|
15
|
-
"api_key" => "lolapi",
|
16
|
-
"list_type" => "build_watchers",
|
17
|
-
"list_name" => 12,
|
18
|
-
"contact_email" => "test@example.com",
|
19
|
-
}}
|
20
|
-
|
21
|
-
it "succesfully submits a subscription to mailstro" do
|
22
|
-
stub_request(:post, "https://api.mailstroapp.com/v1/lists/subscribers").
|
23
|
-
with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
|
24
|
-
|
25
|
-
response = Mailstro.subscribe(contact_email, list_type, list_name)
|
26
|
-
response['success'].should == true
|
27
|
-
end
|
28
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'deleting a subscription from a list', :integration do
|
4
|
-
let(:contact_email) { "test@example.com" }
|
5
|
-
let(:list_type) { :build_watchers }
|
6
|
-
let(:list_name) { 12 }
|
7
|
-
|
8
|
-
before do
|
9
|
-
Mailstro.configure do |config|
|
10
|
-
config.api_key = 'lolapi'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:expected_body) {{
|
15
|
-
"api_key" => "lolapi",
|
16
|
-
"list_type" => "build_watchers",
|
17
|
-
"list_name" => 12,
|
18
|
-
"contact_email" => "test@example.com",
|
19
|
-
}}
|
20
|
-
|
21
|
-
it "succesfully deletes a subscription to mailstro" do
|
22
|
-
stub_request(:delete, "https://api.mailstroapp.com/v1/lists/subscribers").
|
23
|
-
with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
|
24
|
-
|
25
|
-
response = Mailstro.unsubscribe(contact_email, list_type, list_name)
|
26
|
-
response['success'].should == true
|
27
|
-
end
|
28
|
-
end
|