mailgun 0.0.3 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +2 -2
- data/README.md +125 -12
- data/lib/mailgun/base.rb +71 -13
- data/lib/mailgun/bounce.rb +35 -0
- data/lib/mailgun/complaint.rb +38 -0
- data/lib/mailgun/list/member.rb +57 -0
- data/lib/mailgun/list.rb +59 -0
- data/lib/mailgun/log.rb +26 -0
- data/lib/mailgun/mailbox.rb +10 -11
- data/lib/mailgun/mailgun_error.rb +4 -0
- data/lib/mailgun/route.rb +94 -0
- data/lib/mailgun/unsubscribe.rb +38 -0
- data/lib/mailgun.rb +15 -3
- data/mailgun.gemspec +5 -2
- data/spec/base_spec.rb +113 -19
- data/spec/bounce_spec.rb +47 -0
- data/spec/complaint_spec.rb +56 -0
- data/spec/list/member_spec.rb +71 -0
- data/spec/list_spec.rb +70 -0
- data/spec/log_spec.rb +24 -0
- data/spec/mailbox_spec.rb +49 -49
- data/spec/route_spec.rb +78 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/unsubscribe_spec.rb +72 -0
- metadata +59 -6
@@ -0,0 +1,38 @@
|
|
1
|
+
module Mailgun
|
2
|
+
class Unsubscribe
|
3
|
+
# Used internally, called from Mailgun::Base
|
4
|
+
def initialize(mailgun)
|
5
|
+
@mailgun = mailgun
|
6
|
+
end
|
7
|
+
|
8
|
+
# List all unsubscribes for a given domain
|
9
|
+
# * domain the domain for which all unsubscribes will listed
|
10
|
+
def list(domain = Mailgun.domain)
|
11
|
+
response = Mailgun.submit :get, unsubscribe_url(domain)
|
12
|
+
|
13
|
+
if response
|
14
|
+
response["items"].collect {|item| item["address"]}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def find(domain = Mailgun.domain, email)
|
19
|
+
Mailgun.submit :get, unsubscribe_url(domain, email)
|
20
|
+
end
|
21
|
+
|
22
|
+
def add(email, domain=Mailgun.domain, tag='*')
|
23
|
+
Mailgun.submit :post, unsubscribe_url(domain), {:address => email, :tag => tag}
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove(domain = Mailgun.domain, email)
|
27
|
+
Mailgun.submit :delete, unsubscribe_url(domain, email)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Helper method to generate the proper url for Mailgun unsubscribe API calls
|
33
|
+
def unsubscribe_url(domain, address=nil)
|
34
|
+
"#{@mailgun.base_url}/#{domain}/unsubscribes#{'/' + address if address}"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/mailgun.rb
CHANGED
@@ -1,9 +1,21 @@
|
|
1
1
|
require "rest-client"
|
2
2
|
require "json"
|
3
|
+
require "multimap"
|
3
4
|
|
4
|
-
require
|
5
|
-
require
|
5
|
+
require "mailgun/mailgun_error"
|
6
|
+
require "mailgun/base"
|
7
|
+
require "mailgun/route"
|
8
|
+
require "mailgun/mailbox"
|
9
|
+
require "mailgun/bounce"
|
10
|
+
require "mailgun/unsubscribe"
|
11
|
+
require "mailgun/complaint"
|
12
|
+
require "mailgun/log"
|
13
|
+
require "mailgun/list"
|
14
|
+
require "mailgun/list/member"
|
6
15
|
|
7
|
-
|
16
|
+
#require "startup"
|
17
|
+
|
18
|
+
def Mailgun(options={})
|
19
|
+
options[:api_key] = Mailgun.api_key if Mailgun.api_key
|
8
20
|
Mailgun::Base.new(options)
|
9
21
|
end
|
data/mailgun.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.authors = ["Akash Manohar J", "Sean Grove"]
|
5
|
-
gem.email = ["akash@akash.im"
|
5
|
+
gem.email = ["akash@akash.im"]
|
6
6
|
gem.description = %q{Mailgun library for Ruby}
|
7
7
|
gem.summary = %q{Idiomatic library for using the mailgun API from within ruby}
|
8
8
|
gem.homepage = "http://github.com/Bushido/mailgun"
|
@@ -12,5 +12,8 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
13
|
gem.name = "mailgun"
|
14
14
|
gem.require_paths = ["lib"]
|
15
|
-
gem.version = "0.
|
15
|
+
gem.version = "0.5"
|
16
|
+
|
17
|
+
gem.add_dependency(%q<rest-client>, [">= 0"])
|
18
|
+
gem.add_dependency(%q<multimap>, [">= 0"])
|
16
19
|
end
|
data/spec/base_spec.rb
CHANGED
@@ -2,31 +2,125 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mailgun::Base do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
:api_key => @mailgun.api_key,
|
10
|
-
:api_version => @mailgun.api_version,
|
11
|
-
:protocol => @mailgun.protocol,
|
12
|
-
:mailgun_host => @mailgun.mailgun_host
|
13
|
-
}
|
5
|
+
it "should raise an error if the api_key has not been set" do
|
6
|
+
expect do
|
7
|
+
Mailgun()
|
8
|
+
end.to raise_error ArgumentError
|
14
9
|
end
|
15
10
|
|
16
|
-
|
11
|
+
it "can be called directly if the api_key has been set via Mailgun.configure" do
|
12
|
+
Mailgun.config { |c| c.api_key = "some-junk-string" }
|
13
|
+
expect do
|
14
|
+
Mailgun()
|
15
|
+
end.to_not raise_error ArgumentError
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can be instanced with the api_key as a param" do
|
19
|
+
expect do
|
20
|
+
Mailgun({:api_key => "some-junk-string"})
|
21
|
+
end.to_not raise_error ArgumentError
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Mailgun.new" do
|
17
25
|
it "Mailgun() method should return a new Mailgun object" do
|
18
|
-
|
26
|
+
mailgun = Mailgun({:api_key => "some-junk-string"})
|
27
|
+
mailgun.should be_kind_of(Mailgun::Base)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "resources" do
|
32
|
+
before :each do
|
33
|
+
@mailgun = Mailgun({:api_key => "some-junk-string"})
|
19
34
|
end
|
20
35
|
|
21
|
-
it "should
|
22
|
-
@mailgun.
|
36
|
+
it "Mailgun#mailboxes should return an instance of Mailgun::Mailbox" do
|
37
|
+
@mailgun.mailboxes.should be_kind_of(Mailgun::Mailbox)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Mailgun#routes should return an instance of Mailgun::Route" do
|
41
|
+
@mailgun.routes.should be_kind_of(Mailgun::Route)
|
23
42
|
end
|
24
43
|
end
|
25
44
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
45
|
+
|
46
|
+
|
47
|
+
describe "internal helper methods" do
|
48
|
+
before :each do
|
49
|
+
@mailgun = Mailgun({:api_key => "some-junk-string"})
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "Mailgun#base_url" do
|
53
|
+
it "should return https url if use_https is true" do
|
54
|
+
@mailgun.base_url.should == "https://api:#{Mailgun.api_key}@#{Mailgun.mailgun_host}/#{Mailgun.api_version}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "Mailgun.submit" do
|
59
|
+
it "should send method and arguments to RestClient" do
|
60
|
+
RestClient.should_receive(:test_method)
|
61
|
+
.with({:arg1=>"val1"},{})
|
62
|
+
.and_return({})
|
63
|
+
Mailgun.submit :test_method, :arg1=>"val1"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "configuration" do
|
70
|
+
describe "default settings" do
|
71
|
+
it "api_version is v2" do
|
72
|
+
Mailgun.api_version.should eql 'v2'
|
73
|
+
end
|
74
|
+
it "should use https by default" do
|
75
|
+
Mailgun.protocol.should == "https"
|
76
|
+
end
|
77
|
+
it "mailgun_host is 'api.mailgun.net'" do
|
78
|
+
Mailgun.mailgun_host.should eql 'api.mailgun.net'
|
79
|
+
end
|
80
|
+
|
81
|
+
it "test_mode is false" do
|
82
|
+
Mailgun.test_mode.should eql false
|
83
|
+
end
|
84
|
+
|
85
|
+
it "domain is not set" do
|
86
|
+
Mailgun.domain.should be_nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "setting configurations" do
|
91
|
+
before(:each) do
|
92
|
+
Mailgun.configure do |c|
|
93
|
+
c.api_key = 'some-api-key'
|
94
|
+
c.api_version = 'v2'
|
95
|
+
c.protocol = 'https'
|
96
|
+
c.mailgun_host = 'api.mailgun.net'
|
97
|
+
c.test_mode = false
|
98
|
+
c.domain = 'some-domain'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "allows me to set my API key easily" do
|
103
|
+
Mailgun.api_key.should eql 'some-api-key'
|
104
|
+
end
|
105
|
+
|
106
|
+
it "allows me to set the api_version attribute" do
|
107
|
+
Mailgun.api_version.should eql 'v2'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "allows me to set the protocol attribute" do
|
111
|
+
Mailgun.protocol.should eql 'https'
|
112
|
+
end
|
113
|
+
|
114
|
+
it "allows me to set the mailgun_host attribute" do
|
115
|
+
Mailgun.mailgun_host.should eql 'api.mailgun.net'
|
116
|
+
end
|
117
|
+
it "allows me to set the test_mode attribute" do
|
118
|
+
Mailgun.test_mode.should eql false
|
119
|
+
end
|
120
|
+
|
121
|
+
it "allows me to set my domain easily" do
|
122
|
+
Mailgun.domain.should eql 'some-domain'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
32
126
|
end
|
data/spec/bounce_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mailgun::Bounce do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
|
+
|
8
|
+
@bounce_options = {
|
9
|
+
:email => "test@sample.mailgun.org",
|
10
|
+
:name => "test",
|
11
|
+
:domain => "sample.mailgun.org"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "list bounces" do
|
16
|
+
it "should make a GET request with the right params" do
|
17
|
+
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
18
|
+
RestClient.should_receive(:get).with("#{@mailgun.bounces.send(:bounce_url, @bounce_options[:domain])}", {}).and_return(sample_response)
|
19
|
+
|
20
|
+
@mailgun.bounces.list @bounce_options[:domain]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "find bounces" do
|
25
|
+
it "should make a GET request with correct params to find given email address" do
|
26
|
+
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
27
|
+
RestClient.should_receive(:get)
|
28
|
+
.with("#{@mailgun.bounces.send(:bounce_url, @bounce_options[:domain], @bounce_options[:email])}", {})
|
29
|
+
.and_return(sample_response)
|
30
|
+
|
31
|
+
@mailgun.bounces.find(@bounce_options[:domain], @bounce_options[:email])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "add bounces" do
|
36
|
+
it "should make a POST request with correct params to add a given email address" do
|
37
|
+
#sample_response = "{\"message\"=>\"Address has been added to the bounces table\", \"address\"=>\"#{@bounce_options[:email]}\"}"
|
38
|
+
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
39
|
+
RestClient.should_receive(:post)
|
40
|
+
.with("#{@mailgun.bounces.send(:bounce_url, @bounce_options[:domain])}", {:address => @bounce_options[:email]})
|
41
|
+
.and_return(sample_response)
|
42
|
+
|
43
|
+
@mailgun.bounces.add(@bounce_options[:domain], @bounce_options[:email])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mailgun::Complaint do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
|
+
|
8
|
+
@complaint_options = {
|
9
|
+
:email => "test@sample.mailgun.org",
|
10
|
+
:name => "test",
|
11
|
+
:domain => "sample.mailgun.org"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "list complaints" do
|
16
|
+
it "should make a GET request with the right params" do
|
17
|
+
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
18
|
+
RestClient.should_receive(:get).with("#{@mailgun.complaints.send(:complaint_url, @complaint_options[:domain])}", {}).and_return(sample_response)
|
19
|
+
|
20
|
+
@mailgun.complaints.list @complaint_options[:domain]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "find complaint" do
|
25
|
+
it "should make a GET request with the right params to find given email address" do
|
26
|
+
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.mailgun.org\" } ]}"
|
27
|
+
RestClient.should_receive(:get)
|
28
|
+
.with("#{@mailgun.complaints.send(:complaint_url, @complaint_options[:domain], @complaint_options[:email])}", {})
|
29
|
+
.and_return(sample_response)
|
30
|
+
|
31
|
+
@mailgun.complaints.find(@complaint_options[:domain], @complaint_options[:email])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "delete complaint" do
|
36
|
+
it "should make a DELETE request with correct params to remove a given email address" do
|
37
|
+
response_message = "{\"message\"=>\"Complaint event has been removed\", \"address\"=>\"#{@complaint_options[:email]}\"}"
|
38
|
+
Mailgun.should_receive(:submit)
|
39
|
+
.with(:delete, "#{@mailgun.complaints.send(:complaint_url, @complaint_options[:domain], @complaint_options[:email])}")
|
40
|
+
.and_return(response_message)
|
41
|
+
|
42
|
+
@mailgun.complaints.remove(@complaint_options[:domain], @complaint_options[:email])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "add complaint" do
|
47
|
+
it "should make a POST request with correct params to add a given email address to complaint from a tag" do
|
48
|
+
response_message = "{\"message\"=>\"Address has been added to the complaints table\", \"address\"=>\"#{@complaint_options[:email]}\"}"
|
49
|
+
Mailgun.should_receive(:submit)
|
50
|
+
.with(:post, "#{@mailgun.complaints.send(:complaint_url, @complaint_options[:domain])}",{:address=>@complaint_options[:email]})
|
51
|
+
.and_return(response_message)
|
52
|
+
@mailgun.complaints.add(@complaint_options[:domain],@complaint_options[:email])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mailgun::List::Member do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
|
+
|
8
|
+
@list_member_options = {
|
9
|
+
:email => "test@sample.mailgun.org",
|
10
|
+
:list_email => "test_list@sample.mailgun.org",
|
11
|
+
:name => "test",
|
12
|
+
:domain => "sample.mailgun.org"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "list members" do
|
17
|
+
it "should make a GET request with the right params" do
|
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)
|
20
|
+
|
21
|
+
@mailgun.list_members.list @list_member_options[:list_email]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "find member in list" do
|
26
|
+
it "should make a GET request with correct params to find given email address" do
|
27
|
+
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)
|
31
|
+
|
32
|
+
@mailgun.list_members.find(@list_member_options[:list_email], @list_member_options[:email])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "add member to list" do
|
37
|
+
it "should make a POST request with correct params to add a given email address" do
|
38
|
+
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)
|
43
|
+
|
44
|
+
@mailgun.list_members.add(@list_member_options[:list_email], @list_member_options[:email])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "update member in list" do
|
49
|
+
it "should make a PUT request with correct params" do
|
50
|
+
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)
|
55
|
+
|
56
|
+
@mailgun.list_members.update(@list_member_options[:list_email], @list_member_options[:email])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "delete member from list" do
|
61
|
+
it "should make a DELETE request with correct params" do
|
62
|
+
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)
|
66
|
+
|
67
|
+
@mailgun.list_members.remove(@list_member_options[:list_email], @list_member_options[:email])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/spec/list_spec.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mailgun::List do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
|
+
|
8
|
+
@list_options = {
|
9
|
+
:email => "test@sample.mailgun.org",
|
10
|
+
:list_email => "dev@samples.mailgun.org",
|
11
|
+
:name => "test",
|
12
|
+
:domain => "sample.mailgun.org"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "all list" do
|
17
|
+
it "should make a GET request with the right params" do
|
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)
|
21
|
+
|
22
|
+
@mailgun.lists.all
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "find list adress" do
|
27
|
+
it "should make a GET request with correct params to find given email address" do
|
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])}", {})
|
31
|
+
.and_return(sample_response)
|
32
|
+
|
33
|
+
@mailgun.lists.find(@list_options[:list_email])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "create list" do
|
38
|
+
it "should make a POST request with correct params to add a given email address" do
|
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]})
|
42
|
+
.and_return(sample_response)
|
43
|
+
|
44
|
+
@mailgun.lists.create(@list_options[:list_email])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "update list" do
|
49
|
+
it "should make a PUT request with correct params" do
|
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]})
|
53
|
+
.and_return(sample_response)
|
54
|
+
|
55
|
+
@mailgun.lists.update(@list_options[:list_email], @list_options[:email])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "delete list" do
|
60
|
+
it "should make a DELETE request with correct params" do
|
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])}", {})
|
64
|
+
.and_return(sample_response)
|
65
|
+
|
66
|
+
@mailgun.lists.delete(@list_options[:list_email])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/spec/log_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
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
|
+
@log_options = {
|
9
|
+
:email => "test@sample.mailgun.org",
|
10
|
+
:name => "test",
|
11
|
+
:domain => "sample.mailgun.org"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "list log" do
|
16
|
+
it "should make a GET request with the right params" do
|
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)
|
19
|
+
|
20
|
+
@mailgun.log.list @log_options[:domain]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/mailbox_spec.rb
CHANGED
@@ -2,56 +2,56 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mailgun::Mailbox do
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
before :each do
|
6
|
+
@mailgun = Mailgun({:api_key => "api-key"}) # used to get the default values
|
7
7
|
|
8
|
-
|
9
|
-
:email => "test@sample.mailgun.
|
8
|
+
@mailbox_options = {
|
9
|
+
:email => "test@sample.mailgun.org",
|
10
10
|
:name => "test",
|
11
|
-
:domain => "sample.mailgun.
|
11
|
+
:domain => "sample.mailgun.org"
|
12
12
|
}
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
.with("#{@mailgun.send(:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "list mailboxes" do
|
16
|
+
it "should make a GET request with the right params" do
|
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)
|
19
|
+
|
20
|
+
@mailgun.mailboxes.list @mailbox_options[:domain]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "create mailbox" do
|
25
|
+
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
|
+
.and_return({})
|
31
|
+
|
32
|
+
@mailgun.mailboxes.create(@mailbox_options[:email], @mailbox_options[:password])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "update mailbox" do
|
37
|
+
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])
|
41
|
+
.and_return({})
|
42
|
+
|
43
|
+
@mailgun.mailboxes.update_password @mailbox_options[:email],
|
44
|
+
@mailbox_options[:password]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "destroy mailbox" do
|
49
|
+
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])}", {})
|
52
|
+
.and_return({})
|
53
|
+
|
54
|
+
@mailgun.mailboxes.destroy @mailbox_options[:email]
|
55
|
+
end
|
56
|
+
end
|
57
57
|
end
|