mailgun 0.5 → 0.6
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.
- checksums.yaml +7 -0
- data/Gemfile +1 -3
- data/README.md +145 -124
- data/lib/mailgun.rb +1 -0
- data/lib/mailgun/base.rb +18 -13
- data/lib/mailgun/bounce.rb +14 -15
- data/lib/mailgun/complaint.rb +20 -19
- data/lib/mailgun/list.rb +14 -24
- data/lib/mailgun/list/member.rb +25 -29
- data/lib/mailgun/log.rb +6 -9
- data/lib/mailgun/mailbox.rb +20 -20
- data/lib/mailgun/{mail.rb → message.rb} +13 -5
- data/lib/mailgun/route.rb +2 -2
- data/lib/mailgun/unsubscribe.rb +13 -17
- data/mailgun.gemspec +4 -1
- data/spec/bounce_spec.rb +19 -12
- data/spec/complaint_spec.rb +70 -23
- data/spec/list/member_spec.rb +33 -22
- data/spec/list/message_spec.rb +40 -0
- data/spec/list_spec.rb +18 -18
- data/spec/log_spec.rb +6 -3
- data/spec/mailbox_spec.rb +23 -17
- data/spec/route_spec.rb +39 -16
- data/spec/unsubscribe_spec.rb +31 -21
- metadata +42 -19
data/spec/list/member_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mailgun::
|
3
|
+
describe Mailgun::MailingList::Member do
|
4
4
|
|
5
5
|
before :each do
|
6
6
|
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
7
|
|
8
|
-
@
|
8
|
+
@sample = {
|
9
9
|
:email => "test@sample.mailgun.org",
|
10
10
|
:list_email => "test_list@sample.mailgun.org",
|
11
11
|
:name => "test",
|
@@ -16,55 +16,66 @@ describe Mailgun::List::Member do
|
|
16
16
|
describe "list members" do
|
17
17
|
it "should make a GET request with the right params" do
|
18
18
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
19
|
-
|
19
|
+
mailing_list_members_url = @mailgun.list_members(@sample[:list_email]).send(:list_member_url)
|
20
|
+
|
21
|
+
Mailgun.should_receive(:submit).
|
22
|
+
with(:get, mailing_list_members_url, {}).
|
23
|
+
and_return(sample_response)
|
20
24
|
|
21
|
-
@mailgun.list_members
|
25
|
+
@mailgun.list_members(@sample[:list_email]).list
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
29
|
describe "find member in list" do
|
26
30
|
it "should make a GET request with correct params to find given email address" do
|
27
31
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
28
|
-
|
29
|
-
|
30
|
-
.
|
32
|
+
mailing_list_members_url = @mailgun.list_members(@sample[:list_email]).send(:list_member_url, @sample[:email])
|
33
|
+
|
34
|
+
Mailgun.should_receive(:submit).
|
35
|
+
with(:get, mailing_list_members_url).
|
36
|
+
and_return(sample_response)
|
31
37
|
|
32
|
-
@mailgun.list_members
|
38
|
+
@mailgun.list_members(@sample[:list_email]).find(@sample[:email])
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
36
42
|
describe "add member to list" do
|
37
43
|
it "should make a POST request with correct params to add a given email address" do
|
38
44
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
mailing_list_members_url = @mailgun.list_members(@sample[:list_email]).send(:list_member_url)
|
46
|
+
|
47
|
+
Mailgun.should_receive(:submit).
|
48
|
+
with(:post, mailing_list_members_url, {
|
49
|
+
:address => @sample[:email]
|
50
|
+
}).
|
51
|
+
and_return(sample_response)
|
43
52
|
|
44
|
-
@mailgun.list_members
|
53
|
+
@mailgun.list_members(@sample[:list_email]).add(@sample[:email])
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
48
57
|
describe "update member in list" do
|
49
58
|
it "should make a PUT request with correct params" do
|
50
59
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
60
|
+
Mailgun.should_receive(:submit).
|
61
|
+
with(:put, "#{@mailgun.list_members(@sample[:list_email]).send(:list_member_url, @sample[:email])}", {
|
62
|
+
:address => @sample[:email]
|
63
|
+
}).
|
64
|
+
and_return(sample_response)
|
55
65
|
|
56
|
-
@mailgun.list_members
|
66
|
+
@mailgun.list_members(@sample[:list_email]).update(@sample[:email])
|
57
67
|
end
|
58
68
|
end
|
59
69
|
|
60
70
|
describe "delete member from list" do
|
61
71
|
it "should make a DELETE request with correct params" do
|
62
72
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
63
|
-
|
64
|
-
.
|
65
|
-
|
73
|
+
mailing_list_members_url = @mailgun.list_members(@sample[:list_email]).send(:list_member_url, @sample[:email])
|
74
|
+
Mailgun.should_receive(:submit).
|
75
|
+
with(:delete, mailing_list_members_url).
|
76
|
+
and_return(sample_response)
|
66
77
|
|
67
|
-
@mailgun.list_members
|
78
|
+
@mailgun.list_members(@sample[:list_email]).remove(@sample[:email])
|
68
79
|
end
|
69
80
|
end
|
70
81
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mailgun::Log do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
|
+
|
8
|
+
@sample = {
|
9
|
+
:email => "test@sample.mailgun.org",
|
10
|
+
:name => "test",
|
11
|
+
:domain => "sample.mailgun.org"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "send email" do
|
16
|
+
it "should make a POST request to send an email" do
|
17
|
+
|
18
|
+
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
19
|
+
Mailgun.should_receive(:submit)
|
20
|
+
.with(:get, "#{@mailgun.lists.send(:list_url, @sample[:list_email])}")
|
21
|
+
.and_return(sample_response)
|
22
|
+
|
23
|
+
@mailgun.lists.find(@sample[:list_email])
|
24
|
+
|
25
|
+
sample_response = "{\"message\": \"Queued. Thank you.\",\"id\": \"<20111114174239.25659.5817@samples.mailgun.org>\"}"
|
26
|
+
parameters = {
|
27
|
+
:to => "cooldev@your.mailgun.domain",
|
28
|
+
:subject => "missing tps reports",
|
29
|
+
:text => "yeah, we're gonna need you to come in on friday...yeah.",
|
30
|
+
:from => "lumberg.bill@initech.mailgun.domain"
|
31
|
+
}
|
32
|
+
Mailgun.should_receive(:submit) \
|
33
|
+
.with(:post, @mailgun.messages.messages_url, parameters) \
|
34
|
+
.and_return(sample_response)
|
35
|
+
|
36
|
+
@mailgun.messages.send_email(parameters)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/spec/list_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mailgun::
|
3
|
+
describe Mailgun::MailingList do
|
4
4
|
|
5
5
|
before :each do
|
6
6
|
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
7
|
|
8
|
-
@
|
8
|
+
@sample = {
|
9
9
|
:email => "test@sample.mailgun.org",
|
10
10
|
:list_email => "dev@samples.mailgun.org",
|
11
11
|
:name => "test",
|
@@ -13,57 +13,57 @@ describe Mailgun::List do
|
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
16
|
-
describe "
|
16
|
+
describe "list mailing lists" do
|
17
17
|
it "should make a GET request with the right params" do
|
18
18
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
19
|
-
|
20
|
-
.with("#{@mailgun.lists.send(:list_url)}", {}).and_return(sample_response)
|
19
|
+
Mailgun.should_receive(:submit)
|
20
|
+
.with(:get, "#{@mailgun.lists.send(:list_url)}", {}).and_return(sample_response)
|
21
21
|
|
22
|
-
@mailgun.lists.
|
22
|
+
@mailgun.lists.list
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "find list adress" do
|
27
27
|
it "should make a GET request with correct params to find given email address" do
|
28
28
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
29
|
-
|
30
|
-
.with("#{@mailgun.lists.send(:list_url, @
|
29
|
+
Mailgun.should_receive(:submit)
|
30
|
+
.with(:get, "#{@mailgun.lists.send(:list_url, @sample[:list_email])}")
|
31
31
|
.and_return(sample_response)
|
32
32
|
|
33
|
-
@mailgun.lists.find(@
|
33
|
+
@mailgun.lists.find(@sample[:list_email])
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "create list" do
|
38
38
|
it "should make a POST request with correct params to add a given email address" do
|
39
39
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
40
|
-
|
41
|
-
.with("#{@mailgun.lists.send(:list_url)}", {:address => @
|
40
|
+
Mailgun.should_receive(:submit)
|
41
|
+
.with(:post, "#{@mailgun.lists.send(:list_url)}", {:address => @sample[:list_email]})
|
42
42
|
.and_return(sample_response)
|
43
43
|
|
44
|
-
@mailgun.lists.create(@
|
44
|
+
@mailgun.lists.create(@sample[:list_email])
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "update list" do
|
49
49
|
it "should make a PUT request with correct params" do
|
50
50
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
51
|
-
|
52
|
-
.with("#{@mailgun.lists.send(:list_url, @
|
51
|
+
Mailgun.should_receive(:submit)
|
52
|
+
.with(:put, "#{@mailgun.lists.send(:list_url, @sample[:list_email])}", {:address => @sample[:email]})
|
53
53
|
.and_return(sample_response)
|
54
54
|
|
55
|
-
@mailgun.lists.update(@
|
55
|
+
@mailgun.lists.update(@sample[:list_email], @sample[:email])
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "delete list" do
|
60
60
|
it "should make a DELETE request with correct params" do
|
61
61
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
62
|
-
|
63
|
-
.with("#{@mailgun.lists.send(:list_url, @
|
62
|
+
Mailgun.should_receive(:submit)
|
63
|
+
.with(:delete, "#{@mailgun.lists.send(:list_url, @sample[:list_email])}")
|
64
64
|
.and_return(sample_response)
|
65
65
|
|
66
|
-
@mailgun.lists.delete(@
|
66
|
+
@mailgun.lists.delete(@sample[:list_email])
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
data/spec/log_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Mailgun::Log do
|
|
5
5
|
before :each do
|
6
6
|
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
7
|
|
8
|
-
@
|
8
|
+
@sample = {
|
9
9
|
:email => "test@sample.mailgun.org",
|
10
10
|
:name => "test",
|
11
11
|
:domain => "sample.mailgun.org"
|
@@ -15,9 +15,12 @@ describe Mailgun::Log do
|
|
15
15
|
describe "list log" do
|
16
16
|
it "should make a GET request with the right params" do
|
17
17
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
18
|
-
|
18
|
+
log_url = @mailgun.log(@sample[:domain]).send(:log_url)
|
19
|
+
Mailgun.should_receive(:submit).
|
20
|
+
with(:get, log_url, {}).
|
21
|
+
and_return(sample_response)
|
19
22
|
|
20
|
-
@mailgun.log
|
23
|
+
@mailgun.log(@sample[:domain]).list
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
data/spec/mailbox_spec.rb
CHANGED
@@ -5,9 +5,9 @@ describe Mailgun::Mailbox do
|
|
5
5
|
before :each do
|
6
6
|
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
7
|
|
8
|
-
@
|
8
|
+
@sample = {
|
9
9
|
:email => "test@sample.mailgun.org",
|
10
|
-
:
|
10
|
+
:mailbox_name => "test",
|
11
11
|
:domain => "sample.mailgun.org"
|
12
12
|
}
|
13
13
|
end
|
@@ -15,43 +15,49 @@ describe Mailgun::Mailbox do
|
|
15
15
|
describe "list mailboxes" do
|
16
16
|
it "should make a GET request with the right params" do
|
17
17
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
18
|
-
|
18
|
+
mailboxes_url = @mailgun.mailboxes(@sample[:domain]).send(:mailbox_url)
|
19
19
|
|
20
|
-
|
20
|
+
Mailgun.should_receive(:submit).
|
21
|
+
with(:get,mailboxes_url, {}).
|
22
|
+
and_return(sample_response)
|
23
|
+
|
24
|
+
@mailgun.mailboxes(@sample[:domain]).list
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
28
|
describe "create mailbox" do
|
25
29
|
it "should make a POST request with the right params" do
|
26
|
-
|
27
|
-
|
28
|
-
:
|
29
|
-
|
30
|
+
mailboxes_url = @mailgun.mailboxes(@sample[:domain]).send(:mailbox_url)
|
31
|
+
Mailgun.should_receive(:submit)
|
32
|
+
.with(:post, mailboxes_url,
|
33
|
+
:mailbox => @sample[:email],
|
34
|
+
:password => @sample[:password])
|
30
35
|
.and_return({})
|
31
36
|
|
32
|
-
@mailgun.mailboxes.create(@
|
37
|
+
@mailgun.mailboxes(@sample[:domain]).create(@sample[:mailbox_name], @sample[:password])
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
41
|
describe "update mailbox" do
|
37
42
|
it "should make a PUT request with the right params" do
|
38
|
-
|
39
|
-
|
40
|
-
:password => @
|
43
|
+
mailboxes_url = @mailgun.mailboxes(@sample[:domain]).send(:mailbox_url, @sample[:mailbox_name])
|
44
|
+
Mailgun.should_receive(:submit)
|
45
|
+
.with(:put, mailboxes_url, :password => @sample[:password])
|
41
46
|
.and_return({})
|
42
47
|
|
43
|
-
@mailgun.mailboxes
|
44
|
-
|
48
|
+
@mailgun.mailboxes(@sample[:domain]).
|
49
|
+
update_password(@sample[:mailbox_name], @sample[:password])
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
48
53
|
describe "destroy mailbox" do
|
49
54
|
it "should make a DELETE request with the right params" do
|
50
|
-
|
51
|
-
|
55
|
+
mailboxes_url = @mailgun.mailboxes(@sample[:domain]).send(:mailbox_url, @sample[:name])
|
56
|
+
Mailgun.should_receive(:submit)
|
57
|
+
.with(:delete, mailboxes_url)
|
52
58
|
.and_return({})
|
53
59
|
|
54
|
-
@mailgun.mailboxes.destroy
|
60
|
+
@mailgun.mailboxes(@sample[:domain]).destroy(@sample[:name])
|
55
61
|
end
|
56
62
|
end
|
57
63
|
end
|
data/spec/route_spec.rb
CHANGED
@@ -9,12 +9,18 @@ describe Mailgun::Route do
|
|
9
9
|
|
10
10
|
describe "list routes" do
|
11
11
|
before :each do
|
12
|
-
sample_response =
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
sample_response = <<EOF
|
13
|
+
{
|
14
|
+
"total_count": 0,
|
15
|
+
"items": []
|
16
|
+
}
|
17
|
+
EOF.to_json
|
18
|
+
|
19
|
+
Mailgun.should_receive(:submit).
|
20
|
+
with(:get, "#{@mailgun.routes.send(:route_url)}", {}).
|
21
|
+
and_return(sample_response)
|
16
22
|
end
|
17
|
-
|
23
|
+
|
18
24
|
it "should make a GET request with the right params" do
|
19
25
|
@mailgun.routes.list
|
20
26
|
end
|
@@ -26,9 +32,26 @@ describe Mailgun::Route do
|
|
26
32
|
|
27
33
|
describe "get route" do
|
28
34
|
it "should make a GET request with the right params" do
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
sample_response = <<EOF
|
36
|
+
{
|
37
|
+
"route": {
|
38
|
+
"description": "Sample route",
|
39
|
+
"created_at": "Wed, 15 Feb 2012 13:03:31 GMT",
|
40
|
+
"actions": [
|
41
|
+
"forward(\"http://myhost.com/messages/\")",
|
42
|
+
"stop()"
|
43
|
+
],
|
44
|
+
"priority": 1,
|
45
|
+
"expression": "match_recipient(\".*@samples.mailgun.org\")",
|
46
|
+
"id": "4f3bad2335335426750048c6"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
EOF
|
50
|
+
|
51
|
+
Mailgun.should_receive(:submit).
|
52
|
+
with(:get, "#{@mailgun.routes.send(:route_url, @sample_route_id)}").
|
53
|
+
and_return(sample_response)
|
54
|
+
|
32
55
|
@mailgun.routes.find @sample_route_id
|
33
56
|
end
|
34
57
|
end
|
@@ -42,8 +65,8 @@ describe Mailgun::Route do
|
|
42
65
|
options[:expression] = [:match_recipient, "sample.mailgun.org"]
|
43
66
|
options[:action] = [[:forward, "http://test-site.com"], [:stop]]
|
44
67
|
|
45
|
-
|
46
|
-
.with(@mailgun.routes.send(:route_url), instance_of(Multimap))
|
68
|
+
Mailgun.should_receive(:submit)
|
69
|
+
.with(:post, @mailgun.routes.send(:route_url), instance_of(Multimap))
|
47
70
|
.and_return("{\"route\": {\"id\": \"@sample_route_id\"}}")
|
48
71
|
|
49
72
|
@mailgun.routes.create(
|
@@ -59,9 +82,9 @@ describe Mailgun::Route do
|
|
59
82
|
it "should make a PUT request with the right params" do
|
60
83
|
options = {}
|
61
84
|
options[:description] = "test_route"
|
62
|
-
|
63
|
-
|
64
|
-
.with("#{@mailgun.routes.send(:route_url, @sample_route_id)}", instance_of(Multimap))
|
85
|
+
|
86
|
+
Mailgun.should_receive(:submit)
|
87
|
+
.with(:put, "#{@mailgun.routes.send(:route_url, @sample_route_id)}", instance_of(Multimap))
|
65
88
|
.and_return("{\"id\": \"#{@sample_route_id}\"}")
|
66
89
|
@mailgun.routes.update @sample_route_id, options
|
67
90
|
end
|
@@ -69,9 +92,9 @@ describe Mailgun::Route do
|
|
69
92
|
|
70
93
|
describe "delete route" do
|
71
94
|
it "should make a DELETE request with the right params" do
|
72
|
-
|
73
|
-
|
74
|
-
|
95
|
+
Mailgun.should_receive(:submit).
|
96
|
+
with(:delete, "#{@mailgun.routes.send(:route_url, @sample_route_id)}").
|
97
|
+
and_return("{\"id\": \"#{@sample_route_id}\"}")
|
75
98
|
@mailgun.routes.destroy @sample_route_id
|
76
99
|
end
|
77
100
|
end
|
data/spec/unsubscribe_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Mailgun::Unsubscribe do
|
|
5
5
|
before :each do
|
6
6
|
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
7
|
|
8
|
-
@
|
8
|
+
@sample = {
|
9
9
|
:email => "test@sample.mailgun.org",
|
10
10
|
:name => "test",
|
11
11
|
:domain => "sample.mailgun.org",
|
@@ -16,55 +16,65 @@ describe Mailgun::Unsubscribe do
|
|
16
16
|
describe "list unsubscribes" do
|
17
17
|
it "should make a GET request with the right params" do
|
18
18
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
19
|
-
|
19
|
+
unsubscribes_url = @mailgun.unsubscribes(@sample[:domain]).send(:unsubscribe_url)
|
20
|
+
Mailgun.should_receive(:submit).
|
21
|
+
with(:get, unsubscribes_url, {}).
|
22
|
+
and_return(sample_response)
|
20
23
|
|
21
|
-
@mailgun.unsubscribes
|
24
|
+
@mailgun.unsubscribes(@sample[:domain]).list
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
28
|
describe "find unsubscribe" do
|
26
29
|
it "should make a GET request with the right params to find given email address" do
|
27
30
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
28
|
-
|
29
|
-
.with("#{@mailgun.unsubscribes.send(:unsubscribe_url, @unsubscribe_options[:domain], @unsubscribe_options[:email])}", {})
|
30
|
-
.and_return(sample_response)
|
31
|
+
unsubscribes_url = @mailgun.unsubscribes(@sample[:domain]).send(:unsubscribe_url, @sample[:email])
|
31
32
|
|
32
|
-
|
33
|
+
Mailgun.should_receive(:submit)
|
34
|
+
.with(:get, unsubscribes_url)
|
35
|
+
.and_return(sample_response)
|
36
|
+
|
37
|
+
@mailgun.unsubscribes(@sample[:domain]).find(@sample[:email])
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
41
|
describe "delete unsubscribe" do
|
37
42
|
it "should make a DELETE request with correct params to remove a given email address" do
|
38
|
-
response_message = "{\"message\"=>\"Unsubscribe event has been removed\", \"address\"=>\"#{@
|
43
|
+
response_message = "{\"message\"=>\"Unsubscribe event has been removed\", \"address\"=>\"#{@sample[:email]}\"}"
|
44
|
+
unsubscribes_url = @mailgun.unsubscribes(@sample[:domain]).send(:unsubscribe_url, @sample[:email])
|
45
|
+
|
39
46
|
Mailgun.should_receive(:submit)
|
40
|
-
|
41
|
-
|
47
|
+
.with(:delete, unsubscribes_url)
|
48
|
+
.and_return(response_message)
|
42
49
|
|
43
|
-
@mailgun.unsubscribes
|
50
|
+
@mailgun.unsubscribes(@sample[:domain]).remove(@sample[:email])
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
47
54
|
describe "add unsubscribe" do
|
48
55
|
context "to tag" do
|
49
56
|
it "should make a POST request with correct params to add a given email address to unsubscribe from a tag" do
|
50
|
-
response_message = "{\"message\"=>\"Address has been added to the unsubscribes table\", \"address\"=>\"#{@
|
57
|
+
response_message = "{\"message\"=>\"Address has been added to the unsubscribes table\", \"address\"=>\"#{@sample[:email]}\"}"
|
51
58
|
Mailgun.should_receive(:submit)
|
52
|
-
|
53
|
-
|
54
|
-
|
59
|
+
.with(:post, "#{@mailgun.unsubscribes(@sample[:domain]).send(:unsubscribe_url)}",{:address=>@sample[:email], :tag=>@sample[:tag]})
|
60
|
+
.and_return(response_message)
|
61
|
+
|
62
|
+
@mailgun.unsubscribes(@sample[:domain]).add(@sample[:email], @sample[:tag])
|
55
63
|
end
|
56
64
|
end
|
57
65
|
|
58
66
|
context "on all" do
|
59
67
|
it "should make a POST request with correct params to add a given email address to unsubscribe from all tags" do
|
60
68
|
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
69
|
+
unsubscribes_url = @mailgun.unsubscribes(@sample[:domain]).send(:unsubscribe_url)
|
70
|
+
|
71
|
+
Mailgun.should_receive(:submit)
|
72
|
+
.with(:post, unsubscribes_url, {
|
73
|
+
:address => @sample[:email], :tag => '*'
|
74
|
+
})
|
75
|
+
.and_return(sample_response)
|
66
76
|
|
67
|
-
@mailgun.unsubscribes
|
77
|
+
@mailgun.unsubscribes(@sample[:domain]).add(@sample[:email])
|
68
78
|
end
|
69
79
|
end
|
70
80
|
end
|