mailstro 0.0.4 → 0.0.5
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 +12 -2
- data/lib/mailstro/list_delivery.rb +21 -0
- data/lib/mailstro/list_subscribe.rb +19 -0
- data/lib/mailstro/list_unsubscribe.rb +19 -0
- data/lib/mailstro/resource.rb +9 -0
- data/lib/mailstro/version.rb +1 -1
- data/lib/mailstro.rb +17 -3
- data/spec/fixtures/response.json +1 -0
- data/spec/integration/{posting_a_delivery_spec.rb → delivery_spec.rb} +2 -2
- data/spec/integration/list_delivery_spec.rb +29 -0
- data/spec/integration/list_subscribe_spec.rb +26 -0
- data/spec/integration/list_unsubscribe_spec.rb +26 -0
- metadata +14 -5
- data/spec/fixtures/deliveries.json +0 -1
data/Readme.md
CHANGED
@@ -30,10 +30,20 @@ TODO: Write a gem description
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
-
To send
|
33
|
+
To send a 'welcome' email use the following:
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
Mailstro.deliver(:welcome, "
|
36
|
+
Mailstro.deliver(:welcome, "shanon@mailstroapp.com", :greeting => "Hi")
|
37
|
+
```
|
38
|
+
|
39
|
+
To send a 'thank_you' email to a list of 'customers' use the following:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Mailstro.list_subscribe(:customers, 'jack@mailstroapp.com')
|
43
|
+
Mailstro.list_subscribe(:customers, 'fred@mailstroapp.com')
|
44
|
+
Mailstro.list_unsubscribe(:customers, 'jack@mailstroapp.com')
|
45
|
+
|
46
|
+
Mailstro.list_deliver(:customers, :welcome, :greeting => "Hi")
|
37
47
|
```
|
38
48
|
|
39
49
|
## Contributing
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Mailstro
|
2
|
+
class ListDelivery < Resource
|
3
|
+
def self.deliver(template_name, list_name, payload)
|
4
|
+
new(template_name, list_name, payload).deliver
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_reader :list_name, :template_name
|
8
|
+
|
9
|
+
def initialize(template_name, list_name, payload)
|
10
|
+
@template_name = template_name
|
11
|
+
@list_name = list_name
|
12
|
+
@payload = payload
|
13
|
+
end
|
14
|
+
|
15
|
+
def deliver
|
16
|
+
post("lists/deliveries", :template_name => @template_name,
|
17
|
+
:list_name => @list_name,
|
18
|
+
:payload => @payload)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mailstro
|
2
|
+
class ListSubscribe < Resource
|
3
|
+
def self.subscribe(list_name, contact_email)
|
4
|
+
new(list_name, contact_email).deliver
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_reader :list_name, :contact_email
|
8
|
+
|
9
|
+
def initialize(list_name, contact_email)
|
10
|
+
@list_name = list_name
|
11
|
+
@contact_email = contact_email
|
12
|
+
end
|
13
|
+
|
14
|
+
def deliver
|
15
|
+
post("lists/subscribers", :list_name => @list_name,
|
16
|
+
:contact_email => @contact_email)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mailstro
|
2
|
+
class ListUnsubscribe < Resource
|
3
|
+
def self.unsubscribe(list_name, contact_email)
|
4
|
+
new(list_name, contact_email).deliver
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_reader :list_name, :contact_email
|
8
|
+
|
9
|
+
def initialize(list_name, contact_email)
|
10
|
+
@list_name = list_name
|
11
|
+
@contact_email = contact_email
|
12
|
+
end
|
13
|
+
|
14
|
+
def deliver
|
15
|
+
delete("lists/subscribers", :list_name => @list_name,
|
16
|
+
:contact_email => @contact_email)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/mailstro/resource.rb
CHANGED
@@ -21,6 +21,15 @@ module Mailstro
|
|
21
21
|
end.body
|
22
22
|
end
|
23
23
|
|
24
|
+
def delete(path, body = {})
|
25
|
+
connection.delete(path) do |request|
|
26
|
+
request.headers = {
|
27
|
+
'Content-Type' => 'application/json'
|
28
|
+
}
|
29
|
+
request.body = params(body)
|
30
|
+
end.body
|
31
|
+
end
|
32
|
+
|
24
33
|
def connection
|
25
34
|
@connection ||= Faraday.new(:url => Mailstro.configuration.api_endpoint) do |faraday|
|
26
35
|
faraday.use Mailstro::Middleware::Response::RaiseError
|
data/lib/mailstro/version.rb
CHANGED
data/lib/mailstro.rb
CHANGED
@@ -3,9 +3,11 @@ require_relative "mailstro/configuration"
|
|
3
3
|
require_relative "mailstro/resource"
|
4
4
|
require_relative "mailstro/error"
|
5
5
|
require_relative "mailstro/delivery"
|
6
|
+
require_relative "mailstro/list_delivery"
|
7
|
+
require_relative "mailstro/list_subscribe"
|
8
|
+
require_relative "mailstro/list_unsubscribe"
|
6
9
|
|
7
10
|
module Mailstro
|
8
|
-
|
9
11
|
class << self
|
10
12
|
attr_accessor :configuration
|
11
13
|
end
|
@@ -16,7 +18,19 @@ module Mailstro
|
|
16
18
|
configuration.validate!
|
17
19
|
end
|
18
20
|
|
19
|
-
def self.deliver(
|
20
|
-
Delivery.deliver(
|
21
|
+
def self.deliver(template_name, contact_email, payload = {})
|
22
|
+
Delivery.deliver(template_name, contact_email, payload)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.list_deliver(template_name, list, payload = {})
|
26
|
+
ListDelivery.deliver(template_name, list, payload)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.list_subscribe(list_name, contact_email)
|
30
|
+
ListSubscribe.subscribe(list_name, contact_email)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.list_unsubscribe(list_name, contact_email)
|
34
|
+
ListUnsubscribe.unsubscribe(list_name, contact_email)
|
21
35
|
end
|
22
36
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "success": true }
|
@@ -20,10 +20,10 @@ describe 'posting a delivery', :integration do
|
|
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
25
|
response = Mailstro.deliver(template_name, contact_email, payload)
|
26
|
-
response['
|
26
|
+
response['success'].should == true
|
27
27
|
end
|
28
28
|
|
29
29
|
it "raises an error if the api key is not authorized" do
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'posting a list delivery', :integration do
|
4
|
+
let(:template_name) { :test }
|
5
|
+
let(:list_name) { :customers }
|
6
|
+
let(:payload) { { :message => "Are you ok?" } }
|
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
|
+
"template_name" => "test",
|
17
|
+
"list_name" => "customers",
|
18
|
+
"payload" => { "message" => "Are you ok?" }
|
19
|
+
}}
|
20
|
+
|
21
|
+
it "succesfully submits a list delivery to mailstro" do
|
22
|
+
stub_request(:post, "https://api.mailstroapp.com/v1/lists/deliveries").
|
23
|
+
with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
|
24
|
+
|
25
|
+
response = Mailstro.list_deliver(template_name, list_name, payload)
|
26
|
+
|
27
|
+
response[:success].should == true
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'posting a subscription to a list', :integration do
|
4
|
+
let(:list_name) { :test }
|
5
|
+
let(:contact_email) { "test@example.com" }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Mailstro.configure do |config|
|
9
|
+
config.api_key = 'lolapi'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:expected_body) {{
|
14
|
+
"api_key" => "lolapi",
|
15
|
+
"list_name" => "test",
|
16
|
+
"contact_email" => "test@example.com",
|
17
|
+
}}
|
18
|
+
|
19
|
+
it "succesfully submits a subscription to mailstro" do
|
20
|
+
stub_request(:post, "https://api.mailstroapp.com/v1/lists/subscribers").
|
21
|
+
with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
|
22
|
+
|
23
|
+
response = Mailstro.list_subscribe(list_name, contact_email)
|
24
|
+
response['success'].should == true
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'deleting a subscription from a list', :integration do
|
4
|
+
let(:list_name) { :test }
|
5
|
+
let(:contact_email) { "test@example.com" }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Mailstro.configure do |config|
|
9
|
+
config.api_key = 'lolapi'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:expected_body) {{
|
14
|
+
"api_key" => "lolapi",
|
15
|
+
"list_name" => "test",
|
16
|
+
"contact_email" => "test@example.com",
|
17
|
+
}}
|
18
|
+
|
19
|
+
it "succesfully deletes a subscription to mailstro" do
|
20
|
+
stub_request(:delete, "https://api.mailstroapp.com/v1/lists/subscribers").
|
21
|
+
with(:body => expected_body).to_return(:status => 200, :body => fixture("response.json"))
|
22
|
+
|
23
|
+
response = Mailstro.list_unsubscribe(list_name, contact_email)
|
24
|
+
response['success'].should == true
|
25
|
+
end
|
26
|
+
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -140,14 +140,20 @@ files:
|
|
140
140
|
- lib/mailstro/configuration.rb
|
141
141
|
- lib/mailstro/delivery.rb
|
142
142
|
- lib/mailstro/error.rb
|
143
|
+
- lib/mailstro/list_delivery.rb
|
144
|
+
- lib/mailstro/list_subscribe.rb
|
145
|
+
- lib/mailstro/list_unsubscribe.rb
|
143
146
|
- lib/mailstro/middleware/response/raise_error.rb
|
144
147
|
- lib/mailstro/resource.rb
|
145
148
|
- lib/mailstro/rspec.rb
|
146
149
|
- lib/mailstro/test.rb
|
147
150
|
- lib/mailstro/version.rb
|
148
151
|
- mailstro-ruby.gemspec
|
149
|
-
- spec/fixtures/
|
150
|
-
- spec/integration/
|
152
|
+
- spec/fixtures/response.json
|
153
|
+
- spec/integration/delivery_spec.rb
|
154
|
+
- spec/integration/list_delivery_spec.rb
|
155
|
+
- spec/integration/list_subscribe_spec.rb
|
156
|
+
- spec/integration/list_unsubscribe_spec.rb
|
151
157
|
- spec/mailstro/configuration_spec.rb
|
152
158
|
- spec/mailstro/test_spec.rb
|
153
159
|
- spec/mailstro/version_spec.rb
|
@@ -181,8 +187,11 @@ signing_key:
|
|
181
187
|
specification_version: 3
|
182
188
|
summary: Ruby notifier for mailstro.co
|
183
189
|
test_files:
|
184
|
-
- spec/fixtures/
|
185
|
-
- spec/integration/
|
190
|
+
- spec/fixtures/response.json
|
191
|
+
- spec/integration/delivery_spec.rb
|
192
|
+
- spec/integration/list_delivery_spec.rb
|
193
|
+
- spec/integration/list_subscribe_spec.rb
|
194
|
+
- spec/integration/list_unsubscribe_spec.rb
|
186
195
|
- spec/mailstro/configuration_spec.rb
|
187
196
|
- spec/mailstro/test_spec.rb
|
188
197
|
- spec/mailstro/version_spec.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
{ "ok": true }
|