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: 'routes', match_requests_on: %i[uri method body] }
|
|
5
7
|
|
|
6
8
|
describe 'For the Routes endpoint', order: :defined, vcr: vcr_opts do
|
|
7
9
|
before(:all) do
|
|
@@ -12,79 +14,78 @@ describe 'For the Routes endpoint', order: :defined, vcr: vcr_opts do
|
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
it 'creates a route' do
|
|
15
|
-
result = @mg_obj.post(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
result = @mg_obj.post('routes', { priority: 10,
|
|
18
|
+
description: 'Integration Test Route',
|
|
19
|
+
expression: "match_recipient(\"#{@forward_to}\")",
|
|
20
|
+
action: "forward(\"#{@recipient}\")" })
|
|
19
21
|
|
|
20
22
|
result.to_h!
|
|
21
|
-
expect(result.body[
|
|
22
|
-
expect(result.body[
|
|
23
|
-
expect(result.body[
|
|
24
|
-
expect(result.body[
|
|
25
|
-
expect(result.body[
|
|
23
|
+
expect(result.body['message']).to eq('Route has been created')
|
|
24
|
+
expect(result.body['route']['description']).to eq('Integration Test Route')
|
|
25
|
+
expect(result.body['route']['actions']).to include("forward(\"#{@recipient}\")")
|
|
26
|
+
expect(result.body['route']['expression']).to include("match_recipient(\"#{@forward_to}\")")
|
|
27
|
+
expect(result.body['route']['priority']).to eq(10)
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
it 'creates a route with multiple actions' do
|
|
29
|
-
result = @mg_obj.post(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
result = @mg_obj.post('routes', { priority: 10,
|
|
32
|
+
description: 'Integration Test Route',
|
|
33
|
+
expression: "match_recipient(\"#{@forward_to}\")",
|
|
34
|
+
action: ["forward(\"#{@recipient}\")", 'stop()'] })
|
|
33
35
|
|
|
34
36
|
result.to_h!
|
|
35
|
-
expect(result.body[
|
|
36
|
-
expect(result.body[
|
|
37
|
-
expect(result.body[
|
|
38
|
-
expect(result.body[
|
|
39
|
-
expect(result.body[
|
|
40
|
-
expect(result.body[
|
|
41
|
-
expect(result.body[
|
|
37
|
+
expect(result.body['message']).to eq('Route has been created')
|
|
38
|
+
expect(result.body['route']['description']).to eq('Integration Test Route')
|
|
39
|
+
expect(result.body['route']['actions'].count).to eq 2
|
|
40
|
+
expect(result.body['route']['actions'][0]).to include("forward(\"#{@recipient}\")")
|
|
41
|
+
expect(result.body['route']['actions'][1]).to include('stop()')
|
|
42
|
+
expect(result.body['route']['expression']).to include("match_recipient(\"#{@forward_to}\")")
|
|
43
|
+
expect(result.body['route']['priority']).to eq(10)
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
it 'gets a list of all routes.' do
|
|
45
|
-
result = @mg_obj.get(
|
|
47
|
+
result = @mg_obj.get('routes', { limit: 50 })
|
|
46
48
|
|
|
47
49
|
result.to_h!
|
|
48
|
-
expect(result.body[
|
|
50
|
+
expect(result.body['total_count']).to be > 0
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
it 'gets the route.' do
|
|
52
|
-
result = @mg_obj.get(
|
|
54
|
+
result = @mg_obj.get('routes', { limit: 1 })
|
|
53
55
|
route_id = result.to_h['items'].first['id']
|
|
54
56
|
|
|
55
57
|
result = @mg_obj.get("routes/#{route_id}")
|
|
56
58
|
|
|
57
59
|
result.to_h!
|
|
58
|
-
expect(result.body[
|
|
59
|
-
expect(result.body[
|
|
60
|
-
expect(result.body[
|
|
61
|
-
expect(result.body[
|
|
60
|
+
expect(result.body['route']['description']).to eq('Integration Test Route')
|
|
61
|
+
expect(result.body['route']['actions']).to include("forward(\"#{@recipient}\")")
|
|
62
|
+
expect(result.body['route']['expression']).to include("match_recipient(\"#{@forward_to}\")")
|
|
63
|
+
expect(result.body['route']['priority']).to eq(10)
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
it 'updates the route.' do
|
|
65
|
-
result = @mg_obj.get(
|
|
67
|
+
result = @mg_obj.get('routes', { limit: 1 })
|
|
66
68
|
route_id = result.to_h['items'].first['id']
|
|
67
69
|
|
|
68
|
-
result = @mg_obj.put("routes/#{route_id}",
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
result = @mg_obj.put("routes/#{route_id}", { priority: 10,
|
|
71
|
+
description: 'Integration Test Route Update',
|
|
72
|
+
expression: "match_recipient(\"#{@forward_to}\")",
|
|
73
|
+
action: "forward(\"#{@recipient}\")" })
|
|
72
74
|
|
|
73
75
|
result.to_h!
|
|
74
|
-
expect(result.body[
|
|
75
|
-
expect(result.body[
|
|
76
|
-
expect(result.body[
|
|
77
|
-
expect(result.body[
|
|
78
|
-
expect(result.body[
|
|
76
|
+
expect(result.body['message']).to eq('Route has been updated')
|
|
77
|
+
expect(result.body['description']).to eq('Integration Test Route Update')
|
|
78
|
+
expect(result.body['actions']).to include("forward(\"#{@recipient}\")")
|
|
79
|
+
expect(result.body['expression']).to include("match_recipient(\"#{@forward_to}\")")
|
|
80
|
+
expect(result.body['priority']).to eq(10)
|
|
79
81
|
end
|
|
80
82
|
|
|
81
83
|
it 'removes a route' do
|
|
82
|
-
result = @mg_obj.get(
|
|
84
|
+
result = @mg_obj.get('routes', { limit: 1 })
|
|
83
85
|
route_id = result.to_h['items'].first['id']
|
|
84
86
|
|
|
85
87
|
@mg_obj.delete("routes/#{route_id}")
|
|
86
88
|
|
|
87
89
|
result.to_h!
|
|
88
90
|
end
|
|
89
|
-
|
|
90
91
|
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: 'stats' }
|
|
5
7
|
|
|
6
8
|
describe 'For the Stats endpoint', vcr: vcr_opts do
|
|
7
9
|
before(:all) do
|
|
@@ -10,6 +12,6 @@ describe 'For the Stats endpoint', vcr: vcr_opts do
|
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
it 'get some stats.' do
|
|
13
|
-
@mg_obj.get("#{@domain}/stats", {:
|
|
15
|
+
@mg_obj.get("#{@domain}/stats", { limit: 50, skip: 10, event: 'sent' })
|
|
14
16
|
end
|
|
15
17
|
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: 'subaccounts' }
|
|
5
7
|
|
|
6
8
|
describe 'For the subaccounts endpoints', vcr: vcr_opts do
|
|
7
9
|
let(:name) { 'test.subaccount' }
|
|
@@ -16,7 +18,8 @@ describe 'For the subaccounts endpoints', vcr: vcr_opts do
|
|
|
16
18
|
it 'returns a list of templates' do
|
|
17
19
|
result = @mg_obj.list
|
|
18
20
|
|
|
19
|
-
expect(result).to eq({
|
|
21
|
+
expect(result).to eq({ 'subaccounts' => [{ 'id' => 'xxx', 'name' => 'test-ruby-lib', 'status' => 'open' }],
|
|
22
|
+
'total' => 1 })
|
|
20
23
|
end
|
|
21
24
|
end
|
|
22
25
|
|
|
@@ -24,26 +27,23 @@ describe 'For the subaccounts endpoints', vcr: vcr_opts do
|
|
|
24
27
|
it 'creates the subaccount' do
|
|
25
28
|
result = @mg_obj.create(name)
|
|
26
29
|
|
|
27
|
-
expect(result).to eq({
|
|
30
|
+
expect(result).to eq({ 'subaccount' => { 'id' => 'xxx', 'name' => 'test.subaccount', 'status' => 'open' } })
|
|
28
31
|
end
|
|
29
32
|
end
|
|
30
33
|
|
|
31
|
-
|
|
32
34
|
describe '#info' do
|
|
33
35
|
it 'gets the templates info' do
|
|
34
36
|
result = @mg_obj.info(subaccount_id)
|
|
35
37
|
|
|
36
|
-
expect(result).to eq({
|
|
38
|
+
expect(result).to eq({ 'subaccount' => { 'id' => 'xxx', 'name' => 'test-ruby-lib', 'status' => 'open' } })
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
42
|
describe '#enable' do
|
|
43
43
|
it 'enables the subaccount' do
|
|
44
44
|
result = @mg_obj.enable(subaccount_id)
|
|
45
45
|
|
|
46
|
-
expect(result).to eq({
|
|
46
|
+
expect(result).to eq({ 'subaccount' => { 'id' => 'xxx', 'name' => 'test-ruby-lib', 'status' => 'open' } })
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -51,8 +51,7 @@ describe 'For the subaccounts endpoints', vcr: vcr_opts do
|
|
|
51
51
|
it 'disables the subaccount' do
|
|
52
52
|
result = @mg_obj.disable(subaccount_id)
|
|
53
53
|
|
|
54
|
-
expect(result).to eq({
|
|
54
|
+
expect(result).to eq({ 'subaccount' => { 'id' => 'xxx', 'name' => 'test-ruby-lib', 'status' => 'disabled' } })
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
|
-
|
|
58
57
|
end
|
|
@@ -1,30 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
require 'mailgun'
|
|
4
6
|
require 'mailgun/suppressions'
|
|
5
7
|
|
|
6
|
-
vcr_opts = { :
|
|
8
|
+
vcr_opts = { cassette_name: 'suppressions', match_requests_on: %i[uri method body] }
|
|
7
9
|
|
|
8
10
|
describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts do
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@suppress = Mailgun::Suppressions.new(@mg_obj, TESTDOMAIN)
|
|
13
|
-
|
|
14
|
-
@addresses = ['test1@example.com', 'test2@example.org', 'test3@example.net', 'test4@example.info']
|
|
15
|
-
end
|
|
11
|
+
let(:mg_obj) { Mailgun::Client.new(APIKEY, APIHOST, 'v3') }
|
|
12
|
+
let(:suppress) { Mailgun::Suppressions.new(mg_obj, TESTDOMAIN) }
|
|
13
|
+
let(:addresses) { %w[test1@example.com test2@example.org test3@example.net test4@example.info] }
|
|
16
14
|
|
|
17
15
|
it 'can batch-add bounces' do
|
|
18
16
|
bounces = []
|
|
19
|
-
|
|
17
|
+
addresses.each do |addr|
|
|
20
18
|
bounces.push({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
address: addr,
|
|
20
|
+
code: 500,
|
|
21
|
+
error: 'integration testing'
|
|
22
|
+
})
|
|
25
23
|
end
|
|
26
24
|
|
|
27
|
-
response, nested =
|
|
25
|
+
response, nested = suppress.create_bounces bounces
|
|
28
26
|
response.to_h!
|
|
29
27
|
|
|
30
28
|
expect(response.code).to eq(200)
|
|
@@ -35,16 +33,44 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
|
|
|
35
33
|
it 'raises ParameterError if no bounce[:address] is present' do
|
|
36
34
|
bounces = []
|
|
37
35
|
bounces.push({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
code: 500,
|
|
37
|
+
error: 'integration testing'
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
expect { suppress.create_bounces bounces }.to raise_error(Mailgun::ParameterError)
|
|
41
|
+
end
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
it 'returns nil if no bounces passed' do
|
|
44
|
+
response = suppress.create_bounces({})
|
|
45
|
+
|
|
46
|
+
expect(response[0]).to be_nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'creates a single bounce' do
|
|
50
|
+
bounce = {
|
|
51
|
+
address: 'test777@example.info',
|
|
52
|
+
code: 777,
|
|
53
|
+
error: 'integration testing123'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
response = suppress.create_bounce bounce
|
|
57
|
+
response.to_h!
|
|
58
|
+
|
|
59
|
+
expect(response.code).to eq(200)
|
|
60
|
+
expect(response.body['message']).to eq('Address has been added to the bounces table')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'fetches a single bounce' do
|
|
64
|
+
response = suppress.get_bounce('test777@example.info')
|
|
65
|
+
response.to_h!
|
|
66
|
+
|
|
67
|
+
expect(response.code).to eq(200)
|
|
68
|
+
expect(response.body['address']).to eq('test777@example.info')
|
|
43
69
|
end
|
|
44
70
|
|
|
45
71
|
it 'removes a single bounce address' do
|
|
46
|
-
|
|
47
|
-
response =
|
|
72
|
+
addresses.each do |addr|
|
|
73
|
+
response = suppress.delete_bounce addr
|
|
48
74
|
response.to_h!
|
|
49
75
|
|
|
50
76
|
expect(response.code).to eq(200)
|
|
@@ -52,16 +78,24 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
|
|
|
52
78
|
end
|
|
53
79
|
end
|
|
54
80
|
|
|
81
|
+
it 'removes all bounces' do
|
|
82
|
+
response = suppress.delete_all_bounces
|
|
83
|
+
response.to_h!
|
|
84
|
+
|
|
85
|
+
expect(response.code).to eq(200)
|
|
86
|
+
expect(response.body['message']).to eq('Bounced addresses for this domain have been removed')
|
|
87
|
+
end
|
|
88
|
+
|
|
55
89
|
it 'can batch-add unsubscribes with tags as string' do
|
|
56
90
|
unsubscribes = []
|
|
57
|
-
|
|
91
|
+
addresses.each do |addr|
|
|
58
92
|
unsubscribes.push({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
93
|
+
address: addr,
|
|
94
|
+
tag: '123'
|
|
95
|
+
})
|
|
62
96
|
end
|
|
63
97
|
|
|
64
|
-
response, nested =
|
|
98
|
+
response, nested = suppress.create_unsubscribes unsubscribes
|
|
65
99
|
response.to_h!
|
|
66
100
|
|
|
67
101
|
expect(response.code).to eq(200)
|
|
@@ -71,14 +105,31 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
|
|
|
71
105
|
|
|
72
106
|
it 'can batch-add unsubscribes with tags as array' do
|
|
73
107
|
unsubscribes = []
|
|
74
|
-
|
|
108
|
+
addresses.each do |addr|
|
|
75
109
|
unsubscribes.push({
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
110
|
+
address: addr,
|
|
111
|
+
tags: ['integration']
|
|
112
|
+
})
|
|
79
113
|
end
|
|
80
114
|
|
|
81
|
-
response, nested =
|
|
115
|
+
response, nested = suppress.create_unsubscribes unsubscribes
|
|
116
|
+
response.to_h!
|
|
117
|
+
|
|
118
|
+
expect(response.code).to eq(200)
|
|
119
|
+
expect(response.body['message']).to eq('4 addresses have been added to the unsubscribes table')
|
|
120
|
+
expect(nested.length).to eq(0)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'can batch-add unsubscribes with tags as digits' do
|
|
124
|
+
unsubscribes = []
|
|
125
|
+
addresses.each do |addr|
|
|
126
|
+
unsubscribes.push({
|
|
127
|
+
address: addr,
|
|
128
|
+
tag: 123
|
|
129
|
+
})
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
response, nested = suppress.create_unsubscribes unsubscribes
|
|
82
133
|
response.to_h!
|
|
83
134
|
|
|
84
135
|
expect(response.code).to eq(200)
|
|
@@ -89,15 +140,21 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
|
|
|
89
140
|
it 'raises ParameterError if no unsubscribe[:address] is present' do
|
|
90
141
|
unsubscribes = []
|
|
91
142
|
unsubscribes.push({
|
|
92
|
-
|
|
93
|
-
|
|
143
|
+
tag: 'integration'
|
|
144
|
+
})
|
|
94
145
|
|
|
95
|
-
expect {
|
|
146
|
+
expect { suppress.create_unsubscribes unsubscribes }.to raise_error(Mailgun::ParameterError)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'returns nil if no unsubscribes passed' do
|
|
150
|
+
response = suppress.create_unsubscribes({})
|
|
151
|
+
|
|
152
|
+
expect(response[0]).to be_nil
|
|
96
153
|
end
|
|
97
154
|
|
|
98
155
|
it 'removes a single unsubscribe address' do
|
|
99
|
-
|
|
100
|
-
response =
|
|
156
|
+
addresses.each do |addr|
|
|
157
|
+
response = suppress.delete_unsubscribe addr
|
|
101
158
|
response.to_h!
|
|
102
159
|
|
|
103
160
|
expect(response.code).to eq(200)
|
|
@@ -105,13 +162,40 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
|
|
|
105
162
|
end
|
|
106
163
|
end
|
|
107
164
|
|
|
165
|
+
it 'creates a single unsubscribe' do
|
|
166
|
+
response = suppress.create_unsubscribe({
|
|
167
|
+
address: 'test777@example.com',
|
|
168
|
+
tags: ['integration']
|
|
169
|
+
})
|
|
170
|
+
response.to_h!
|
|
171
|
+
|
|
172
|
+
expect(response.code).to eq(200)
|
|
173
|
+
expect(response.body['message']).to eq('Address has been added to the unsubscribes table')
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it 'returns a single unsubscribe' do
|
|
177
|
+
response = suppress.get_unsubscribe('test777@example.com')
|
|
178
|
+
response.to_h!
|
|
179
|
+
|
|
180
|
+
expect(response.code).to eq(200)
|
|
181
|
+
expect(response.body['address']).to eq('test777@example.com')
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it 'returns all unsubscribers' do
|
|
185
|
+
response = suppress.list_unsubscribes
|
|
186
|
+
response.to_h!
|
|
187
|
+
|
|
188
|
+
expect(response.code).to eq(200)
|
|
189
|
+
expect(response.body['items'][0]['address']).to eq('test777@example.com')
|
|
190
|
+
end
|
|
191
|
+
|
|
108
192
|
it 'can batch-add complaints' do
|
|
109
193
|
complaints = []
|
|
110
|
-
|
|
111
|
-
complaints.push :
|
|
194
|
+
addresses.each do |addr|
|
|
195
|
+
complaints.push address: addr
|
|
112
196
|
end
|
|
113
197
|
|
|
114
|
-
response, nested =
|
|
198
|
+
response, nested = suppress.create_complaints complaints
|
|
115
199
|
response.to_h!
|
|
116
200
|
|
|
117
201
|
expect(response.code).to eq(200)
|
|
@@ -122,15 +206,45 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
|
|
|
122
206
|
it 'raises ParameterError if no complaint[:address] is present' do
|
|
123
207
|
complaints = []
|
|
124
208
|
complaints.push({
|
|
125
|
-
|
|
126
|
-
|
|
209
|
+
tag: 'integration'
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
expect { suppress.create_complaints complaints }.to raise_error(Mailgun::ParameterError)
|
|
213
|
+
end
|
|
127
214
|
|
|
128
|
-
|
|
215
|
+
it 'returns nil if no complaints passed' do
|
|
216
|
+
response = suppress.create_complaints({})
|
|
217
|
+
|
|
218
|
+
expect(response[0]).to be_nil
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
it 'creates a single complaint' do
|
|
222
|
+
response = suppress.create_complaint({ address: 'test777@example.com' })
|
|
223
|
+
response.to_h!
|
|
224
|
+
|
|
225
|
+
expect(response.code).to eq(200)
|
|
226
|
+
expect(response.body['message']).to eq('Address has been added to the complaints table')
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it 'returns a single complaint' do
|
|
230
|
+
response = suppress.get_complaint('test777@example.com')
|
|
231
|
+
response.to_h!
|
|
232
|
+
|
|
233
|
+
expect(response.code).to eq(200)
|
|
234
|
+
expect(response.body['address']).to eq('test777@example.com')
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it 'returns all complaints' do
|
|
238
|
+
response = suppress.list_complaints
|
|
239
|
+
response.to_h!
|
|
240
|
+
|
|
241
|
+
expect(response.code).to eq(200)
|
|
242
|
+
expect(response.body['items'][0]['address']).to eq('test1@example.com')
|
|
129
243
|
end
|
|
130
244
|
|
|
131
245
|
it 'removes a single complaint address' do
|
|
132
|
-
|
|
133
|
-
response =
|
|
246
|
+
addresses.each do |addr|
|
|
247
|
+
response = suppress.delete_complaint addr
|
|
134
248
|
response.to_h!
|
|
135
249
|
|
|
136
250
|
expect(response.code).to eq(200)
|
|
@@ -138,5 +252,69 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
|
|
|
138
252
|
end
|
|
139
253
|
end
|
|
140
254
|
|
|
141
|
-
|
|
255
|
+
describe 'paging' do
|
|
256
|
+
before do
|
|
257
|
+
suppress.list_bounces
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
describe '#next' do
|
|
261
|
+
it 'returns the response' do
|
|
262
|
+
resp = suppress.next
|
|
263
|
+
expect(resp.status).to eq(200)
|
|
264
|
+
expect(JSON.parse(resp.body)).to include('items')
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
describe '#prev' do
|
|
269
|
+
it 'returns the response' do
|
|
270
|
+
resp = suppress.prev
|
|
271
|
+
expect(resp.status).to eq(200)
|
|
272
|
+
expect(JSON.parse(resp.body)).to include('items')
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
context 'with 1000 or more entries' do
|
|
278
|
+
subject(:suppressions) { Mailgun::Suppressions.new(client, domain) }
|
|
279
|
+
|
|
280
|
+
let(:large_list) { Array.new(1000) { |i| { address: "user#{i}@example.com" } } }
|
|
281
|
+
let(:client) { double(:client) }
|
|
282
|
+
let(:domain) { 'example.com' }
|
|
283
|
+
|
|
284
|
+
def stub_response(body = {})
|
|
285
|
+
double(:response).tap do |r|
|
|
286
|
+
allow(r).to receive_messages(to_h: body, to_h!: body, code: 200, body: body)
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
it 'splits bounces list and makes two POST requests' do
|
|
291
|
+
expect(client).to receive(:post)
|
|
292
|
+
.with('example.com/bounces', anything, { 'Content-Type' => 'application/json' })
|
|
293
|
+
.twice
|
|
294
|
+
.and_return(stub_response)
|
|
295
|
+
|
|
296
|
+
_resp, split = suppressions.create_bounces(large_list)
|
|
297
|
+
expect(split).not_to be_empty
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
it 'splits unsubscribes list and makes two POST requests' do
|
|
301
|
+
expect(client).to receive(:post)
|
|
302
|
+
.with('example.com/unsubscribes', anything, { 'Content-Type' => 'application/json' })
|
|
303
|
+
.twice
|
|
304
|
+
.and_return(stub_response)
|
|
305
|
+
|
|
306
|
+
_resp, split = suppressions.create_unsubscribes(large_list)
|
|
307
|
+
expect(split).not_to be_empty
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
it 'splits complaints list and makes two POST requests' do
|
|
311
|
+
expect(client).to receive(:post)
|
|
312
|
+
.with('example.com/complaints', anything, { 'Content-Type' => 'application/json' })
|
|
313
|
+
.twice
|
|
314
|
+
.and_return(stub_response)
|
|
315
|
+
|
|
316
|
+
_resp, split = suppressions.create_complaints(large_list)
|
|
317
|
+
expect(split).not_to be_empty
|
|
318
|
+
end
|
|
319
|
+
end
|
|
142
320
|
end
|
|
@@ -1,11 +1,13 @@
|
|
|
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: 'templates' }
|
|
5
7
|
|
|
6
8
|
describe 'For the templates endpoints', vcr: vcr_opts do
|
|
7
9
|
let(:template_name) { 'test.template' }
|
|
8
|
-
let(:domain) {
|
|
10
|
+
let(:domain) { 'integration-test.domain.invalid' }
|
|
9
11
|
let(:tag) { 'v2' }
|
|
10
12
|
|
|
11
13
|
before(:all) do
|
|
@@ -21,14 +23,14 @@ describe 'For the templates endpoints', vcr: vcr_opts do
|
|
|
21
23
|
name: template_name,
|
|
22
24
|
description: 'Test',
|
|
23
25
|
template: '{{fname}} {{lname}}',
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
comment: 'test comment',
|
|
27
|
+
headers: '{"Subject": "{{subject}}"}',
|
|
28
|
+
tag: 'V1'
|
|
27
29
|
}
|
|
28
30
|
)
|
|
29
31
|
|
|
30
|
-
expect(result['template'][
|
|
31
|
-
expect(result['template'][
|
|
32
|
+
expect(result['template']['name']).to eq('test.template')
|
|
33
|
+
expect(result['template']['description']).to eq('Test')
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
|
|
@@ -36,8 +38,8 @@ describe 'For the templates endpoints', vcr: vcr_opts do
|
|
|
36
38
|
it 'gets the templates info' do
|
|
37
39
|
result = @mg_obj.info(domain, 'test.template')
|
|
38
40
|
|
|
39
|
-
expect(result).to include(
|
|
40
|
-
expect(result[
|
|
41
|
+
expect(result).to include('template')
|
|
42
|
+
expect(result['template']['name']).to eq(template_name)
|
|
41
43
|
end
|
|
42
44
|
end
|
|
43
45
|
|
|
@@ -88,7 +90,7 @@ describe 'For the templates endpoints', vcr: vcr_opts do
|
|
|
88
90
|
}
|
|
89
91
|
)
|
|
90
92
|
|
|
91
|
-
expect(result['template'][
|
|
93
|
+
expect(result['template']['version']['tag']).to eq(tag)
|
|
92
94
|
end
|
|
93
95
|
end
|
|
94
96
|
|
|
@@ -96,7 +98,7 @@ describe 'For the templates endpoints', vcr: vcr_opts do
|
|
|
96
98
|
it "gets the template's version info" do
|
|
97
99
|
result = @mg_obj.info_version(domain, template_name, tag)
|
|
98
100
|
|
|
99
|
-
expect(result[
|
|
101
|
+
expect(result['template']['version']['tag']).to eq(tag)
|
|
100
102
|
end
|
|
101
103
|
end
|
|
102
104
|
|
|
@@ -121,7 +123,7 @@ describe 'For the templates endpoints', vcr: vcr_opts do
|
|
|
121
123
|
it "returns template's versions" do
|
|
122
124
|
result = @mg_obj.template_versions_list(domain, template_name)
|
|
123
125
|
|
|
124
|
-
expect(result[
|
|
126
|
+
expect(result['template']['versions'].first).to include('tag')
|
|
125
127
|
end
|
|
126
128
|
end
|
|
127
129
|
|