mailgun-ruby 1.2.15 → 1.3.5

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +52 -3
  4. data/Gemfile +1 -0
  5. data/README.md +2 -2
  6. data/docs/MessageBuilder.md +12 -0
  7. data/docs/Metrics.md +108 -0
  8. data/docs/Webhooks.md +4 -2
  9. data/lib/mailgun/chains.rb +1 -1
  10. data/lib/mailgun/client.rb +40 -30
  11. data/lib/mailgun/domains/domains.rb +19 -0
  12. data/lib/mailgun/events/events.rb +4 -4
  13. data/lib/mailgun/exceptions/exceptions.rb +7 -7
  14. data/lib/mailgun/messages/message_builder.rb +14 -2
  15. data/lib/mailgun/metrics/metrics.rb +61 -0
  16. data/lib/mailgun/response.rb +11 -10
  17. data/lib/mailgun/version.rb +1 -1
  18. data/lib/mailgun.rb +2 -1
  19. data/mailgun.gemspec +6 -3
  20. data/spec/integration/domains_spec.rb +95 -92
  21. data/spec/integration/email_validation_spec.rb +2 -1
  22. data/spec/integration/list_spec.rb +1 -1
  23. data/spec/integration/mailer_spec.rb +5 -5
  24. data/spec/integration/mailgun_spec.rb +14 -12
  25. data/spec/integration/metrics_spec.rb +218 -0
  26. data/spec/integration/routes_spec.rb +17 -1
  27. data/spec/integration/stats_spec.rb +1 -1
  28. data/spec/integration/unsubscribes_spec.rb +2 -2
  29. data/spec/integration/webhook_spec.rb +1 -1
  30. data/spec/spec_helper.rb +1 -0
  31. data/spec/unit/connection/test_client.rb +1 -1
  32. data/spec/unit/events/events_spec.rb +1 -1
  33. data/spec/unit/exceptions/exceptions_spec.rb +3 -3
  34. data/spec/unit/messages/message_builder_spec.rb +4 -3
  35. data/vcr_cassettes/bounces.yml +59 -98
  36. data/vcr_cassettes/complaints.yml +237 -97
  37. data/vcr_cassettes/domains.yml +332 -763
  38. data/vcr_cassettes/email_validation.yml +81 -144
  39. data/vcr_cassettes/events.yml +24 -63
  40. data/vcr_cassettes/exceptions.yml +49 -2
  41. data/vcr_cassettes/list_members.yml +187 -179
  42. data/vcr_cassettes/mailing_list.yml +309 -17
  43. data/vcr_cassettes/metrics.yml +116 -0
  44. data/vcr_cassettes/routes.yml +246 -246
  45. data/vcr_cassettes/send_message.yml +54 -3
  46. data/vcr_cassettes/stats.yml +28 -24
  47. data/vcr_cassettes/suppressions.yml +229 -447
  48. data/vcr_cassettes/unsubscribes.yml +219 -9
  49. metadata +58 -15
  50. data/docs/Messages.md +0 -107
  51. /data/docs/{railgun/Templates.md → Templates.md} +0 -0
@@ -1,5 +1,6 @@
1
1
  require 'mime/types'
2
2
  require 'time'
3
+ require 'faraday/multipart'
3
4
 
4
5
  module Mailgun
5
6
 
@@ -189,7 +190,7 @@ module Mailgun
189
190
  @counters[:attributes][:campaign_id] += 1
190
191
  end
191
192
 
192
- # Add tags to message. Limit of 3 per message.
193
+ # Add tags to message. Limit of 10 per message.
193
194
  #
194
195
  # @param [String] tag A defined campaign ID to add to the message.
195
196
  # @return [void]
@@ -384,6 +385,17 @@ module Mailgun
384
385
  @message[parameter] << (value || '')
385
386
  end
386
387
 
388
+ # Adds multipart attachment using Faraday::Multipart::FilePart
389
+ #
390
+ # @param [String] parameter The message object parameter name.
391
+ # @param [String] value The attachment.
392
+ # @param [String] filename Filename of the attachment.
393
+ # @return [void]
394
+ def add_faraday_attachment(parameter, attachment, filename)
395
+ content_type = attachment.respond_to?(:content_type) ? attachment.content_type : nil
396
+ @message[parameter] << Faraday::Multipart::FilePart.new(attachment, content_type, filename)
397
+ end
398
+
387
399
  # Converts boolean type to string
388
400
  #
389
401
  # @param [String] value The item to convert
@@ -469,7 +481,7 @@ module Mailgun
469
481
  attachment.instance_variable_set :@original_filename, filename
470
482
  attachment.instance_eval 'def original_filename; @original_filename; end'
471
483
  end
472
- set_multi_complex(disposition, attachment)
484
+ add_faraday_attachment(disposition, attachment, filename)
473
485
  end
474
486
  end
475
487
 
@@ -0,0 +1,61 @@
1
+ require 'mailgun/exceptions/exceptions'
2
+
3
+ module Mailgun
4
+ # A Mailgun::Metrics object is a simple interface to Mailgun Metrics.
5
+ # Uses Mailgun
6
+ class Metrics
7
+ # Public: creates a new Mailgun::Metrics instance.
8
+ # Defaults to Mailgun::Client
9
+ def initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v1'))
10
+ @client = client
11
+ end
12
+
13
+ # Public: Post query to get account metrics
14
+ #
15
+ # options - [Hash] of
16
+ # start - [String] A start date (default: 7 days before current time). Must be in RFC 2822 format.
17
+ # end - [String] An end date (default: current time). Must be in RFC 2822 format.
18
+ # resolution - [String] A resolution in the format of 'day' 'hour' 'month'. Default is day.
19
+ # duration - [String] A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.
20
+ # dimensions - [Array] Attributes of the metric data such as 'subaccount'.
21
+ # metrics - [Array] Name of the metrics to receive the stats for such as 'processed_count'
22
+ # filter - [Object]
23
+ # AND: - [Array] of objects
24
+ # attribute - [String]
25
+ # comparator - [String]
26
+ # values - [Array] of objects
27
+ # label - [String]
28
+ # value - [String]
29
+ # include_subaccounts - [Boolean] Include stats from all subaccounts.
30
+ # include_aggregates - [Boolean] Include top-level aggregate metrics.
31
+ #
32
+ # Returns [Hash] Metrics
33
+ def account_metrics(options={})
34
+ @client.post('analytics/metrics', options.to_json, { "Content-Type" => "application/json" }).to_h!
35
+ end
36
+
37
+ # Public: Post query to get account usage metrics
38
+ #
39
+ # options - [Hash] of
40
+ # start - [String] A start date (default: 7 days before current time). Must be in RFC 2822 format.
41
+ # end - [String] An end date (default: current time). Must be in RFC 2822 format.
42
+ # resolution - [String] A resolution in the format of 'day' 'hour' 'month'. Default is day.
43
+ # duration - [String] A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.
44
+ # dimensions - [Array] Attributes of the metric data such as 'subaccount'.
45
+ # metrics - [Array] Name of the metrics to receive the stats for such as 'processed_count'
46
+ # filter - [Object]
47
+ # AND: - [Array] of objects
48
+ # attribute - [String]
49
+ # comparator - [String]
50
+ # values - [Array] of objects
51
+ # label - [String]
52
+ # value - [String]
53
+ # include_subaccounts - [Boolean] Include stats from all subaccounts.
54
+ # include_aggregates - [Boolean] Include top-level aggregate metrics.
55
+ #
56
+ # Returns [Hash] Metrics
57
+ def account_usage_metrics(options={})
58
+ @client.post('analytics/usage/metrics', options.to_json, { "Content-Type" => "application/json" }).to_h!
59
+ end
60
+ end
61
+ end
@@ -6,19 +6,20 @@ module Mailgun
6
6
  #
7
7
  # See the Github documentation for full examples.
8
8
  class Response
9
- # All responses have a payload and a code corresponding to http, though
9
+ # All responses have a payload and a status corresponding to http, though
10
10
  # slightly different
11
- attr_accessor :body, :code
11
+ attr_accessor :body, :status, :code
12
12
 
13
- ResponseHash = Struct.new(:body, :code)
13
+ ResponseHash = Struct.new(:body, :status)
14
14
  def self.from_hash(h)
15
15
  # Create a "fake" response object with the data passed from h
16
- self.new ResponseHash.new(h[:body], h[:code])
16
+ self.new ResponseHash.new(h[:body], h[:status])
17
17
  end
18
18
 
19
19
  def initialize(response)
20
20
  @body = response.body
21
- @code = response.code
21
+ @status = response.status
22
+ @code = response.status
22
23
  end
23
24
 
24
25
  # Return response as Ruby Hash
@@ -57,12 +58,12 @@ module Mailgun
57
58
  rescue => err
58
59
  raise ParseError.new(err), err
59
60
  end
60
-
61
- # Returns true if response code is 2xx
62
- #
63
- # @return [Boolean] A boolean that binarizes the response code result.
61
+
62
+ # Returns true if response status is 2xx
63
+ #
64
+ # @return [Boolean] A boolean that binarizes the response status result.
64
65
  def success?
65
- (200..299).include?(code)
66
+ (200..299).include?(status)
66
67
  end
67
68
  end
68
69
  end
@@ -1,4 +1,4 @@
1
1
  # It's the version. Yeay!
2
2
  module Mailgun
3
- VERSION = '1.2.15'
3
+ VERSION = '1.3.5'
4
4
  end
data/lib/mailgun.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'tempfile'
2
- require 'rest_client'
2
+ require 'faraday'
3
3
  require 'yaml'
4
4
  require 'json'
5
5
 
@@ -18,6 +18,7 @@ require 'mailgun/webhooks/webhooks'
18
18
  require 'mailgun/templates/templates'
19
19
  require 'mailgun/subaccounts/subaccounts'
20
20
  require 'mailgun/tags/tags'
21
+ require 'mailgun/metrics/metrics'
21
22
 
22
23
  # Module for interacting with the sweet Mailgun API.
23
24
  #
data/mailgun.gemspec CHANGED
@@ -28,13 +28,16 @@ Gem::Specification.new do |spec|
28
28
  spec.required_ruby_version = '>= 2.2.2'
29
29
 
30
30
  spec.add_development_dependency 'bundler', '>= 1.16.2'
31
- spec.add_development_dependency 'rspec', '~> 3.8.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.13.0'
32
+ spec.add_development_dependency 'rspec-its', '~> 2.0.0'
32
33
  spec.add_development_dependency 'rake', '~> 12.3.2'
33
34
  spec.add_development_dependency 'webmock', '~> 3.7'
34
- spec.add_development_dependency 'pry', '~> 0.11.3'
35
+ spec.add_development_dependency 'pry', '~> 0.15.2'
35
36
  spec.add_development_dependency 'vcr', '~> 3.0.3'
36
37
  spec.add_development_dependency 'simplecov', '~> 0.16.1'
37
38
  spec.add_development_dependency 'rails'
38
- spec.add_dependency 'rest-client', '>= 2.0.2'
39
+ spec.add_dependency 'mime-types'
40
+ spec.add_dependency 'faraday', "~> 2.1"
41
+ spec.add_dependency 'faraday-multipart', '~> 1.1.0'
39
42
 
40
43
  end
@@ -4,54 +4,67 @@ require 'mailgun'
4
4
  vcr_opts = { :cassette_name => "domains" }
5
5
 
6
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
7
+ let(:api_version) { APIVERSION }
8
+ let(:mg_client) { Mailgun::Client.new(APIKEY, APIHOST, api_version, SSL) }
9
+ let(:mg_obj) { Mailgun::Domains.new(mg_client) }
10
+ let(:domain) { 'integration-test.domain.invalid' }
11
+
12
+ describe '#add_domain' do
13
+ let(:api_version) { 'v4' }
12
14
 
13
- it 'creates the domain' do
14
- result = @mg_obj.add_domain(@domain, { smtp_password: 'super_secret', spam_action: 'tag' })
15
+ it 'creates a domain' do
16
+ response = mg_obj.add_domain(domain, { spam_action: 'tag' })
15
17
 
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")
18
+ expect(response['domain']['name']).to eq(domain)
19
+ expect(response['domain']['spam_action']).to eq('tag')
20
+ end
19
21
  end
20
22
 
21
- it 'get the domain.' do
22
- result = @mg_obj.get(@domain)
23
+ describe '#get' do
24
+ let(:api_version) { 'v4' }
25
+
26
+ it 'returns the domain' do
27
+ response = mg_obj.get(domain)
23
28
 
24
- expect(result).to include("domain")
25
- expect(result["domain"]["name"]).to eq(@domain)
29
+ expect(response).to include('domain')
30
+ expect(response['domain']['name']).to eq(domain)
31
+ end
26
32
  end
27
33
 
28
- it 'gets a list of domains.' do
29
- result = @mg_obj.get_domains
34
+ describe '#get_domains' do
35
+ let(:api_version) { 'v4' }
36
+
37
+ it 'returns a list of domains' do
38
+ response = mg_obj.get_domains
30
39
 
31
- expect(result.size).to be > 0
40
+ expect(response.size).to be > 0
41
+ end
32
42
  end
33
43
 
34
- it 'deletes a domain.' do
35
- result = @mg_obj.delete(@domain)
44
+ context '#update' do
45
+ let(:api_version) { 'v4' }
36
46
 
37
- expect(result).to be_truthy
47
+ it 'updates the domain' do
48
+ response = mg_obj.update(domain, { spam_action: 'block', web_scheme: 'https', wildcard: true })
49
+
50
+ expect(response['domain']['spam_action']).to eq('block')
51
+ expect(response['domain']['web_scheme']).to eq('https')
52
+ expect(response['domain']['wildcard']).to eq(true)
53
+ end
38
54
  end
39
55
 
40
- it 'updates the domain' do
41
- result = @mg_obj.update(@domain, { spam_action: 'block', web_scheme: 'https', wildcard: true })
56
+ context 'delete a domain' do
57
+ subject(:response) { mg_obj.delete(domain) }
42
58
 
43
- expect(result['domain']["spam_action"]).to eq('block')
44
- expect(result['domain']["web_scheme"]).to eq('https')
45
- expect(result['domain']["wildcard"]).to eq(true)
59
+ it { is_expected.to be_falsey }
46
60
  end
47
61
 
48
62
  describe '#create_smtp_credentials' do
49
63
  it 'creates smtp credentials for domain' do
50
- result = @mg_obj.create_smtp_credentials(
51
- @domain,
64
+ result = mg_obj.create_smtp_credentials(
65
+ domain,
52
66
  {
53
- login: 'test_login',
54
- password: 'test_password'
67
+ login: 'test_login'
55
68
  }
56
69
  )
57
70
 
@@ -61,11 +74,11 @@ describe 'For the domains endpoint', vcr: vcr_opts do
61
74
 
62
75
  describe '#update_smtp_credentials' do
63
76
  it 'updates smtp credentials for domain' do
64
- result = @mg_obj.update_smtp_credentials(
65
- @domain,
77
+ result = mg_obj.update_smtp_credentials(
78
+ domain,
66
79
  'test_login',
67
80
  {
68
- password: 'test_password2'
81
+ spec: 'abc'
69
82
  }
70
83
  )
71
84
 
@@ -75,19 +88,8 @@ describe 'For the domains endpoint', vcr: vcr_opts do
75
88
 
76
89
  describe '#delete_smtp_credentials' do
77
90
  it 'deletes smtp credentials for domain' do
78
- result = @mg_obj.delete_smtp_credentials(
79
- @domain,
80
- 'test_login'
81
- )
82
-
83
- expect(result['message']).to eq('Credentials have been deleted')
84
- end
85
- end
86
-
87
- describe '#delete_smtp_credentials' do
88
- it 'deletes smtp credentials for domain' do
89
- result = @mg_obj.delete_smtp_credentials(
90
- @domain,
91
+ result = mg_obj.delete_smtp_credentials(
92
+ domain,
91
93
  'test_login'
92
94
  )
93
95
 
@@ -97,8 +99,8 @@ describe 'For the domains endpoint', vcr: vcr_opts do
97
99
 
98
100
  describe '#get_domain_connection_settings' do
99
101
  it 'returns delivery connection settings for the defined domain' do
100
- result = @mg_obj.get_domain_connection_settings(
101
- @domain
102
+ result = mg_obj.get_domain_connection_settings(
103
+ domain
102
104
  )
103
105
 
104
106
  expect(result).to include(
@@ -110,8 +112,8 @@ describe 'For the domains endpoint', vcr: vcr_opts do
110
112
 
111
113
  describe '#update_domain_connection_settings' do
112
114
  it 'updates the specified delivery connection settings' do
113
- result = @mg_obj.update_domain_connection_settings(
114
- @domain,
115
+ result = mg_obj.update_domain_connection_settings(
116
+ domain,
115
117
  {
116
118
  require_tls: true,
117
119
  skip_verification: true
@@ -127,19 +129,19 @@ describe 'For the domains endpoint', vcr: vcr_opts do
127
129
 
128
130
  describe '#get_domain_tracking_settings' do
129
131
  it 'returns tracking settings for the defined domain' do
130
- result = @mg_obj.get_domain_tracking_settings(
131
- @domain
132
+ result = mg_obj.get_domain_tracking_settings(
133
+ domain
132
134
  )
133
135
 
134
136
  expect(result).to include('tracking')
135
- expect(result['tracking']['click']['active']).to eq(true)
137
+ expect(result['tracking']['click']['active']).to eq(false)
136
138
  end
137
139
  end
138
140
 
139
141
  describe '#update_domain_tracking_open_settings' do
140
142
  it 'updates the specified tracking open settings' do
141
- result = @mg_obj.update_domain_tracking_open_settings(
142
- @domain,
143
+ result = mg_obj.update_domain_tracking_open_settings(
144
+ domain,
143
145
  {
144
146
  active: false
145
147
  }
@@ -151,8 +153,8 @@ describe 'For the domains endpoint', vcr: vcr_opts do
151
153
 
152
154
  describe '#update_domain_tracking_click_settings' do
153
155
  it 'updates the specified tracking click settings' do
154
- result = @mg_obj.update_domain_tracking_click_settings(
155
- @domain,
156
+ result = mg_obj.update_domain_tracking_click_settings(
157
+ domain,
156
158
  {
157
159
  active: false
158
160
  }
@@ -164,8 +166,8 @@ describe 'For the domains endpoint', vcr: vcr_opts do
164
166
 
165
167
  describe '#update_domain_tracking_unsubscribe_settings' do
166
168
  it 'updates the specified tracking unsubscribe settings' do
167
- result = @mg_obj.update_domain_tracking_unsubscribe_settings(
168
- @domain,
169
+ result = mg_obj.update_domain_tracking_unsubscribe_settings(
170
+ domain,
169
171
  {
170
172
  active: false
171
173
  }
@@ -177,34 +179,34 @@ describe 'For the domains endpoint', vcr: vcr_opts do
177
179
 
178
180
  describe '#update_domain_dkim_authority' do
179
181
  it 'updates the DKIM authority for a domain' do
180
- result = @mg_obj.update_domain_dkim_authority(
181
- @domain,
182
+ result = mg_obj.update_domain_dkim_authority(
183
+ domain,
182
184
  {
183
- active: false
185
+ self: true
184
186
  }
185
187
  )
186
188
 
187
- expect(result['message']).to eq('Domain DKIM authority has been changed')
189
+ expect(result['message']).to eq('Domain DKIM authority has not been changed')
188
190
  end
189
191
  end
190
192
 
191
193
  describe '#update_domain_dkim_selector' do
192
194
  it 'updates the DKIM selector for a domain' do
193
- result = @mg_obj.update_domain_dkim_selector(
194
- @domain,
195
+ result = mg_obj.update_domain_dkim_selector(
196
+ domain,
195
197
  {
196
198
  dkim_selector: 'mailo1'
197
199
  }
198
200
  )
199
201
 
200
- expect(result['message']).to eq('Domain DKIM authority changed')
202
+ expect(result['message']).to eq('DKIM selector changed')
201
203
  end
202
204
  end
203
205
 
204
206
  describe '#update_domain_web_prefix' do
205
207
  it 'updates the the CNAME used for tracking opens and clicks' do
206
- result = @mg_obj.update_domain_web_prefix(
207
- @domain,
208
+ result = mg_obj.update_domain_web_prefix(
209
+ domain,
208
210
  {
209
211
  web_prefix: 'email'
210
212
  }
@@ -215,15 +217,12 @@ describe 'For the domains endpoint', vcr: vcr_opts do
215
217
  end
216
218
 
217
219
  describe 'V4' do
218
- before do
219
- @mg_client = Mailgun::Client.new(APIKEY, APIHOST, 'v4', SSL)
220
- @mg_obj = Mailgun::Domains.new(@mg_client)
221
- end
220
+ let(:api_version) { 'v4' }
222
221
 
223
222
  describe '#get_domain_keys' do
224
223
  it 'lists the domain keys for a specified signing domain' do
225
- result = @mg_obj.get_domain_keys(
226
- @domain
224
+ result = mg_obj.get_domain_keys(
225
+ domain
227
226
  )
228
227
 
229
228
  expect(result).to include('items')
@@ -233,9 +232,10 @@ describe 'For the domains endpoint', vcr: vcr_opts do
233
232
 
234
233
  describe '#activate_domain_key' do
235
234
  it 'activates a domain key' do
236
- result = @mg_obj.activate_domain_key(
237
- @domain,
238
- 'smtp'
235
+
236
+ result = mg_obj.activate_domain_key(
237
+ domain,
238
+ 'mailo1'
239
239
  )
240
240
 
241
241
  expect(result['message']).to eq('domain key activated')
@@ -244,11 +244,9 @@ describe 'For the domains endpoint', vcr: vcr_opts do
244
244
 
245
245
  describe '#deactivate_domain_key' do
246
246
  it 'deactivates a domain key' do
247
- result = @mg_obj.deactivate_domain_key(
248
- {
249
- signing_domain: 'x509.zeefarmer.com',
250
- selector: 'tetetet'
251
- }
247
+ result = mg_obj.deactivate_domain_key(
248
+ domain,
249
+ 'tetetet'
252
250
  )
253
251
 
254
252
  expect(result['message']).to eq('domain key deactivated')
@@ -257,15 +255,12 @@ describe 'For the domains endpoint', vcr: vcr_opts do
257
255
  end
258
256
 
259
257
  describe '#delete_domain_key' do
260
- before do
261
- @mg_client = Mailgun::Client.new(APIKEY, APIHOST, 'v1', SSL)
262
- @mg_obj = Mailgun::Domains.new(@mg_client)
263
- end
258
+ let(:api_version) { 'v1' }
264
259
 
265
260
  it 'deletes a domain key' do
266
- result = @mg_obj.delete_domain_key(
261
+ result = mg_obj.delete_domain_key(
267
262
  {
268
- signing_domain: @domain,
263
+ signing_domain: domain,
269
264
  selector: 'test'
270
265
  }
271
266
  )
@@ -276,16 +271,24 @@ describe 'For the domains endpoint', vcr: vcr_opts do
276
271
 
277
272
  describe '#get_domain_stats' do
278
273
  it 'returns total stats for a given domain' do
279
- result = @mg_obj.get_domain_stats(
280
- @domain,
274
+ result = mg_obj.get_domain_stats(
275
+ domain,
281
276
  {
282
- event: 'clicked',
283
- start: 'Sun, 23 Dec 2023 01:23:45 JST',
284
- duration: '24h'
277
+ event: 'clicked'
285
278
  }
286
279
  )
287
280
 
288
281
  expect(result).to include('stats')
289
282
  end
290
283
  end
284
+
285
+ def create_mg_object(version)
286
+ mg_client = Mailgun::Client.new(APIKEY, APIHOST, version, SSL)
287
+ Mailgun::Domains.new(mg_client)
288
+ end
289
+
290
+ def create_domain
291
+ mg_obj = create_mg_object('v4')
292
+ mg_obj.add_domain(domain)
293
+ end
291
294
  end
@@ -16,6 +16,7 @@ describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do
16
16
  end
17
17
 
18
18
  it 'returns parsed and unparsable lists' do
19
+ skip 'is parse method removed?'
19
20
  res = @mg_obj.parse(@all_addrs)
20
21
 
21
22
  expect(res["parsed"]).to eq(@valid)
@@ -58,7 +59,7 @@ describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do
58
59
  "is_role_address" => false,
59
60
  "is_valid" => false,
60
61
  "mailbox_verification" => "unknown",
61
- "reason" => "Validation failed for 'example.org', reason: 'malformed address; missing @ sign'",
62
+ #"reason" => "Validation failed for 'example.org', reason: 'malformed address; missing @ sign'",
62
63
  "parts" => {
63
64
  "display_name" => nil,
64
65
  "domain" => nil,
@@ -6,7 +6,7 @@ vcr_opts = { :cassette_name => "mailing_list" }
6
6
  describe 'For the Mailing Lists endpoint', vcr: vcr_opts do
7
7
  before(:all) do
8
8
  @mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
9
- @domain = TESTDOMAIN
9
+ @domain = TESTDOMAIN || 'DOMAIN.TEST'
10
10
  @ml_address = "integration_test_list@#{@domain}"
11
11
  end
12
12
 
@@ -9,7 +9,7 @@ ActionMailer::Base.raise_delivery_errors = true
9
9
  Rails.logger = Logger.new('/dev/null')
10
10
  Rails.logger.level = Logger::DEBUG
11
11
 
12
- class UnitTestMailer < ActionMailer::Base
12
+ class IntegrationUnitTestMailer < ActionMailer::Base
13
13
  default from: 'unittest@example.org'
14
14
 
15
15
  def plain_message(address, from, subject, headers)
@@ -24,14 +24,14 @@ end
24
24
  vcr_opts = { :cassette_name => 'message_deliver' }
25
25
 
26
26
  describe 'Message deliver', vcr: vcr_opts do
27
- let(:domain) { TESTDOMAIN }
27
+ let(:domain) { TESTDOMAIN || 'DOMAIN.TEST' }
28
28
  let(:config) do
29
29
  {
30
30
  api_key: APIKEY,
31
31
  domain: domain
32
32
  }
33
33
  end
34
- let(:mail) { UnitTestMailer.plain_message("bob@#{domain}", "bob@#{domain}", 'subject', {}) }
34
+ let!(:mail) { IntegrationUnitTestMailer.plain_message("bob@#{domain}", "bob@#{domain}", 'subject', {}) }
35
35
 
36
36
  it 'successfully delivers message' do
37
37
  result = Railgun::Mailer.new(config).deliver!(mail)
@@ -53,9 +53,9 @@ describe 'Invalid domain', vcr: vcr_opts do
53
53
  domain: domain
54
54
  }
55
55
  end
56
- let(:mail) { UnitTestMailer.plain_message('sally@not-our-doma.in', "bob@#{domain}", 'subject', {}) }
56
+ let(:mail) { IntegrationUnitTestMailer.plain_message('sally@not-our-doma.in', "bob@#{domain}", 'subject', {}) }
57
57
 
58
58
  it 'raises expected error' do
59
- expect { Railgun::Mailer.new(config).deliver!(mail) }.to raise_error Mailgun::CommunicationError, /Forbidden/
59
+ expect { Railgun::Mailer.new(config).deliver!(mail) }.to raise_error Mailgun::Unauthorized, /Invalid Domain or API key/
60
60
  end
61
61
  end