wj-mailgun-ruby 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +22 -0
- data/.ruby-env.yml.example +12 -0
- data/.ruby-version +1 -0
- data/.travis.yml +24 -0
- data/Gemfile +6 -0
- data/LICENSE +191 -0
- data/README.md +241 -0
- data/Rakefile +35 -0
- data/docs/Domains.md +54 -0
- data/docs/Events.md +46 -0
- data/docs/MessageBuilder.md +105 -0
- data/docs/Messages.md +107 -0
- data/docs/OptInHandler.md +103 -0
- data/docs/Snippets.md +526 -0
- data/docs/Suppressions.md +82 -0
- data/docs/Webhooks.md +40 -0
- data/lib/mailgun-ruby.rb +2 -0
- data/lib/mailgun.rb +39 -0
- data/lib/mailgun/address.rb +45 -0
- data/lib/mailgun/chains.rb +16 -0
- data/lib/mailgun/client.rb +199 -0
- data/lib/mailgun/domains/domains.rb +84 -0
- data/lib/mailgun/events/events.rb +120 -0
- data/lib/mailgun/exceptions/exceptions.rb +65 -0
- data/lib/mailgun/lists/opt_in_handler.rb +58 -0
- data/lib/mailgun/messages/batch_message.rb +125 -0
- data/lib/mailgun/messages/message_builder.rb +413 -0
- data/lib/mailgun/response.rb +62 -0
- data/lib/mailgun/suppressions.rb +270 -0
- data/lib/mailgun/version.rb +4 -0
- data/lib/mailgun/webhooks/webhooks.rb +101 -0
- data/lib/railgun.rb +8 -0
- data/lib/railgun/attachment.rb +56 -0
- data/lib/railgun/errors.rb +27 -0
- data/lib/railgun/mailer.rb +161 -0
- data/lib/railgun/message.rb +17 -0
- data/lib/railgun/railtie.rb +9 -0
- data/mailgun.gemspec +37 -0
- data/spec/integration/bounces_spec.rb +44 -0
- data/spec/integration/campaign_spec.rb +60 -0
- data/spec/integration/complaints_spec.rb +38 -0
- data/spec/integration/domains_spec.rb +39 -0
- data/spec/integration/email_validation_spec.rb +57 -0
- data/spec/integration/events_spec.rb +28 -0
- data/spec/integration/list_members_spec.rb +63 -0
- data/spec/integration/list_spec.rb +58 -0
- data/spec/integration/mailgun_spec.rb +121 -0
- data/spec/integration/messages/sample_data/mime.txt +38 -0
- data/spec/integration/routes_spec.rb +74 -0
- data/spec/integration/stats_spec.rb +15 -0
- data/spec/integration/suppressions_spec.rb +126 -0
- data/spec/integration/unsubscribes_spec.rb +42 -0
- data/spec/integration/webhook_spec.rb +54 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/unit/connection/test_client.rb +99 -0
- data/spec/unit/events/events_spec.rb +50 -0
- data/spec/unit/lists/opt_in_handler_spec.rb +24 -0
- data/spec/unit/mailgun_spec.rb +127 -0
- data/spec/unit/messages/batch_message_spec.rb +131 -0
- data/spec/unit/messages/message_builder_spec.rb +584 -0
- data/spec/unit/messages/sample_data/mailgun_icon.png +0 -0
- data/spec/unit/messages/sample_data/mime.txt +38 -0
- data/spec/unit/messages/sample_data/rackspace_logo.jpg +0 -0
- data/vcr_cassettes/bounces.yml +175 -0
- data/vcr_cassettes/complaints.yml +175 -0
- data/vcr_cassettes/domains.todo.yml +42 -0
- data/vcr_cassettes/domains.yml +360 -0
- data/vcr_cassettes/email_validation.yml +167 -0
- data/vcr_cassettes/events.yml +108 -0
- data/vcr_cassettes/exceptions.yml +45 -0
- data/vcr_cassettes/list_members.yml +320 -0
- data/vcr_cassettes/mailing_list.todo.yml +43 -0
- data/vcr_cassettes/mailing_list.yml +390 -0
- data/vcr_cassettes/routes.yml +359 -0
- data/vcr_cassettes/send_message.yml +107 -0
- data/vcr_cassettes/stats.yml +44 -0
- data/vcr_cassettes/suppressions.yml +676 -0
- data/vcr_cassettes/unsubscribes.yml +191 -0
- data/vcr_cassettes/webhooks.yml +276 -0
- metadata +263 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
|
4
|
+
vcr_opts = { :cassette_name => "domains" }
|
5
|
+
|
6
|
+
describe 'For the domains endpoint', vcr: vcr_opts do
|
7
|
+
before(:all) do
|
8
|
+
@mg_client = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
9
|
+
@mg_obj = Mailgun::Domains.new(@mg_client)
|
10
|
+
@domain = "integration-test.domain.invalid"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'creates the domain' do
|
14
|
+
result = @mg_obj.add_domain(@domain, { smtp_password: 'super_secret', spam_action: 'tag' })
|
15
|
+
|
16
|
+
expect(result['domain']["name"]).to eq(@domain)
|
17
|
+
expect(result['domain']["spam_action"]).to eq("tag")
|
18
|
+
expect(result['domain']["smtp_password"]).to eq("super_secret")
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'get the domain.' do
|
22
|
+
result = @mg_obj.get(@domain)
|
23
|
+
|
24
|
+
expect(result).to include("domain")
|
25
|
+
expect(result["domain"]["name"]).to eq(@domain)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'gets a list of domains.' do
|
29
|
+
result = @mg_obj.get_domains
|
30
|
+
|
31
|
+
expect(result.size).to be > 0
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'deletes a domain.' do
|
35
|
+
result = @mg_obj.delete(@domain)
|
36
|
+
|
37
|
+
expect(result).to be_truthy
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'mailgun'
|
4
|
+
require 'mailgun/address'
|
5
|
+
|
6
|
+
vcr_opts = { :cassette_name => "email_validation" }
|
7
|
+
|
8
|
+
describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do
|
9
|
+
before(:all) do
|
10
|
+
@mg_obj = Mailgun::Address.new(PUB_APIKEY)
|
11
|
+
|
12
|
+
@valid = ["Alice <alice@example.com>", "bob@example.com"]
|
13
|
+
@invalid = ["example.org"]
|
14
|
+
|
15
|
+
@all_addrs = @valid + @invalid
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns parsed and unparsable lists' do
|
19
|
+
res = @mg_obj.parse(@all_addrs)
|
20
|
+
|
21
|
+
expect(res["parsed"]).to eq(@valid)
|
22
|
+
expect(res["unparseable"]).to eq(@invalid)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'validates alice@mailgun.net with info' do
|
26
|
+
res = @mg_obj.validate("alice@mailgun.net")
|
27
|
+
|
28
|
+
expected = {
|
29
|
+
"address" => "alice@mailgun.net",
|
30
|
+
"did_you_mean" => nil,
|
31
|
+
"is_valid" => true,
|
32
|
+
"parts" => {
|
33
|
+
"display_name" => nil,
|
34
|
+
"domain" => "mailgun.net",
|
35
|
+
"local_part" => "alice",
|
36
|
+
},
|
37
|
+
}
|
38
|
+
expect(res).to eq(expected)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'fails to validate example.org' do
|
42
|
+
res = @mg_obj.validate("example.org")
|
43
|
+
|
44
|
+
expected = {
|
45
|
+
"address" => "example.org",
|
46
|
+
"did_you_mean" => nil,
|
47
|
+
"is_valid" => false,
|
48
|
+
"parts" => {
|
49
|
+
"display_name" => nil,
|
50
|
+
"domain" => nil,
|
51
|
+
"local_part" => nil,
|
52
|
+
},
|
53
|
+
}
|
54
|
+
expect(res).to eq(expected)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
require 'mailgun/events/events'
|
4
|
+
|
5
|
+
vcr_opts = { :cassette_name => "events" }
|
6
|
+
|
7
|
+
describe 'For the Events endpoint', vcr: vcr_opts do
|
8
|
+
before(:all) do
|
9
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
10
|
+
@domain = TESTDOMAIN
|
11
|
+
@events = Mailgun::Events.new(@mg_obj, @domain)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'can get an event.' do
|
15
|
+
result = @mg_obj.get("#{@domain}/events", {:limit => 1})
|
16
|
+
|
17
|
+
result.to_h!
|
18
|
+
expect(result.body["items"].length).to be_within(1).of(1)
|
19
|
+
expect(result.body["paging"]).to include("next")
|
20
|
+
expect(result.body["paging"]).to include("previous")
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'can iterate over all events with `each`' do
|
24
|
+
@events.each do |e|
|
25
|
+
expect(e.id).to eq("JAx9z641TuGGUyaJlD9sCQ")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
|
4
|
+
vcr_opts = { :cassette_name => "list_members" }
|
5
|
+
|
6
|
+
describe 'For the Mailing Lists Members endpoint', order: :defined, vcr: vcr_opts do
|
7
|
+
before(:all) do
|
8
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
9
|
+
@domain = TESTDOMAIN
|
10
|
+
@ml_address = "integration_test_list@#{@domain}"
|
11
|
+
@ml_member = "integration_test_member_member@#{@domain}"
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates a list' do
|
15
|
+
result = @mg_obj.post("lists", {:address => @ml_address,
|
16
|
+
:name => 'Integration Test List',
|
17
|
+
:description => 'This list should be deleted automatically.',
|
18
|
+
:access_level => 'members'})
|
19
|
+
result.to_h!
|
20
|
+
expect(result.body["message"]).to eq("Mailing list has been created")
|
21
|
+
expect(result.body["list"]["address"]).to eq(@ml_address)
|
22
|
+
expect(result.body["list"]["name"]).to eq('Integration Test List')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'adds a list member' do
|
26
|
+
result = @mg_obj.post("lists/#{@ml_address}/members",
|
27
|
+
{:address => @ml_member,
|
28
|
+
:name => 'Jane Doe',
|
29
|
+
:subscribed => true,
|
30
|
+
:upsert => 'no'})
|
31
|
+
|
32
|
+
result.to_h!
|
33
|
+
expect(result.body["message"]).to eq("Mailing list member has been created")
|
34
|
+
expect(result.body["member"]["address"]).to eq(@ml_member)
|
35
|
+
expect(result.body["member"]["name"]).to eq('Jane Doe')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'gets a list member.' do
|
39
|
+
result = @mg_obj.get("lists/#{@ml_address}/members/#{@ml_member}")
|
40
|
+
|
41
|
+
result.to_h!
|
42
|
+
expect(result.body["member"]["address"]).to eq(@ml_member)
|
43
|
+
expect(result.body["member"]["name"]).to eq('Jane Doe')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'updates a list member.' do
|
47
|
+
result = @mg_obj.put("lists/#{@ml_address}/members/#{@ml_member}",
|
48
|
+
{:name => 'Jane Doe Update',
|
49
|
+
:subscribed => false})
|
50
|
+
|
51
|
+
result.to_h!
|
52
|
+
expect(result.body["message"]).to eq("Mailing list member has been updated")
|
53
|
+
expect(result.body["member"]["address"]).to eq(@ml_member)
|
54
|
+
expect(result.body["member"]["name"]).to eq('Jane Doe Update')
|
55
|
+
expect(result.body["member"]["subscribed"]).to eq(false)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'removes a list member' do
|
59
|
+
@mg_obj.delete("lists/#{@ml_address}/members/#{@ml_member}")
|
60
|
+
@mg_obj.delete("lists/#{@ml_address}")
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
|
4
|
+
vcr_opts = { :cassette_name => "mailing_list" }
|
5
|
+
|
6
|
+
describe 'For the Mailing Lists endpoint', vcr: vcr_opts do
|
7
|
+
before(:all) do
|
8
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
9
|
+
@domain = TESTDOMAIN
|
10
|
+
@ml_address = "integration_test_list@#{@domain}"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'creates a list' do
|
14
|
+
result = @mg_obj.post("lists", {:address => @ml_address,
|
15
|
+
:name => 'Integration Test List',
|
16
|
+
:description => 'This list should be deleted automatically.',
|
17
|
+
:access_level => 'members'})
|
18
|
+
|
19
|
+
result.to_h!
|
20
|
+
expect(result.body["message"]).to eq("Mailing list has been created")
|
21
|
+
expect(result.body["list"]["address"]).to eq(@ml_address)
|
22
|
+
expect(result.body["list"]["name"]).to eq('Integration Test List')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'gets a list.' do
|
26
|
+
result = @mg_obj.get("lists/#{@ml_address}")
|
27
|
+
|
28
|
+
result.to_h!
|
29
|
+
expect(result.body["list"]["address"]).to eq(@ml_address)
|
30
|
+
expect(result.body["list"]["name"]).to eq('Integration Test List')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'gets a list of all lists.' do
|
34
|
+
result = @mg_obj.get("lists", {:limit => 50})
|
35
|
+
|
36
|
+
result.to_h!
|
37
|
+
expect(result.body["total_count"]).to be > 0
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'updates a list.' do
|
41
|
+
result = @mg_obj.put("lists/#{@ml_address}",
|
42
|
+
{:address => @ml_address,
|
43
|
+
:name => 'Integration Test List Update',
|
44
|
+
:description => 'This list should be deleted automatically.',
|
45
|
+
:access_level => 'readonly'})
|
46
|
+
|
47
|
+
result.to_h!
|
48
|
+
expect(result.body["message"]).to eq("Mailing list has been updated")
|
49
|
+
expect(result.body["list"]["address"]).to eq(@ml_address)
|
50
|
+
expect(result.body["list"]["name"]).to eq('Integration Test List Update')
|
51
|
+
expect(result.body["list"]["access_level"]).to eq('readonly')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'deletes a list' do
|
55
|
+
@mg_obj.delete("lists/#{@ml_address}")
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
require 'mailgun/exceptions/exceptions'
|
4
|
+
|
5
|
+
vcr_opts = { :cassette_name => "instance" }
|
6
|
+
|
7
|
+
describe 'Mailgun instantiation', vcr: vcr_opts do
|
8
|
+
it 'instantiates an HttpClient object' do
|
9
|
+
expect {@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)}.not_to raise_error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
vcr_opts = { :cassette_name => "exceptions" }
|
14
|
+
|
15
|
+
describe 'Client exceptions', vcr: vcr_opts do
|
16
|
+
before(:all) do
|
17
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
18
|
+
@domain = TESTDOMAIN
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'display useful error information' do
|
22
|
+
begin
|
23
|
+
@mg_obj.send_message("not-our-doma.in", {
|
24
|
+
:from => "sally@not-our-doma.in",
|
25
|
+
:to => "bob@#{@domain}",
|
26
|
+
:subject => 'Exception Integration Test',
|
27
|
+
:text => 'INTEGRATION TESTING'
|
28
|
+
})
|
29
|
+
rescue Mailgun::CommunicationError => err
|
30
|
+
expect(err.message).to eq('404 Not Found: Domain not found: not-our-doma.in')
|
31
|
+
else
|
32
|
+
fail
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
vcr_opts = { :cassette_name => "send_message" }
|
38
|
+
|
39
|
+
describe 'The method send_message()', vcr: vcr_opts do
|
40
|
+
before(:all) do
|
41
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
42
|
+
@domain = TESTDOMAIN
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'sends a standard message in test mode.' do
|
46
|
+
result = @mg_obj.send_message(@domain, {:from => "bob@#{@domain}",
|
47
|
+
:to => "sally@#{@domain}",
|
48
|
+
:subject => 'Hash Integration Test',
|
49
|
+
:text => 'INTEGRATION TESTING',
|
50
|
+
'o:testmode' => true}
|
51
|
+
)
|
52
|
+
result.to_h!
|
53
|
+
expect(result.body).to include("message")
|
54
|
+
expect(result.body).to include("id")
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'fakes message send while in *client* test mode' do
|
58
|
+
@mg_obj.enable_test_mode!
|
59
|
+
|
60
|
+
expect(@mg_obj.test_mode?).to eq(true)
|
61
|
+
|
62
|
+
data = { :from => "joe@#{@domain}",
|
63
|
+
:to => "bob@#{@domain}",
|
64
|
+
:subject => "Test",
|
65
|
+
:text => "Test Data" }
|
66
|
+
|
67
|
+
result = @mg_obj.send_message(@domain, data)
|
68
|
+
|
69
|
+
result.to_h!
|
70
|
+
|
71
|
+
expect(result.body).to include("message")
|
72
|
+
expect(result.body).to include("id")
|
73
|
+
|
74
|
+
expect(result.code).to eq(200)
|
75
|
+
expect(result.body['id']).to eq("test-mode-mail@localhost")
|
76
|
+
expect(result.body['message']).to eq("Queued. Thank you.")
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'sends a message builder message in test mode.' do
|
80
|
+
mb_obj = Mailgun::MessageBuilder.new()
|
81
|
+
mb_obj.from("sender@#{@domain}", {'first' => 'Sending', 'last' => 'User'})
|
82
|
+
mb_obj.add_recipient(:to, "recipient@#{@domain}", {'first' => 'Recipient', 'last' => 'User'})
|
83
|
+
mb_obj.subject("Message Builder Integration Test")
|
84
|
+
mb_obj.body_text("This is the text body.")
|
85
|
+
mb_obj.test_mode(true)
|
86
|
+
|
87
|
+
result = @mg_obj.send_message(@domain, mb_obj)
|
88
|
+
|
89
|
+
result.to_h!
|
90
|
+
expect(result.body).to include("message")
|
91
|
+
expect(result.body).to include("id")
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'sends a custom MIME message in test mode.' do
|
95
|
+
mime_string = 'Delivered-To: mgbox01@gmail.com
|
96
|
+
Received: by luna.mailgun.net with HTTP; Tue, 26 Nov 2013 17:59:11 +0000
|
97
|
+
Mime-Version: 1.0
|
98
|
+
Content-Type: text/plain; charset="ascii"
|
99
|
+
Subject: Hello
|
100
|
+
From: Excited User <me@samples.mailgun.org>
|
101
|
+
To: sally@example.com
|
102
|
+
Message-Id: <20131126175911.25310.92289@samples.mailgun.org>
|
103
|
+
Content-Transfer-Encoding: 7bit
|
104
|
+
X-Mailgun-Sid: WyI2NTU4MSIsICJtZ2JveDAxQGdtYWlsLmNvbSIsICIxZmYiXQ==
|
105
|
+
Date: Tue, 26 Nov 2013 17:59:22 +0000
|
106
|
+
X-Mailgun-Drop-Message: yes
|
107
|
+
Sender: me@samples.mailgun.org
|
108
|
+
|
109
|
+
Testing some Mailgun awesomness!'
|
110
|
+
|
111
|
+
message_params = {:to => "sally@#{@domain}",
|
112
|
+
:message => mime_string}
|
113
|
+
|
114
|
+
result = @mg_obj.send_message(@domain, message_params)
|
115
|
+
|
116
|
+
result.to_h!
|
117
|
+
expect(result.body).to include("message")
|
118
|
+
expect(result.body).to include("id")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
X-SBRS: 5.6
|
2
|
+
X-SenderGroup: WHITELIST
|
3
|
+
X-MailFlowPolicy: $TRUSTED
|
4
|
+
DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=trstx.com; q=dns/txt; s=mx;
|
5
|
+
t=1381182797; h=Mime-Version: Content-Type: Subject: From: To:
|
6
|
+
Message-Id: Date: Sender: Content-Transfer-Encoding;
|
7
|
+
bh=r6P1omjKL3m7gDuZC6dZEJU6trgWm1IRwAJb8h4wtfg=; b=UPFaFGiuDx2yZjCmiMEji0fIXvGMNwXUsuaX4Ss9p5EUkqE25eYjeJaJZ5w5FK+t0jsUPZqu
|
8
|
+
FIH6sftQv7GBEbSktY6sv7dgv5q2yVlY8YNG7CXvUZdWmvwfQVvfL9j1RHJo9H3QpXT9c8bZ
|
9
|
+
p9rpYmqZtZEz2ZesPj4kzUaB0lU=
|
10
|
+
DomainKey-Signature: a=rsa-sha1; c=nofws; d=trstx.com; s=mx; q=dns;
|
11
|
+
h=Mime-Version: Content-Type: Subject: From: To: Message-Id: Date:
|
12
|
+
Sender: Content-Transfer-Encoding;
|
13
|
+
b=QUYQf9OP16DphNAjeF95+G7V6DaqL4FA+m1sjIEWHdLzrGTQkiYTpzJdne3lzSypB0DwaG
|
14
|
+
AT9zOhjjN64DWFOkJD2Ce5t6vfHa/GC3FCUMq3xz/Big94g+kOciawkHyUhCrmPyh/D7kWx1
|
15
|
+
J75UIAdmE9XQ9bCSPhZ2MRaOv7b8c=
|
16
|
+
Received: by luna.mailgun.net with HTTP; Mon, 07 Oct 2013 21:53:16 +0000
|
17
|
+
Content-Type: text/plain; charset="ascii"
|
18
|
+
Subject: Test Subject
|
19
|
+
From: <joe@example.com>
|
20
|
+
To: <bob@sample.com>
|
21
|
+
Message-ID: <20131007215316.27052.7818@example.com>
|
22
|
+
X-Mailgun-Sid: WyI4MzY1OSIsICJ0cmF2aXMuc3dpZW50ZWtAcmFja3NwYWasdfewNvbSIsICJjZjQ4Il0=
|
23
|
+
Date: Mon, 7 Oct 2013 21:53:17 +0000
|
24
|
+
Sender: <joe@example.com>
|
25
|
+
Content-Transfer-Encoding: 7bit
|
26
|
+
MIME-Version: 1.0
|
27
|
+
|
28
|
+
--3a8c26e9f23c4ac193606295aa17fa6f
|
29
|
+
Content-Type: text/plain; charset="ascii"
|
30
|
+
Content-Transfer-Encoding: 7bit
|
31
|
+
|
32
|
+
Testing some Mailgun awesomness!
|
33
|
+
--3a8c26e9f23c4ac193606295aa17fa6f
|
34
|
+
Content-Type: text/html; charset="ascii"
|
35
|
+
Content-Transfer-Encoding: 7bit
|
36
|
+
|
37
|
+
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">Test
|
38
|
+
--3a8c26e9f23c4ac193606295aa17fa6f--
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
|
4
|
+
vcr_opts = { :cassette_name => "routes" }
|
5
|
+
|
6
|
+
describe 'For the Routes endpoint', order: :defined, vcr: vcr_opts do
|
7
|
+
before(:all) do
|
8
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
9
|
+
@domain = TESTDOMAIN
|
10
|
+
@forward_to = "alice@#{@domain}"
|
11
|
+
@recipient = ".*@#{@domain}"
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates a route' do
|
15
|
+
result = @mg_obj.post("routes", { priority: 10,
|
16
|
+
description: 'Integration Test Route',
|
17
|
+
expression: "match_recipient(\"#{@forward_to}\")",
|
18
|
+
action: "forward(\"#{@recipient}\")" })
|
19
|
+
|
20
|
+
result.to_h!
|
21
|
+
expect(result.body["message"]).to eq("Route has been created")
|
22
|
+
expect(result.body["route"]["description"]).to eq("Integration Test Route")
|
23
|
+
expect(result.body["route"]["actions"]).to include("forward(\"#{@recipient}\")")
|
24
|
+
expect(result.body["route"]["expression"]).to include("match_recipient(\"#{@forward_to}\")")
|
25
|
+
expect(result.body["route"]["priority"]).to eq(10)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'gets a list of all routes.' do
|
29
|
+
result = @mg_obj.get("routes", {:limit => 50})
|
30
|
+
|
31
|
+
result.to_h!
|
32
|
+
expect(result.body["total_count"]).to be > 0
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'gets the route.' do
|
36
|
+
result = @mg_obj.get("routes", {:limit => 1})
|
37
|
+
route_id = result.to_h['items'].first['id']
|
38
|
+
|
39
|
+
result = @mg_obj.get("routes/#{route_id}")
|
40
|
+
|
41
|
+
result.to_h!
|
42
|
+
expect(result.body["route"]["description"]).to eq("Integration Test Route")
|
43
|
+
expect(result.body["route"]["actions"]).to include("forward(\"#{@recipient}\")")
|
44
|
+
expect(result.body["route"]["expression"]).to include("match_recipient(\"#{@forward_to}\")")
|
45
|
+
expect(result.body["route"]["priority"]).to eq(10)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'updates the route.' do
|
49
|
+
result = @mg_obj.get("routes", {:limit => 1})
|
50
|
+
route_id = result.to_h['items'].first['id']
|
51
|
+
|
52
|
+
result = @mg_obj.put("routes/#{route_id}", {:priority => 10,
|
53
|
+
:description => 'Integration Test Route Update',
|
54
|
+
:expression => "match_recipient(\"#{@forward_to}\")",
|
55
|
+
:action => "forward(\"#{@recipient}\")"})
|
56
|
+
|
57
|
+
result.to_h!
|
58
|
+
expect(result.body["message"]).to eq("Route has been updated")
|
59
|
+
expect(result.body["description"]).to eq("Integration Test Route Update")
|
60
|
+
expect(result.body["actions"]).to include("forward(\"#{@recipient}\")")
|
61
|
+
expect(result.body["expression"]).to include("match_recipient(\"#{@forward_to}\")")
|
62
|
+
expect(result.body["priority"]).to eq(10)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'removes a route' do
|
66
|
+
result = @mg_obj.get("routes", {:limit => 1})
|
67
|
+
route_id = result.to_h['items'].first['id']
|
68
|
+
|
69
|
+
@mg_obj.delete("routes/#{route_id}")
|
70
|
+
|
71
|
+
result.to_h!
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|