mailgun-ruby 1.4.5 → 1.4.6

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.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -1
  3. data/README.md +3 -1
  4. data/lib/mailgun/api_keys/api_keys.rb +2 -2
  5. data/lib/mailgun/client.rb +1 -1
  6. data/lib/mailgun/domains/domain_keys.rb +5 -5
  7. data/lib/mailgun/domains/domains.rb +12 -9
  8. data/lib/mailgun/events/events.rb +1 -1
  9. data/lib/mailgun/helpers/api_version_checker.rb +23 -12
  10. data/lib/mailgun/helpers/deprecation.rb +32 -0
  11. data/lib/mailgun/lists/mailing_lists.rb +250 -0
  12. data/lib/mailgun/messages/message_builder.rb +17 -7
  13. data/lib/mailgun/response.rb +1 -1
  14. data/lib/mailgun/routes/routes.rb +98 -0
  15. data/lib/mailgun/tags/analytics_tags.rb +2 -2
  16. data/lib/mailgun/tags/tags.rb +16 -8
  17. data/lib/mailgun/version.rb +1 -1
  18. data/lib/mailgun/webhooks/account_webhooks.rb +2 -2
  19. data/lib/mailgun/webhooks/webhooks.rb +17 -9
  20. data/lib/mailgun.rb +1 -0
  21. metadata +6 -326
  22. data/.github/workflows/ci.yml +0 -49
  23. data/.github_changelog_generator +0 -1
  24. data/.gitignore +0 -24
  25. data/.rubocop.yml +0 -68
  26. data/.ruby-env.yml.example +0 -13
  27. data/Gemfile +0 -9
  28. data/Rakefile +0 -32
  29. data/docs/AccountWebhooks.md +0 -55
  30. data/docs/AnalyticsTags.md +0 -63
  31. data/docs/ApiKeys.md +0 -65
  32. data/docs/DomainKeys.md +0 -49
  33. data/docs/Domains.md +0 -82
  34. data/docs/EmailValidation.md +0 -34
  35. data/docs/Events.md +0 -48
  36. data/docs/Logs.md +0 -67
  37. data/docs/MessageBuilder.md +0 -120
  38. data/docs/Metrics.md +0 -108
  39. data/docs/OptInHandler.md +0 -103
  40. data/docs/Snippets.md +0 -519
  41. data/docs/Subaccounts.md +0 -68
  42. data/docs/Suppressions.md +0 -92
  43. data/docs/Templates.md +0 -92
  44. data/docs/Webhooks.md +0 -65
  45. data/docs/railgun/EmailValidation.md +0 -34
  46. data/docs/railgun/Overview.md +0 -11
  47. data/docs/railgun/Parameters.md +0 -83
  48. data/mailgun.gemspec +0 -47
  49. data/spec/integration/account_webhooks_spec.rb +0 -57
  50. data/spec/integration/analytics_tags_spec.rb +0 -54
  51. data/spec/integration/api_keys_spec.rb +0 -50
  52. data/spec/integration/bounces_spec.rb +0 -45
  53. data/spec/integration/campaign_spec.rb +0 -62
  54. data/spec/integration/complaints_spec.rb +0 -40
  55. data/spec/integration/domain_keys_spec.rb +0 -124
  56. data/spec/integration/domains_spec.rb +0 -201
  57. data/spec/integration/email_validation_spec.rb +0 -73
  58. data/spec/integration/events_spec.rb +0 -28
  59. data/spec/integration/list_members_spec.rb +0 -64
  60. data/spec/integration/list_spec.rb +0 -59
  61. data/spec/integration/logs_spec.rb +0 -105
  62. data/spec/integration/mailer_spec.rb +0 -65
  63. data/spec/integration/mailgun_spec.rb +0 -198
  64. data/spec/integration/messages/sample_data/mime.txt +0 -38
  65. data/spec/integration/metrics_spec.rb +0 -224
  66. data/spec/integration/routes_spec.rb +0 -91
  67. data/spec/integration/stats_spec.rb +0 -17
  68. data/spec/integration/subaccounts_spec.rb +0 -57
  69. data/spec/integration/suppressions_spec.rb +0 -320
  70. data/spec/integration/templates_spec.rb +0 -137
  71. data/spec/integration/unsubscribes_spec.rb +0 -44
  72. data/spec/integration/webhook_spec.rb +0 -79
  73. data/spec/spec_helper.rb +0 -53
  74. data/spec/unit/client_spec.rb +0 -448
  75. data/spec/unit/connection/test_client.rb +0 -169
  76. data/spec/unit/events/events_spec.rb +0 -88
  77. data/spec/unit/exceptions/exceptions_spec.rb +0 -31
  78. data/spec/unit/helpers/api_version_checker_spec.rb +0 -206
  79. data/spec/unit/lists/opt_in_handler_spec.rb +0 -28
  80. data/spec/unit/mailgun_spec.rb +0 -171
  81. data/spec/unit/messages/batch_message_spec.rb +0 -148
  82. data/spec/unit/messages/message_builder_spec.rb +0 -745
  83. data/spec/unit/messages/sample_data/mailgun_icon.png +0 -0
  84. data/spec/unit/messages/sample_data/mime.txt +0 -38
  85. data/spec/unit/messages/sample_data/rackspace_logo.jpg +0 -0
  86. data/spec/unit/messages/sample_data/unknown.type +0 -0
  87. data/spec/unit/railgun/content_type_spec.rb +0 -89
  88. data/spec/unit/railgun/mailer_spec.rb +0 -391
  89. data/spec/unit/response_spec.rb +0 -225
  90. data/spec/unit/webhooks_spec.rb +0 -121
  91. data/vcr_cassettes/For_the_suppressions_handling_class/creates_a_single_bounce.yml +0 -55
  92. data/vcr_cassettes/account_webhooks.yml +0 -269
  93. data/vcr_cassettes/analytics_tags.yml +0 -187
  94. data/vcr_cassettes/api_keys.yml +0 -212
  95. data/vcr_cassettes/bounces.yml +0 -136
  96. data/vcr_cassettes/complaints.yml +0 -315
  97. data/vcr_cassettes/domains.todo.yml +0 -42
  98. data/vcr_cassettes/domains.yml +0 -1243
  99. data/vcr_cassettes/email_validation.yml +0 -152
  100. data/vcr_cassettes/events.yml +0 -69
  101. data/vcr_cassettes/exceptions-invalid-api-key.yml +0 -52
  102. data/vcr_cassettes/exceptions-invalid-data.yml +0 -52
  103. data/vcr_cassettes/exceptions-not-allowed.yml +0 -54
  104. data/vcr_cassettes/exceptions.yml +0 -92
  105. data/vcr_cassettes/list_members.yml +0 -328
  106. data/vcr_cassettes/logs.yml +0 -53
  107. data/vcr_cassettes/mailer_invalid_domain.yml +0 -109
  108. data/vcr_cassettes/mailing_list.todo.yml +0 -43
  109. data/vcr_cassettes/mailing_list.yml +0 -682
  110. data/vcr_cassettes/message_deliver.yml +0 -149
  111. data/vcr_cassettes/metrics.yml +0 -116
  112. data/vcr_cassettes/routes.yml +0 -359
  113. data/vcr_cassettes/send_message.yml +0 -158
  114. data/vcr_cassettes/stats.yml +0 -48
  115. data/vcr_cassettes/subaccounts.yml +0 -270
  116. data/vcr_cassettes/suppressions.yml +0 -1392
  117. data/vcr_cassettes/templates.yml +0 -1065
  118. data/vcr_cassettes/unsubscribes.yml +0 -401
  119. data/vcr_cassettes/webhooks.yml +0 -246
  120. data/vcr_cassettes/webhooks_v4.yml +0 -275
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'mailgun'
5
-
6
- vcr_opts = { cassette_name: 'subaccounts' }
7
-
8
- describe 'For the subaccounts endpoints', vcr: vcr_opts do
9
- let(:name) { 'test.subaccount' }
10
- let(:subaccount_id) { 'xxx' }
11
-
12
- before(:all) do
13
- mg_client = Mailgun::Client.new(APIKEY, APIHOST, 'v5')
14
- @mg_obj = Mailgun::Subaccounts.new mg_client
15
- end
16
-
17
- describe '#list' do
18
- it 'returns a list of templates' do
19
- result = @mg_obj.list
20
-
21
- expect(result).to eq({ 'subaccounts' => [{ 'id' => 'xxx', 'name' => 'test-ruby-lib', 'status' => 'open' }],
22
- 'total' => 1 })
23
- end
24
- end
25
-
26
- describe '#create' do
27
- it 'creates the subaccount' do
28
- result = @mg_obj.create(name)
29
-
30
- expect(result).to eq({ 'subaccount' => { 'id' => 'xxx', 'name' => 'test.subaccount', 'status' => 'open' } })
31
- end
32
- end
33
-
34
- describe '#info' do
35
- it 'gets the templates info' do
36
- result = @mg_obj.info(subaccount_id)
37
-
38
- expect(result).to eq({ 'subaccount' => { 'id' => 'xxx', 'name' => 'test-ruby-lib', 'status' => 'open' } })
39
- end
40
- end
41
-
42
- describe '#enable' do
43
- it 'enables the subaccount' do
44
- result = @mg_obj.enable(subaccount_id)
45
-
46
- expect(result).to eq({ 'subaccount' => { 'id' => 'xxx', 'name' => 'test-ruby-lib', 'status' => 'open' } })
47
- end
48
- end
49
-
50
- describe '#disable' do
51
- it 'disables the subaccount' do
52
- result = @mg_obj.disable(subaccount_id)
53
-
54
- expect(result).to eq({ 'subaccount' => { 'id' => 'xxx', 'name' => 'test-ruby-lib', 'status' => 'disabled' } })
55
- end
56
- end
57
- end
@@ -1,320 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- require 'mailgun'
6
- require 'mailgun/suppressions'
7
-
8
- vcr_opts = { cassette_name: 'suppressions', match_requests_on: %i[uri method body] }
9
-
10
- describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts do
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] }
14
-
15
- it 'can batch-add bounces' do
16
- bounces = []
17
- addresses.each do |addr|
18
- bounces.push({
19
- address: addr,
20
- code: 500,
21
- error: 'integration testing'
22
- })
23
- end
24
-
25
- response, nested = suppress.create_bounces bounces
26
- response.to_h!
27
-
28
- expect(response.code).to eq(200)
29
- expect(response.body['message']).to eq('4 addresses have been added to the bounces table')
30
- expect(nested.length).to eq(0)
31
- end
32
-
33
- it 'raises ParameterError if no bounce[:address] is present' do
34
- bounces = []
35
- bounces.push({
36
- code: 500,
37
- error: 'integration testing'
38
- })
39
-
40
- expect { suppress.create_bounces bounces }.to raise_error(Mailgun::ParameterError)
41
- end
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')
69
- end
70
-
71
- it 'removes a single bounce address' do
72
- addresses.each do |addr|
73
- response = suppress.delete_bounce addr
74
- response.to_h!
75
-
76
- expect(response.code).to eq(200)
77
- expect(response.body['message']).to eq('Bounced address has been removed')
78
- end
79
- end
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
-
89
- it 'can batch-add unsubscribes with tags as string' do
90
- unsubscribes = []
91
- addresses.each do |addr|
92
- unsubscribes.push({
93
- address: addr,
94
- tag: '123'
95
- })
96
- end
97
-
98
- response, nested = suppress.create_unsubscribes unsubscribes
99
- response.to_h!
100
-
101
- expect(response.code).to eq(200)
102
- expect(response.body['message']).to eq('4 addresses have been added to the unsubscribes table')
103
- expect(nested.length).to eq(0)
104
- end
105
-
106
- it 'can batch-add unsubscribes with tags as array' do
107
- unsubscribes = []
108
- addresses.each do |addr|
109
- unsubscribes.push({
110
- address: addr,
111
- tags: ['integration']
112
- })
113
- end
114
-
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
133
- response.to_h!
134
-
135
- expect(response.code).to eq(200)
136
- expect(response.body['message']).to eq('4 addresses have been added to the unsubscribes table')
137
- expect(nested.length).to eq(0)
138
- end
139
-
140
- it 'raises ParameterError if no unsubscribe[:address] is present' do
141
- unsubscribes = []
142
- unsubscribes.push({
143
- tag: 'integration'
144
- })
145
-
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
153
- end
154
-
155
- it 'removes a single unsubscribe address' do
156
- addresses.each do |addr|
157
- response = suppress.delete_unsubscribe addr
158
- response.to_h!
159
-
160
- expect(response.code).to eq(200)
161
- expect(response.body['message']).to eq('Unsubscribe event has been removed')
162
- end
163
- end
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
-
192
- it 'can batch-add complaints' do
193
- complaints = []
194
- addresses.each do |addr|
195
- complaints.push address: addr
196
- end
197
-
198
- response, nested = suppress.create_complaints complaints
199
- response.to_h!
200
-
201
- expect(response.code).to eq(200)
202
- expect(response.body['message']).to eq('4 complaint addresses have been added to the complaints table')
203
- expect(nested.length).to eq(0)
204
- end
205
-
206
- it 'raises ParameterError if no complaint[:address] is present' do
207
- complaints = []
208
- complaints.push({
209
- tag: 'integration'
210
- })
211
-
212
- expect { suppress.create_complaints complaints }.to raise_error(Mailgun::ParameterError)
213
- end
214
-
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')
243
- end
244
-
245
- it 'removes a single complaint address' do
246
- addresses.each do |addr|
247
- response = suppress.delete_complaint addr
248
- response.to_h!
249
-
250
- expect(response.code).to eq(200)
251
- expect(response.body['message']).to eq('Spam complaint has been removed')
252
- end
253
- end
254
-
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
320
- end
@@ -1,137 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'mailgun'
5
-
6
- vcr_opts = { cassette_name: 'templates' }
7
-
8
- describe 'For the templates endpoints', vcr: vcr_opts do
9
- let(:template_name) { 'test.template' }
10
- let(:domain) { 'integration-test.domain.invalid' }
11
- let(:tag) { 'v2' }
12
-
13
- before(:all) do
14
- @mg_client = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
15
- @mg_obj = Mailgun::Templates.new(@mg_client)
16
- end
17
-
18
- describe '#create' do
19
- it 'creates the template' do
20
- result = @mg_obj.create(
21
- domain,
22
- {
23
- name: template_name,
24
- description: 'Test',
25
- template: '{{fname}} {{lname}}',
26
- comment: 'test comment',
27
- headers: '{"Subject": "{{subject}}"}',
28
- tag: 'V1'
29
- }
30
- )
31
-
32
- expect(result['template']['name']).to eq('test.template')
33
- expect(result['template']['description']).to eq('Test')
34
- end
35
- end
36
-
37
- describe '#info' do
38
- it 'gets the templates info' do
39
- result = @mg_obj.info(domain, 'test.template')
40
-
41
- expect(result).to include('template')
42
- expect(result['template']['name']).to eq(template_name)
43
- end
44
- end
45
-
46
- describe '#update' do
47
- it 'updates the template' do
48
- result = @mg_obj.update(domain, template_name, { description: 'Updated Description' })
49
-
50
- expect(result['message']).to eq('template has been updated')
51
- end
52
- end
53
-
54
- describe '#list' do
55
- it 'returns a list of templates' do
56
- result = @mg_obj.list(domain)
57
-
58
- expect(result.first).to have_key('name')
59
- expect(result.first).to have_key('description')
60
- end
61
- end
62
-
63
- describe '#delete' do
64
- it 'deletes a template' do
65
- result = @mg_obj.delete(domain, template_name)
66
-
67
- expect(result).to be_truthy
68
- end
69
- end
70
-
71
- describe '#remove_all' do
72
- it 'deletes all templates from domain' do
73
- result = @mg_obj.remove_all(domain)
74
-
75
- expect(result).to be_truthy
76
- end
77
- end
78
-
79
- describe '#create_version' do
80
- it 'creates the version for the template' do
81
- result = @mg_obj.create_version(
82
- domain,
83
- template_name,
84
- {
85
- template: '{{fname}} {{lname}}',
86
- comment: 'test comment',
87
- headers: '{"Subject": "{{subject}}"}',
88
- tag: tag,
89
- active: 'yes'
90
- }
91
- )
92
-
93
- expect(result['template']['version']['tag']).to eq(tag)
94
- end
95
- end
96
-
97
- describe '#info_version' do
98
- it "gets the template's version info" do
99
- result = @mg_obj.info_version(domain, template_name, tag)
100
-
101
- expect(result['template']['version']['tag']).to eq(tag)
102
- end
103
- end
104
-
105
- describe '#update_version' do
106
- it 'updates the template' do
107
- result = @mg_obj.update_version(
108
- domain,
109
- template_name,
110
- tag,
111
- {
112
- template: '{{fname}} {{lname}}',
113
- comment: 'test comment 2',
114
- headers: '{"Subject": "{{subject}}"}'
115
- }
116
- )
117
-
118
- expect(result['message']).to eq('version has been updated')
119
- end
120
- end
121
-
122
- describe '#template_versions_list' do
123
- it "returns template's versions" do
124
- result = @mg_obj.template_versions_list(domain, template_name)
125
-
126
- expect(result['template']['versions'].first).to include('tag')
127
- end
128
- end
129
-
130
- describe '#delete_version' do
131
- it "deletes template's version" do
132
- result = @mg_obj.delete_version(domain, template_name, tag)
133
-
134
- expect(result).to be_truthy
135
- end
136
- end
137
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'mailgun'
5
-
6
- vcr_opts = { cassette_name: 'unsubscribes' }
7
-
8
- describe 'For the Unsubscribes endpoint', order: :defined, vcr: vcr_opts do
9
- before(:all) do
10
- @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
11
- @domain = TESTDOMAIN || 'DOMAIN.TEST'
12
- @email = "integration-test-email@#{@domain}"
13
- end
14
-
15
- it 'adds an unsubscriber' do
16
- result = @mg_obj.post "#{@domain}/unsubscribes", address: @email, tag: '*'
17
-
18
- result.to_h!
19
- expect(result.body['message']).to eq('Address has been added to the unsubscribes table')
20
- expect(result.body['address']).to eq(@email)
21
- end
22
-
23
- it 'get an unsubscribee.' do
24
- result = @mg_obj.get "#{@domain}/unsubscribes/#{@email}"
25
-
26
- result.to_h!
27
- expect(result.body['address']).to eq(@email)
28
- end
29
-
30
- it 'gets a list of unsubscribes.' do
31
- result = @mg_obj.get "#{@domain}/unsubscribes"
32
-
33
- result.to_h!
34
- expect(result.body['items'].length).to be > 0
35
- end
36
-
37
- it 'removes an unsubscribee' do
38
- result = @mg_obj.delete "#{@domain}/unsubscribes/#{@email}"
39
-
40
- result.to_h!
41
- expect(result.body['address']).to eq(@email)
42
- expect(result.body['message']).to eq('Unsubscribe event has been removed')
43
- end
44
- end
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'mailgun'
5
-
6
- vcr_opts = { cassette_name: 'webhooks' }
7
-
8
- describe 'For the webhooks endpoint', order: :defined, vcr: vcr_opts do
9
- let(:api_version) { 'v3' }
10
- let(:mg_client) { Mailgun::Client.new(APIKEY, APIHOST, api_version, SSL) }
11
- let(:mg_obj) { Mailgun::Webhooks.new(mg_client) }
12
- let(:domain) { 'DOMAIN.TEST' }
13
- let(:testhook) { 'accepted' }
14
- let(:testhookup) { 'accepted' }
15
-
16
- it 'creates a webhook' do
17
- result = mg_obj.create(domain, testhook, "http://example.com/mailgun/events/#{testhook}")
18
-
19
- expect(result).to be_truthy
20
- end
21
-
22
- it 'gets a webhook' do
23
- result = mg_obj.get(domain, testhook)
24
-
25
- expect(result).to include("http://example.com/mailgun/events/#{testhook}")
26
- end
27
-
28
- it 'gets a list of all webhooks' do
29
- result = mg_obj.list(domain)
30
-
31
- expect(result['accepted']['urls'][0]).to include("http://example.com/mailgun/events/#{testhook}")
32
- end
33
-
34
- it 'updates a webhook' do
35
- result = mg_obj.update(domain, testhook, "http://example.com/mailgun/events/#{testhookup}")
36
-
37
- expect(result).to be_truthy
38
- end
39
-
40
- it 'removes a webhook' do
41
- result = mg_obj.remove(domain, testhook)
42
-
43
- expect(result).to be_truthy
44
- end
45
- end
46
-
47
- describe 'For the v4 webhooks endpoint', vcr: { cassette_name: 'webhooks_v4' } do
48
- let(:mg_client) { Mailgun::Client.new(APIKEY, APIHOST, 'v4', SSL) }
49
- let(:mg_obj) { Mailgun::Webhooks.new(mg_client) }
50
- let(:domain) { 'DOMAIN.TEST' }
51
- let(:url) { 'http://example.com/mailgun/events/v4' }
52
-
53
- describe '#create_v4' do
54
- it 'creates webhooks for multiple event types' do
55
- result = mg_obj.create_v4(domain, url: url, event_types: %w[accepted delivered])
56
-
57
- expect(result.keys).to contain_exactly('accepted', 'delivered')
58
- expect(result['accepted']['urls']).to include(url)
59
- expect(result['delivered']['urls']).to include(url)
60
- end
61
- end
62
-
63
- describe '#update_v4' do
64
- it 'replaces the event types associated with a url' do
65
- result = mg_obj.update_v4(domain, url: url, event_types: %w[clicked opened])
66
-
67
- expect(result.keys).to contain_exactly('clicked', 'opened')
68
- expect(result['clicked']['urls']).to include(url)
69
- end
70
- end
71
-
72
- describe '#remove_v4' do
73
- it 'removes the urls from all event types' do
74
- result = mg_obj.remove_v4(domain, url: [url, 'http://example.com/mailgun/events/v4-other'])
75
-
76
- expect(result).to eq({})
77
- end
78
- end
79
- end
data/spec/spec_helper.rb DELETED
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'simplecov'
4
- require 'simplecov-json'
5
- SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
6
- [
7
- SimpleCov::Formatter::HTMLFormatter,
8
- SimpleCov::Formatter::JSONFormatter
9
- ]
10
- )
11
-
12
- SimpleCov.start do
13
- add_filter '/spec/'
14
- end
15
-
16
- require 'mailgun'
17
-
18
- require 'vcr'
19
- require 'webmock/rspec'
20
- # Keep repeated query keys (e.g. ?url=a&url=b) instead of collapsing them to the last value
21
- WebMock::Config.instance.query_values_notation = :flat_array
22
- require 'rspec/its'
23
-
24
- # WebMock.disable_net_connect!(allow_localhost: true)
25
- require_relative 'unit/connection/test_client'
26
-
27
- RSpec.configure(&:raise_errors_for_deprecations!)
28
-
29
- APIHOST = 'api.mailgun.net'
30
- APIVERSION = 'v3'
31
- SSL = true
32
-
33
- # For integration tests modify .ruby-env.yml
34
- # use .ruby-env.yml.example for an example
35
- # alternatively
36
- # set environment variables as named in .ruby-env.yml.example
37
- envfile = File.join(File.dirname(__FILE__), '..', '.ruby-env.yml')
38
- envs = File.exist?(envfile) ? YAML.load_file(envfile) : ENV
39
- APIKEY = envs['MAILGUN_APIKEY']
40
- PUB_APIKEY = envs['MAILGUN_PUB_APIKEY']
41
- TESTDOMAIN = envs['MAILGUN_TESTDOMAIN']
42
-
43
- VCR.configure do |c|
44
- c.cassette_library_dir = 'vcr_cassettes'
45
- c.hook_into :webmock
46
- c.default_cassette_options = { record: :new_episodes }
47
- c.filter_sensitive_data('<APIKEY>') { APIKEY }
48
- c.filter_sensitive_data('<BASIC_AUTH>') { ["api:#{APIKEY}"].pack('m0') } if APIKEY
49
- c.filter_sensitive_data('DOMAIN.TEST') { TESTDOMAIN }
50
- c.filter_sensitive_data('<PUBKEY>') { PUB_APIKEY }
51
-
52
- c.configure_rspec_metadata!
53
- end