mailgun 0.6 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/mailgun.rb +1 -0
- data/lib/mailgun/base.rb +6 -0
- data/lib/mailgun/domain.rb +40 -0
- data/mailgun.gemspec +1 -1
- data/spec/domain_spec.rb +68 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f299f5774c3b4633c5585f6fd12c81c47c06de1c
|
4
|
+
data.tar.gz: fefddce633b68496cd6248cd93e70e1e6684ce38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6171bc203666c967ab67d3f9bed2ff5c2177810bf13895e2c67d5ef8158c09dd1ede7cd396f22c62a86a05f14efda28180af0600dd344aec366555da9a9fb5c5
|
7
|
+
data.tar.gz: 6b5c901517191cdf63704b22859b0c4bb03d516cc48efbe8eefe2a085278b84d8dec4eee9a9bfc98514911daece3d2e8127ae4be0777a3136d484f2583211918
|
data/README.md
CHANGED
@@ -15,6 +15,7 @@ Mailgun exposes the following resources:
|
|
15
15
|
* Bounces
|
16
16
|
* Unsubscribes
|
17
17
|
* Complaints
|
18
|
+
* Domain management
|
18
19
|
|
19
20
|
Patches are welcome (and easy!).
|
20
21
|
|
@@ -150,6 +151,21 @@ Supported route filters are: `:match_header`, `:match_recipient`, and `:catch_al
|
|
150
151
|
Supported route actions are: `:forward`, and `:stop`
|
151
152
|
|
152
153
|
|
154
|
+
#### Domains
|
155
|
+
```ruby
|
156
|
+
# Add a domain
|
157
|
+
@mailgun.domains.create "example.com"
|
158
|
+
|
159
|
+
# List all domains that belong to the account
|
160
|
+
@mailgun.domains.list
|
161
|
+
|
162
|
+
# Get info for a domain
|
163
|
+
@mailgun.domains.find "example.com"
|
164
|
+
|
165
|
+
# Remove a domain
|
166
|
+
@mailbox.domains.delete "example.com"
|
167
|
+
```
|
168
|
+
|
153
169
|
## Making Your Changes
|
154
170
|
|
155
171
|
* Fork the project (Github has really good step-by-step directions)
|
@@ -186,6 +202,8 @@ Supported route actions are: `:forward`, and `:stop`
|
|
186
202
|
* Yomi Colledge ([@baphled](http://github.com/baphled))
|
187
203
|
* Scott Carleton ([@scotterc](http://github.com/scotterc)) - new functionality and improvements
|
188
204
|
* Alan deLevie ([@adelevie](http://github.com/adelevie)) - Sending email
|
205
|
+
* kdayton (<http://github.com/kdayton->) - Support for domains API
|
206
|
+
* gabriel (<http://github.com/gabriel>) - Fix to accept domain in options
|
189
207
|
|
190
208
|
## License
|
191
209
|
|
data/lib/mailgun.rb
CHANGED
data/lib/mailgun/base.rb
CHANGED
@@ -6,12 +6,14 @@ module Mailgun
|
|
6
6
|
# * Procotol - http or https [default to https]
|
7
7
|
# * API key and version
|
8
8
|
# * Test mode - if enabled, doesn't actually send emails (see http://documentation.mailgun.net/user_manual.html#sending-in-test-mode)
|
9
|
+
# * Domain - domain to use
|
9
10
|
def initialize(options)
|
10
11
|
Mailgun.mailgun_host = options.fetch(:mailgun_host) {"api.mailgun.net"}
|
11
12
|
Mailgun.protocol = options.fetch(:protocol) { "https" }
|
12
13
|
Mailgun.api_version = options.fetch(:api_version) { "v2" }
|
13
14
|
Mailgun.test_mode = options.fetch(:test_mode) { false }
|
14
15
|
Mailgun.api_key = options.fetch(:api_key) { raise ArgumentError.new(":api_key is a required argument to initialize Mailgun") if Mailgun.api_key.nil?}
|
16
|
+
Mailgun.domain = options.fetch(:domain)
|
15
17
|
end
|
16
18
|
|
17
19
|
# Returns the base url used in all Mailgun API calls
|
@@ -36,6 +38,10 @@ module Mailgun
|
|
36
38
|
Mailgun::Bounce.new(self, domain)
|
37
39
|
end
|
38
40
|
|
41
|
+
def domains
|
42
|
+
Mailgun::Domain.new(self)
|
43
|
+
end
|
44
|
+
|
39
45
|
def unsubscribes(domain = Mailgun.domain)
|
40
46
|
Mailgun::Unsubscribe.new(self, domain)
|
41
47
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Mailgun
|
2
|
+
|
3
|
+
# Interface to manage domains
|
4
|
+
class Domain
|
5
|
+
|
6
|
+
# Used internally, called from Mailgun::Base
|
7
|
+
def initialize(mailgun)
|
8
|
+
@mailgun = mailgun
|
9
|
+
end
|
10
|
+
|
11
|
+
# List all domains on the account
|
12
|
+
def list(options={})
|
13
|
+
Mailgun.submit(:get, domain_url, options)["items"] || []
|
14
|
+
end
|
15
|
+
|
16
|
+
# Find domain by name
|
17
|
+
def find(domain)
|
18
|
+
Mailgun.submit :get, domain_url(domain)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Add domain to account
|
22
|
+
def create(domain, opts = {})
|
23
|
+
opts = {name: domain}.merge(opts)
|
24
|
+
Mailgun.submit :post, domain_url, opts
|
25
|
+
end
|
26
|
+
|
27
|
+
# Remves a domain from account
|
28
|
+
def delete(domain)
|
29
|
+
Mailgun.submit :delete, domain_url(domain)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Helper method to generate the proper url for Mailgun domain API calls
|
35
|
+
def domain_url(domain = nil)
|
36
|
+
"#{@mailgun.base_url}/domains#{'/' + domain if domain}"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/mailgun.gemspec
CHANGED
@@ -12,7 +12,7 @@ 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.7"
|
16
16
|
|
17
17
|
gem.add_dependency(%q<rest-client>, [">= 0"])
|
18
18
|
gem.add_dependency(%q<multimap>, [">= 0"])
|
data/spec/domain_spec.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mailgun::Domain 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 "list domains" do
|
16
|
+
it "should make a GET request with the right params" do
|
17
|
+
|
18
|
+
sample_response = "{\"total_count\": 1, \"items\": [{\"created_at\": \"Tue, 12 Feb 2013 20:13:49 GMT\", \"smtp_login\": \"postmaster@sample.mailgun.org\", \"name\": \"sample.mailgun.org\", \"smtp_password\": \"67bw67bz7w\" }]}"
|
19
|
+
domains_url = @mailgun.domains.send(:domain_url)
|
20
|
+
|
21
|
+
Mailgun.should_receive(:submit).
|
22
|
+
with(:get, domains_url, {}).
|
23
|
+
and_return(sample_response)
|
24
|
+
|
25
|
+
@mailgun.domains.list
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "find domains" do
|
30
|
+
it "should make a GET request with correct params to find given domain" do
|
31
|
+
sample_response = "{\"domain\": {\"created_at\": \"Tue, 12 Feb 2013 20:13:49 GMT\", \"smtp_login\": \"postmaster@bample.mailgun.org\", \"name\": \"sample.mailgun.org\", \"smtp_password\": \"67bw67bz7w\" }, \"receiving_dns_records\": [], \"sending_dns_records\": []}"
|
32
|
+
domains_url = @mailgun.domains.send(:domain_url, @sample[:domain])
|
33
|
+
|
34
|
+
Mailgun.should_receive(:submit).
|
35
|
+
with(:get, domains_url).
|
36
|
+
and_return(sample_response)
|
37
|
+
|
38
|
+
@mailgun.domains.find(@sample[:domain])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "add domains" do
|
43
|
+
it "should make a POST request with correct params to add a domain" do
|
44
|
+
sample_response = "{\"domain\": {\"created_at\": \"Tue, 12 Feb 2013 20:13:49 GMT\", \"smtp_login\": \"postmaster@sample.mailgun.org\",\"name\": \"sample.mailgun.org\",\"smtp_password\": \"67bw67bz7w\"}, \"message\": \"Domain has been created\"}"
|
45
|
+
domains_url = @mailgun.domains.send(:domain_url)
|
46
|
+
|
47
|
+
Mailgun.should_receive(:submit).
|
48
|
+
with(:post, domains_url, {:name => @sample[:domain]} ).
|
49
|
+
and_return(sample_response)
|
50
|
+
|
51
|
+
@mailgun.domains.create(@sample[:domain])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "delete domain" do
|
56
|
+
it "should make a DELETE request with correct params" do
|
57
|
+
sample_response = "{\"message\": \"Domain has been deleted\"}"
|
58
|
+
domains_url = @mailgun.domains.send(:domain_url, @sample[:domain])
|
59
|
+
|
60
|
+
Mailgun.should_receive(:submit).
|
61
|
+
with(:delete, domains_url).
|
62
|
+
and_return(sample_response)
|
63
|
+
|
64
|
+
@mailgun.domains.delete(@sample[:domain])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailgun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akash Manohar J
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/mailgun/base.rb
|
84
84
|
- lib/mailgun/bounce.rb
|
85
85
|
- lib/mailgun/complaint.rb
|
86
|
+
- lib/mailgun/domain.rb
|
86
87
|
- lib/mailgun/list.rb
|
87
88
|
- lib/mailgun/list/member.rb
|
88
89
|
- lib/mailgun/log.rb
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- spec/base_spec.rb
|
96
97
|
- spec/bounce_spec.rb
|
97
98
|
- spec/complaint_spec.rb
|
99
|
+
- spec/domain_spec.rb
|
98
100
|
- spec/list/member_spec.rb
|
99
101
|
- spec/list/message_spec.rb
|
100
102
|
- spec/list_spec.rb
|
@@ -130,6 +132,7 @@ test_files:
|
|
130
132
|
- spec/base_spec.rb
|
131
133
|
- spec/bounce_spec.rb
|
132
134
|
- spec/complaint_spec.rb
|
135
|
+
- spec/domain_spec.rb
|
133
136
|
- spec/list/member_spec.rb
|
134
137
|
- spec/list/message_spec.rb
|
135
138
|
- spec/list_spec.rb
|