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.
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mailgun::List::Member do
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
- @list_member_options = {
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
- RestClient.should_receive(:get).with("#{@mailgun.list_members.send(:list_member_url, @list_member_options[:list_email])}", {}).and_return(sample_response)
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.list @list_member_options[:list_email]
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
- RestClient.should_receive(:get)
29
- .with("#{@mailgun.list_members.send(:list_member_url, @list_member_options[:list_email], @list_member_options[:email])}", {})
30
- .and_return(sample_response)
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.find(@list_member_options[:list_email], @list_member_options[:email])
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
- RestClient.should_receive(:post)
40
- .with("#{@mailgun.list_members.send(:list_member_url, @list_member_options[:list_email])}", {
41
- :address => @list_member_options[:email], :subscribed => 'yes', :upsert => 'no'
42
- }).and_return(sample_response)
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.add(@list_member_options[:list_email], @list_member_options[:email])
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
- RestClient.should_receive(:put)
52
- .with("#{@mailgun.list_members.send(:list_member_url, @list_member_options[:list_email], @list_member_options[:email])}", {
53
- :address => @list_member_options[:email], :subscribed => 'yes'
54
- }).and_return(sample_response)
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.update(@list_member_options[:list_email], @list_member_options[:email])
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
- RestClient.should_receive(:delete)
64
- .with("#{@mailgun.list_members.send(:list_member_url, @list_member_options[:list_email], @list_member_options[:email])}", {})
65
- .and_return(sample_response)
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.remove(@list_member_options[:list_email], @list_member_options[:email])
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
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mailgun::List do
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
- @list_options = {
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 "all list" do
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
- RestClient.should_receive(:get)
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.all
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
- RestClient.should_receive(:get)
30
- .with("#{@mailgun.lists.send(:list_url, @list_options[:list_email])}", {})
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(@list_options[:list_email])
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
- RestClient.should_receive(:post)
41
- .with("#{@mailgun.lists.send(:list_url)}", {:address => @list_options[:list_email]})
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(@list_options[:list_email])
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
- RestClient.should_receive(:put)
52
- .with("#{@mailgun.lists.send(:list_url, @list_options[:list_email])}", {:address => @list_options[:email]})
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(@list_options[:list_email], @list_options[:email])
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
- RestClient.should_receive(:delete)
63
- .with("#{@mailgun.lists.send(:list_url, @list_options[:list_email])}", {})
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(@list_options[:list_email])
66
+ @mailgun.lists.delete(@sample[:list_email])
67
67
  end
68
68
  end
69
69
 
@@ -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
- @log_options = {
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
- RestClient.should_receive(:get).with("#{@mailgun.log.send(:log_url, @log_options[:domain])}", {:limit => 100, :skip => 0}).and_return(sample_response)
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.list @log_options[:domain]
23
+ @mailgun.log(@sample[:domain]).list
21
24
  end
22
25
  end
23
26
 
@@ -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
- @mailbox_options = {
8
+ @sample = {
9
9
  :email => "test@sample.mailgun.org",
10
- :name => "test",
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
- RestClient.should_receive(:get).with("#{@mailgun.mailboxes.send(:mailbox_url, @mailbox_options[:domain])}", {}).and_return(sample_response)
18
+ mailboxes_url = @mailgun.mailboxes(@sample[:domain]).send(:mailbox_url)
19
19
 
20
- @mailgun.mailboxes.list @mailbox_options[:domain]
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
- RestClient.should_receive(:post)
27
- .with("#{@mailgun.mailboxes.send(:mailbox_url, @mailbox_options[:domain])}",
28
- :mailbox => @mailbox_options[:email],
29
- :password => @mailbox_options[:password])
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(@mailbox_options[:email], @mailbox_options[:password])
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
- RestClient.should_receive(:put)
39
- .with("#{@mailgun.mailboxes.send(:mailbox_url, @mailbox_options[:domain], @mailbox_options[:name])}",
40
- :password => @mailbox_options[: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.update_password @mailbox_options[:email],
44
- @mailbox_options[:password]
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
- RestClient.should_receive(:delete)
51
- .with("#{@mailgun.mailboxes.send(:mailbox_url, @mailbox_options[:domain], @mailbox_options[:name])}", {})
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 @mailbox_options[:email]
60
+ @mailgun.mailboxes(@sample[:domain]).destroy(@sample[:name])
55
61
  end
56
62
  end
57
63
  end
@@ -9,12 +9,18 @@ describe Mailgun::Route do
9
9
 
10
10
  describe "list routes" do
11
11
  before :each do
12
- sample_response = "{\"items\": []}"
13
- RestClient.should_receive(:get)
14
- .with("#{@mailgun.routes.send(:route_url)}",:limit=>100, :skip=>0)
15
- .and_return(sample_response)
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
- RestClient.should_receive(:get)
30
- .with("#{@mailgun.routes.send(:route_url, @sample_route_id)}", {})
31
- .and_return("{\"route\": {\"id\": \"#{@sample_route_id}\" }}")
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
- RestClient.should_receive(:post)
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
- RestClient.should_receive(:put)
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
- RestClient.should_receive(:delete)
73
- .with("#{@mailgun.routes.send(:route_url, @sample_route_id)}", {})
74
- .and_return("{\"id\": \"#{@sample_route_id}\"}")
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
@@ -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
- @unsubscribe_options = {
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
- RestClient.should_receive(:get).with("#{@mailgun.unsubscribes.send(:unsubscribe_url, @unsubscribe_options[:domain])}", {}).and_return(sample_response)
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.list @unsubscribe_options[:domain]
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
- RestClient.should_receive(:get)
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
- @mailgun.unsubscribes.find(@unsubscribe_options[:domain], @unsubscribe_options[:email])
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\"=>\"#{@unsubscribe_options[:email]}\"}"
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
- .with(:delete, "#{@mailgun.unsubscribes.send(:unsubscribe_url, @unsubscribe_options[:domain], @unsubscribe_options[:email])}")
41
- .and_return(response_message)
47
+ .with(:delete, unsubscribes_url)
48
+ .and_return(response_message)
42
49
 
43
- @mailgun.unsubscribes.remove(@unsubscribe_options[:domain], @unsubscribe_options[:email])
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\"=>\"#{@unsubscribe_options[:email]}\"}"
57
+ response_message = "{\"message\"=>\"Address has been added to the unsubscribes table\", \"address\"=>\"#{@sample[:email]}\"}"
51
58
  Mailgun.should_receive(:submit)
52
- .with(:post, "#{@mailgun.unsubscribes.send(:unsubscribe_url, @unsubscribe_options[:domain])}",{:address=>@unsubscribe_options[:email], :tag=>@unsubscribe_options[:tag]})
53
- .and_return(response_message)
54
- @mailgun.unsubscribes.add(@unsubscribe_options[:email], @unsubscribe_options[:domain], @unsubscribe_options[:tag])
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
- RestClient.should_receive(:post)
62
- .with("#{@mailgun.unsubscribes.send(:unsubscribe_url, @unsubscribe_options[:domain])}", {
63
- :address => @unsubscribe_options[:email], :tag => '*'
64
- })
65
- .and_return(sample_response)
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.add(@unsubscribe_options[:email], @unsubscribe_options[:domain])
77
+ @mailgun.unsubscribes(@sample[:domain]).add(@sample[:email])
68
78
  end
69
79
  end
70
80
  end