mailgun-ruby 1.4.1 → 1.4.3
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 +4 -4
- data/.github/workflows/ci.yml +30 -8
- data/.rubocop.yml +64 -4
- data/Gemfile +3 -1
- data/README.md +1 -1
- data/Rakefile +5 -8
- data/docs/AnalyticsTags.md +63 -0
- data/lib/mailgun/address.rb +5 -5
- data/lib/mailgun/chains.rb +2 -3
- data/lib/mailgun/client.rb +56 -56
- data/lib/mailgun/domains/domains.rb +11 -10
- data/lib/mailgun/events/events.rb +4 -3
- data/lib/mailgun/exceptions/exceptions.rb +12 -15
- data/lib/mailgun/helpers/api_version_checker.rb +6 -1
- data/lib/mailgun/lists/opt_in_handler.rb +6 -10
- data/lib/mailgun/logs/logs.rb +4 -2
- data/lib/mailgun/messages/batch_message.rb +10 -10
- data/lib/mailgun/messages/message_builder.rb +40 -56
- data/lib/mailgun/metrics/metrics.rb +12 -6
- data/lib/mailgun/response.rb +12 -10
- data/lib/mailgun/subaccounts/subaccounts.rb +13 -8
- data/lib/mailgun/suppressions.rb +36 -43
- data/lib/mailgun/tags/analytics_tags.rb +37 -2
- data/lib/mailgun/tags/tags.rb +29 -19
- data/lib/mailgun/templates/templates.rb +40 -29
- data/lib/mailgun/version.rb +3 -1
- data/lib/mailgun/webhooks/webhooks.rb +22 -19
- data/lib/mailgun-ruby.rb +2 -0
- data/lib/mailgun.rb +4 -4
- data/lib/railgun/attachment.rb +12 -19
- data/lib/railgun/errors.rb +2 -3
- data/lib/railgun/mailer.rb +37 -41
- data/lib/railgun/railtie.rb +2 -0
- data/lib/railgun.rb +2 -0
- data/mailgun.gemspec +15 -11
- data/spec/integration/analytics_tags_spec.rb +54 -0
- data/spec/integration/bounces_spec.rb +12 -11
- data/spec/integration/campaign_spec.rb +20 -18
- data/spec/integration/complaints_spec.rb +8 -6
- data/spec/integration/domains_spec.rb +12 -18
- data/spec/integration/email_validation_spec.rb +35 -34
- data/spec/integration/events_spec.rb +8 -8
- data/spec/integration/list_members_spec.rb +27 -26
- data/spec/integration/list_spec.rb +22 -21
- data/spec/integration/logs_spec.rb +49 -47
- data/spec/integration/mailer_spec.rb +7 -3
- data/spec/integration/mailgun_spec.rb +85 -92
- data/spec/integration/metrics_spec.rb +137 -131
- data/spec/integration/routes_spec.rb +41 -40
- data/spec/integration/stats_spec.rb +4 -2
- data/spec/integration/subaccounts_spec.rb +9 -10
- data/spec/integration/suppressions_spec.rb +222 -44
- data/spec/integration/templates_spec.rb +14 -12
- data/spec/integration/unsubscribes_spec.rb +8 -6
- data/spec/integration/webhook_spec.rb +18 -12
- data/spec/spec_helper.rb +15 -8
- data/spec/unit/client_spec.rb +424 -0
- data/spec/unit/connection/test_client.rb +108 -55
- data/spec/unit/events/events_spec.rb +48 -29
- data/spec/unit/exceptions/exceptions_spec.rb +8 -7
- data/spec/unit/helpers/api_version_checker_spec.rb +206 -0
- data/spec/unit/lists/opt_in_handler_spec.rb +11 -7
- data/spec/unit/mailgun_spec.rb +71 -68
- data/spec/unit/messages/batch_message_spec.rb +37 -36
- data/spec/unit/messages/message_builder_spec.rb +170 -169
- data/spec/unit/railgun/content_type_spec.rb +31 -30
- data/spec/unit/railgun/mailer_spec.rb +62 -59
- data/spec/unit/response_spec.rb +225 -0
- data/vcr_cassettes/For_the_suppressions_handling_class/creates_a_single_bounce.yml +55 -0
- data/vcr_cassettes/analytics_tags.yml +187 -0
- data/vcr_cassettes/suppressions.yml +1053 -170
- metadata +95 -29
- data/.rubocop_todo.yml +0 -22
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'mailgun'
|
|
3
5
|
|
|
4
|
-
vcr_opts = { :
|
|
6
|
+
vcr_opts = { cassette_name: 'domains' }
|
|
5
7
|
|
|
6
8
|
describe 'For the domains endpoint', vcr: vcr_opts do
|
|
7
9
|
let(:api_version) { APIVERSION }
|
|
@@ -42,7 +44,7 @@ describe 'For the domains endpoint', vcr: vcr_opts do
|
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
describe '#update' do
|
|
46
48
|
let(:api_version) { 'v4' }
|
|
47
49
|
|
|
48
50
|
it 'updates the domain' do
|
|
@@ -50,11 +52,11 @@ describe 'For the domains endpoint', vcr: vcr_opts do
|
|
|
50
52
|
|
|
51
53
|
expect(response['domain']['spam_action']).to eq('block')
|
|
52
54
|
expect(response['domain']['web_scheme']).to eq('https')
|
|
53
|
-
expect(response['domain']['wildcard']).to
|
|
55
|
+
expect(response['domain']['wildcard']).to be(true)
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
describe '#verify' do
|
|
58
60
|
let(:api_version) { 'v4' }
|
|
59
61
|
|
|
60
62
|
it 'verifies the domain' do
|
|
@@ -71,7 +73,6 @@ describe 'For the domains endpoint', vcr: vcr_opts do
|
|
|
71
73
|
end
|
|
72
74
|
end
|
|
73
75
|
|
|
74
|
-
|
|
75
76
|
context 'Domain::Keys methods' do
|
|
76
77
|
describe '#list_domain_keys' do
|
|
77
78
|
let(:api_version) { 'v1' }
|
|
@@ -123,7 +124,6 @@ describe 'For the domains endpoint', vcr: vcr_opts do
|
|
|
123
124
|
let(:api_version) { 'v4' }
|
|
124
125
|
|
|
125
126
|
it 'activates a domain key' do
|
|
126
|
-
|
|
127
127
|
result = mg_obj.activate_domain_key(
|
|
128
128
|
domain,
|
|
129
129
|
'mailo1'
|
|
@@ -187,7 +187,7 @@ describe 'For the domains endpoint', vcr: vcr_opts do
|
|
|
187
187
|
end
|
|
188
188
|
|
|
189
189
|
context 'Domain::Tracking methods' do
|
|
190
|
-
# TODO add missing:
|
|
190
|
+
# TODO: add missing:
|
|
191
191
|
# get_domain_tracking_certificate
|
|
192
192
|
# regenerate_domain_tracking_certificate
|
|
193
193
|
# generate_domain_tracking_certificate
|
|
@@ -199,7 +199,7 @@ describe 'For the domains endpoint', vcr: vcr_opts do
|
|
|
199
199
|
)
|
|
200
200
|
|
|
201
201
|
expect(result).to include('tracking')
|
|
202
|
-
expect(result['tracking']['click']['active']).to
|
|
202
|
+
expect(result['tracking']['click']['active']).to be(false)
|
|
203
203
|
end
|
|
204
204
|
end
|
|
205
205
|
|
|
@@ -212,7 +212,7 @@ describe 'For the domains endpoint', vcr: vcr_opts do
|
|
|
212
212
|
}
|
|
213
213
|
)
|
|
214
214
|
|
|
215
|
-
expect(result['click']['active']).to
|
|
215
|
+
expect(result['click']['active']).to be(false)
|
|
216
216
|
end
|
|
217
217
|
end
|
|
218
218
|
|
|
@@ -225,7 +225,7 @@ describe 'For the domains endpoint', vcr: vcr_opts do
|
|
|
225
225
|
}
|
|
226
226
|
)
|
|
227
227
|
|
|
228
|
-
expect(result['open']['active']).to
|
|
228
|
+
expect(result['open']['active']).to be(false)
|
|
229
229
|
end
|
|
230
230
|
end
|
|
231
231
|
|
|
@@ -238,17 +238,11 @@ describe 'For the domains endpoint', vcr: vcr_opts do
|
|
|
238
238
|
}
|
|
239
239
|
)
|
|
240
240
|
|
|
241
|
-
expect(result['unsubscribe']['active']).to
|
|
241
|
+
expect(result['unsubscribe']['active']).to be(false)
|
|
242
242
|
end
|
|
243
243
|
end
|
|
244
244
|
end
|
|
245
245
|
|
|
246
|
-
context 'Domain::DKIM_Security methods' do
|
|
247
|
-
# TODO add missing:
|
|
248
|
-
# dkim_rotation
|
|
249
|
-
# dkim_rotate
|
|
250
|
-
end
|
|
251
|
-
|
|
252
246
|
context 'Credentials methods' do
|
|
253
247
|
# TODO: to be moved to the dedicated module
|
|
254
248
|
|
|
@@ -261,7 +255,7 @@ describe 'For the domains endpoint', vcr: vcr_opts do
|
|
|
261
255
|
}
|
|
262
256
|
)
|
|
263
257
|
|
|
264
|
-
expect(result['message']).to eq(
|
|
258
|
+
expect(result['message']).to eq('Created 1 credentials pair(s)')
|
|
265
259
|
end
|
|
266
260
|
end
|
|
267
261
|
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
require 'mailgun'
|
|
4
6
|
require 'mailgun/address'
|
|
5
7
|
|
|
6
|
-
vcr_opts = { :
|
|
8
|
+
vcr_opts = { cassette_name: 'email_validation' }
|
|
7
9
|
|
|
8
10
|
describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do
|
|
9
11
|
before(:all) do
|
|
10
12
|
@mg_obj = Mailgun::Address.new
|
|
11
13
|
|
|
12
|
-
@valid = [
|
|
13
|
-
@invalid = [
|
|
14
|
+
@valid = ['Alice <alice@example.com>', 'bob@example.com']
|
|
15
|
+
@invalid = ['example.org']
|
|
14
16
|
|
|
15
17
|
@all_addrs = @valid + @invalid
|
|
16
18
|
end
|
|
@@ -19,54 +21,53 @@ describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do
|
|
|
19
21
|
skip 'is parse method removed?'
|
|
20
22
|
res = @mg_obj.parse(@all_addrs)
|
|
21
23
|
|
|
22
|
-
expect(res[
|
|
23
|
-
expect(res[
|
|
24
|
+
expect(res['parsed']).to eq(@valid)
|
|
25
|
+
expect(res['unparsable']).to eq(@invalid)
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
it 'validates alice@mailgun.net with info' do
|
|
27
|
-
res = @mg_obj.validate(
|
|
29
|
+
res = @mg_obj.validate('alice@mailgun.net')
|
|
28
30
|
|
|
29
31
|
expected = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
'address' => 'alice@mailgun.net',
|
|
33
|
+
'did_you_mean' => nil,
|
|
34
|
+
'is_disposable_address' => false,
|
|
35
|
+
'is_role_address' => false,
|
|
36
|
+
'is_valid' => true,
|
|
37
|
+
'mailbox_verification' => 'true',
|
|
38
|
+
'reason' => nil,
|
|
39
|
+
'parts' => {
|
|
40
|
+
'display_name' => nil,
|
|
41
|
+
'domain' => 'mailgun.net',
|
|
42
|
+
'local_part' => 'alice'
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
expect(res).to eq(expected)
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
it 'performs mailbox validation for alice@mailgun.net' do
|
|
47
|
-
res = @mg_obj.validate(
|
|
49
|
+
res = @mg_obj.validate('alice@mailgun.net', true)
|
|
48
50
|
|
|
49
|
-
expect(res[
|
|
51
|
+
expect(res['mailbox_verification']).to eq('true')
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
it 'fails to validate example.org' do
|
|
53
|
-
res = @mg_obj.validate(
|
|
55
|
+
res = @mg_obj.validate('example.org')
|
|
54
56
|
|
|
55
57
|
expected = {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
'address' => 'example.org',
|
|
59
|
+
'did_you_mean' => nil,
|
|
60
|
+
'is_disposable_address' => false,
|
|
61
|
+
'is_role_address' => false,
|
|
62
|
+
'is_valid' => false,
|
|
63
|
+
'mailbox_verification' => 'unknown',
|
|
64
|
+
# "reason" => "Validation failed for 'example.org', reason: 'malformed address; missing @ sign'",
|
|
65
|
+
'parts' => {
|
|
66
|
+
'display_name' => nil,
|
|
67
|
+
'domain' => nil,
|
|
68
|
+
'local_part' => nil
|
|
69
|
+
}
|
|
68
70
|
}
|
|
69
71
|
expect(res).to eq(expected)
|
|
70
72
|
end
|
|
71
|
-
|
|
72
73
|
end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'mailgun'
|
|
3
5
|
require 'mailgun/events/events'
|
|
4
6
|
|
|
5
|
-
vcr_opts = { :
|
|
7
|
+
vcr_opts = { cassette_name: 'events' }
|
|
6
8
|
|
|
7
9
|
describe 'For the Events endpoint', vcr: vcr_opts do
|
|
8
10
|
before(:all) do
|
|
@@ -12,17 +14,15 @@ describe 'For the Events endpoint', vcr: vcr_opts do
|
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
it 'can get an event.' do
|
|
15
|
-
result = @mg_obj.get("#{@domain}/events", {:
|
|
17
|
+
result = @mg_obj.get("#{@domain}/events", { limit: 1 })
|
|
16
18
|
|
|
17
19
|
result.to_h!
|
|
18
|
-
expect(result.body[
|
|
19
|
-
expect(result.body[
|
|
20
|
-
expect(result.body[
|
|
20
|
+
expect(result.body['items'].length).to be_within(1).of(1)
|
|
21
|
+
expect(result.body['paging']).to include('next')
|
|
22
|
+
expect(result.body['paging']).to include('previous')
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
it 'can iterate over all events with `each`' do
|
|
24
|
-
@events.
|
|
25
|
-
expect(e).to have_key('event')
|
|
26
|
-
end
|
|
26
|
+
expect(@events).to all(have_key('event'))
|
|
27
27
|
end
|
|
28
28
|
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'mailgun'
|
|
3
5
|
|
|
4
|
-
vcr_opts = { :
|
|
6
|
+
vcr_opts = { cassette_name: 'list_members' }
|
|
5
7
|
|
|
6
8
|
describe 'For the Mailing Lists Members endpoint', order: :defined, vcr: vcr_opts do
|
|
7
9
|
before(:all) do
|
|
@@ -10,54 +12,53 @@ describe 'For the Mailing Lists Members endpoint', order: :defined, vcr: vcr_opt
|
|
|
10
12
|
@ml_address = "integration_test_list@#{@domain}"
|
|
11
13
|
@ml_member = "integration_test_member_member@#{@domain}"
|
|
12
14
|
end
|
|
13
|
-
|
|
15
|
+
|
|
14
16
|
it 'creates a list' do
|
|
15
|
-
result = @mg_obj.post(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
result = @mg_obj.post('lists', { address: @ml_address,
|
|
18
|
+
name: 'Integration Test List',
|
|
19
|
+
description: 'This list should be deleted automatically.',
|
|
20
|
+
access_level: 'members' })
|
|
19
21
|
result.to_h!
|
|
20
|
-
expect(result.body[
|
|
21
|
-
expect(result.body[
|
|
22
|
-
expect(result.body[
|
|
22
|
+
expect(result.body['message']).to eq('Mailing list has been created')
|
|
23
|
+
expect(result.body['list']['address']).to eq(@ml_address)
|
|
24
|
+
expect(result.body['list']['name']).to eq('Integration Test List')
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
it 'adds a list member' do
|
|
26
28
|
result = @mg_obj.post("lists/#{@ml_address}/members",
|
|
27
|
-
{:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
{ address: @ml_member,
|
|
30
|
+
name: 'Jane Doe',
|
|
31
|
+
subscribed: true,
|
|
32
|
+
upsert: 'no' })
|
|
31
33
|
|
|
32
34
|
result.to_h!
|
|
33
|
-
expect(result.body[
|
|
34
|
-
expect(result.body[
|
|
35
|
-
expect(result.body[
|
|
35
|
+
expect(result.body['message']).to eq('Mailing list member has been created')
|
|
36
|
+
expect(result.body['member']['address']).to eq(@ml_member)
|
|
37
|
+
expect(result.body['member']['name']).to eq('Jane Doe')
|
|
36
38
|
end
|
|
37
|
-
|
|
39
|
+
|
|
38
40
|
it 'gets a list member.' do
|
|
39
41
|
result = @mg_obj.get("lists/#{@ml_address}/members/#{@ml_member}")
|
|
40
42
|
|
|
41
43
|
result.to_h!
|
|
42
|
-
expect(result.body[
|
|
43
|
-
expect(result.body[
|
|
44
|
+
expect(result.body['member']['address']).to eq(@ml_member)
|
|
45
|
+
expect(result.body['member']['name']).to eq('Jane Doe')
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
it 'updates a list member.' do
|
|
47
49
|
result = @mg_obj.put("lists/#{@ml_address}/members/#{@ml_member}",
|
|
48
|
-
{:
|
|
49
|
-
|
|
50
|
+
{ name: 'Jane Doe Update',
|
|
51
|
+
subscribed: false })
|
|
50
52
|
|
|
51
53
|
result.to_h!
|
|
52
|
-
expect(result.body[
|
|
53
|
-
expect(result.body[
|
|
54
|
-
expect(result.body[
|
|
55
|
-
expect(result.body[
|
|
54
|
+
expect(result.body['message']).to eq('Mailing list member has been updated')
|
|
55
|
+
expect(result.body['member']['address']).to eq(@ml_member)
|
|
56
|
+
expect(result.body['member']['name']).to eq('Jane Doe Update')
|
|
57
|
+
expect(result.body['member']['subscribed']).to be(false)
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
it 'removes a list member' do
|
|
59
61
|
@mg_obj.delete("lists/#{@ml_address}/members/#{@ml_member}")
|
|
60
62
|
@mg_obj.delete("lists/#{@ml_address}")
|
|
61
63
|
end
|
|
62
|
-
|
|
63
64
|
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'mailgun'
|
|
3
5
|
|
|
4
|
-
vcr_opts = { :
|
|
6
|
+
vcr_opts = { cassette_name: 'mailing_list' }
|
|
5
7
|
|
|
6
8
|
describe 'For the Mailing Lists endpoint', vcr: vcr_opts do
|
|
7
9
|
before(:all) do
|
|
@@ -11,48 +13,47 @@ describe 'For the Mailing Lists endpoint', vcr: vcr_opts do
|
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
it 'creates a list' do
|
|
14
|
-
result = @mg_obj.post(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
result = @mg_obj.post('lists', { address: @ml_address,
|
|
17
|
+
name: 'Integration Test List',
|
|
18
|
+
description: 'This list should be deleted automatically.',
|
|
19
|
+
access_level: 'members' })
|
|
18
20
|
|
|
19
21
|
result.to_h!
|
|
20
|
-
expect(result.body[
|
|
21
|
-
expect(result.body[
|
|
22
|
-
expect(result.body[
|
|
22
|
+
expect(result.body['message']).to eq('Mailing list has been created')
|
|
23
|
+
expect(result.body['list']['address']).to eq(@ml_address)
|
|
24
|
+
expect(result.body['list']['name']).to eq('Integration Test List')
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
it 'gets a list.' do
|
|
26
28
|
result = @mg_obj.get("lists/#{@ml_address}")
|
|
27
29
|
|
|
28
30
|
result.to_h!
|
|
29
|
-
expect(result.body[
|
|
30
|
-
expect(result.body[
|
|
31
|
+
expect(result.body['list']['address']).to eq(@ml_address)
|
|
32
|
+
expect(result.body['list']['name']).to eq('Integration Test List')
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
it 'gets a list of all lists.' do
|
|
34
|
-
result = @mg_obj.get(
|
|
36
|
+
result = @mg_obj.get('lists', { limit: 50 })
|
|
35
37
|
|
|
36
38
|
result.to_h!
|
|
37
|
-
expect(result.body[
|
|
39
|
+
expect(result.body['total_count']).to be > 0
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
it 'updates a list.' do
|
|
41
43
|
result = @mg_obj.put("lists/#{@ml_address}",
|
|
42
|
-
{:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
{ address: @ml_address,
|
|
45
|
+
name: 'Integration Test List Update',
|
|
46
|
+
description: 'This list should be deleted automatically.',
|
|
47
|
+
access_level: 'readonly' })
|
|
46
48
|
|
|
47
49
|
result.to_h!
|
|
48
|
-
expect(result.body[
|
|
49
|
-
expect(result.body[
|
|
50
|
-
expect(result.body[
|
|
51
|
-
expect(result.body[
|
|
50
|
+
expect(result.body['message']).to eq('Mailing list has been updated')
|
|
51
|
+
expect(result.body['list']['address']).to eq(@ml_address)
|
|
52
|
+
expect(result.body['list']['name']).to eq('Integration Test List Update')
|
|
53
|
+
expect(result.body['list']['access_level']).to eq('readonly')
|
|
52
54
|
end
|
|
53
55
|
|
|
54
56
|
it 'deletes a list' do
|
|
55
57
|
@mg_obj.delete("lists/#{@ml_address}")
|
|
56
58
|
end
|
|
57
|
-
|
|
58
59
|
end
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'mailgun'
|
|
3
5
|
|
|
4
6
|
vcr_opts = { cassette_name: 'logs' }
|
|
5
7
|
|
|
6
8
|
describe Mailgun::Logs, vcr: vcr_opts do
|
|
7
|
-
let(:logs) {
|
|
9
|
+
let(:logs) { described_class.new(Mailgun::Client.new(APIKEY, APIHOST, 'v1')) }
|
|
8
10
|
|
|
9
11
|
describe '#account_logs' do
|
|
10
12
|
let(:options) do
|
|
@@ -37,65 +39,65 @@ describe Mailgun::Logs, vcr: vcr_opts do
|
|
|
37
39
|
it 'responds with account logs' do
|
|
38
40
|
expect(logs.account_logs(options)).to eq(
|
|
39
41
|
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
'start' => 'Wed, 25 Jun 2025 00:00:00 -0000',
|
|
43
|
+
'end' => 'Wed, 25 Jun 2025 23:00:00 -0000',
|
|
44
|
+
'items' => [
|
|
43
45
|
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
'id' => '123',
|
|
47
|
+
'event' => 'accepted',
|
|
48
|
+
'@timestamp' => '2025-06-25T17:19:51.166Z',
|
|
49
|
+
'account' => {
|
|
50
|
+
'id' => '123'
|
|
49
51
|
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
'method' => 'HTTP',
|
|
53
|
+
'originating-ip' => '123.123.12.123',
|
|
54
|
+
'api-key-id' => 'xxx',
|
|
55
|
+
'domain' => {
|
|
56
|
+
'name' => 'example.mailgun.org'
|
|
55
57
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
'recipient' => 'alex@example.com',
|
|
59
|
+
'recipient-domain' => 'example.com',
|
|
60
|
+
'envelope' => {
|
|
61
|
+
'sender' => 'example.mailgun.org',
|
|
62
|
+
'transport' => 'smtp',
|
|
63
|
+
'targets' => 'alex@example.com'
|
|
62
64
|
},
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
'storage' => {
|
|
66
|
+
'region' => 'us-east4',
|
|
67
|
+
'env' => 'production',
|
|
68
|
+
'key' => 'xxx',
|
|
69
|
+
'url' => ['https://storage.api.mailgun.net/v3/domains/example.mailgun.org/messages/123']
|
|
68
70
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
'log-level' => 'info',
|
|
72
|
+
'user-variables' => '{}',
|
|
73
|
+
'message' => {
|
|
74
|
+
'headers' => {
|
|
75
|
+
'to' => 'alex@example.com',
|
|
76
|
+
'message-id' => '123@example.mailgun.org',
|
|
77
|
+
'from' => 'bob@sending_domain.com+4',
|
|
78
|
+
'subject' => 'The Ruby SDK is awesome!'
|
|
77
79
|
},
|
|
78
|
-
|
|
80
|
+
'attachments' => [
|
|
79
81
|
{
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
'filename' => 'image.jpg',
|
|
83
|
+
'content-type' => 'image/jpeg',
|
|
84
|
+
'size' => 16_712
|
|
83
85
|
}
|
|
84
86
|
],
|
|
85
|
-
|
|
87
|
+
'size' => 23_476
|
|
86
88
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
'flags' => {
|
|
90
|
+
'is-authenticated' => true,
|
|
91
|
+
'is-system-test' => false,
|
|
92
|
+
'is-routed' => false,
|
|
93
|
+
'is-test-mode' => false,
|
|
94
|
+
'is-delayed-bounce' => false,
|
|
95
|
+
'is-callback' => false
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
],
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
'pagination' => {},
|
|
100
|
+
'aggregates' => {}
|
|
99
101
|
}
|
|
100
102
|
)
|
|
101
103
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'json'
|
|
3
5
|
require 'logger'
|
|
@@ -21,7 +23,7 @@ class IntegrationUnitTestMailer < ActionMailer::Base
|
|
|
21
23
|
end
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
vcr_opts = { :
|
|
26
|
+
vcr_opts = { cassette_name: 'message_deliver' }
|
|
25
27
|
|
|
26
28
|
describe 'Message deliver', vcr: vcr_opts do
|
|
27
29
|
let(:domain) { TESTDOMAIN || 'DOMAIN.TEST' }
|
|
@@ -43,7 +45,7 @@ describe 'Message deliver', vcr: vcr_opts do
|
|
|
43
45
|
end
|
|
44
46
|
end
|
|
45
47
|
|
|
46
|
-
vcr_opts = { :
|
|
48
|
+
vcr_opts = { cassette_name: 'mailer_invalid_domain' }
|
|
47
49
|
|
|
48
50
|
describe 'Invalid domain', vcr: vcr_opts do
|
|
49
51
|
let(:domain) { 'not-our-doma.in' }
|
|
@@ -56,6 +58,8 @@ describe 'Invalid domain', vcr: vcr_opts do
|
|
|
56
58
|
let(:mail) { IntegrationUnitTestMailer.plain_message('sally@not-our-doma.in', "bob@#{domain}", 'subject', {}) }
|
|
57
59
|
|
|
58
60
|
it 'raises expected error' do
|
|
59
|
-
expect
|
|
61
|
+
expect do
|
|
62
|
+
Railgun::Mailer.new(config).deliver!(mail)
|
|
63
|
+
end.to raise_error Mailgun::Unauthorized, /Invalid Domain or API key/
|
|
60
64
|
end
|
|
61
65
|
end
|