mailgun-ruby 1.4.0 → 1.4.2

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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +2 -3
  3. data/Gemfile +3 -1
  4. data/README.md +1 -1
  5. data/Rakefile +5 -3
  6. data/docs/AnalyticsTags.md +63 -0
  7. data/docs/Domains.md +71 -18
  8. data/docs/MessageBuilder.md +1 -1
  9. data/lib/mailgun/address.rb +4 -6
  10. data/lib/mailgun/chains.rb +2 -3
  11. data/lib/mailgun/client.rb +71 -60
  12. data/lib/mailgun/domains/domains.rb +10 -96
  13. data/lib/mailgun/events/events.rb +3 -4
  14. data/lib/mailgun/exceptions/exceptions.rb +14 -15
  15. data/lib/mailgun/helpers/api_version_checker.rb +6 -1
  16. data/lib/mailgun/lists/opt_in_handler.rb +3 -8
  17. data/lib/mailgun/logs/logs.rb +3 -3
  18. data/lib/mailgun/messages/batch_message.rb +7 -10
  19. data/lib/mailgun/messages/message_builder.rb +35 -27
  20. data/lib/mailgun/metrics/metrics.rb +5 -5
  21. data/lib/mailgun/response.rb +11 -9
  22. data/lib/mailgun/subaccounts/subaccounts.rb +12 -9
  23. data/lib/mailgun/suppressions.rb +37 -48
  24. data/lib/mailgun/tags/analytics_tags.rb +63 -0
  25. data/lib/mailgun/tags/tags.rb +35 -18
  26. data/lib/mailgun/templates/templates.rb +39 -30
  27. data/lib/mailgun/version.rb +3 -1
  28. data/lib/mailgun/webhooks/webhooks.rb +22 -19
  29. data/lib/mailgun-ruby.rb +4 -2
  30. data/lib/mailgun.rb +37 -21
  31. data/lib/railgun/attachment.rb +9 -14
  32. data/lib/railgun/errors.rb +2 -3
  33. data/lib/railgun/mailer.rb +34 -44
  34. data/lib/railgun/railtie.rb +10 -1
  35. data/lib/railgun.rb +14 -5
  36. data/mailgun.gemspec +15 -14
  37. data/spec/integration/analytics_tags_spec.rb +54 -0
  38. data/spec/integration/bounces_spec.rb +12 -11
  39. data/spec/integration/campaign_spec.rb +20 -18
  40. data/spec/integration/complaints_spec.rb +8 -6
  41. data/spec/integration/domains_spec.rb +220 -194
  42. data/spec/integration/email_validation_spec.rb +35 -34
  43. data/spec/integration/events_spec.rb +7 -5
  44. data/spec/integration/list_members_spec.rb +27 -26
  45. data/spec/integration/list_spec.rb +22 -21
  46. data/spec/integration/logs_spec.rb +48 -46
  47. data/spec/integration/mailer_spec.rb +7 -3
  48. data/spec/integration/mailgun_spec.rb +82 -90
  49. data/spec/integration/metrics_spec.rb +130 -130
  50. data/spec/integration/routes_spec.rb +41 -40
  51. data/spec/integration/stats_spec.rb +4 -2
  52. data/spec/integration/subaccounts_spec.rb +9 -10
  53. data/spec/integration/suppressions_spec.rb +21 -20
  54. data/spec/integration/templates_spec.rb +14 -12
  55. data/spec/integration/unsubscribes_spec.rb +8 -6
  56. data/spec/integration/webhook_spec.rb +13 -12
  57. data/spec/spec_helper.rb +8 -12
  58. data/spec/unit/connection/test_client.rb +61 -55
  59. data/spec/unit/events/events_spec.rb +25 -22
  60. data/spec/unit/exceptions/exceptions_spec.rb +8 -7
  61. data/spec/unit/lists/opt_in_handler_spec.rb +8 -6
  62. data/spec/unit/mailgun_spec.rb +64 -63
  63. data/spec/unit/messages/batch_message_spec.rb +15 -15
  64. data/spec/unit/messages/message_builder_spec.rb +98 -94
  65. data/spec/unit/railgun/content_type_spec.rb +24 -23
  66. data/spec/unit/railgun/mailer_spec.rb +58 -58
  67. data/vcr_cassettes/analytics_tags.yml +187 -0
  68. data/vcr_cassettes/domains.yml +152 -0
  69. metadata +73 -46
  70. data/.rubocop.yml +0 -8
  71. data/.rubocop_todo.yml +0 -22
  72. data/lib/railgun/message.rb +0 -18
  73. data/spec/integration/tags.rb +0 -139
  74. data/vcr_cassettes/tags.yml +0 -417
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'mailgun'
3
5
 
4
- vcr_opts = { :cassette_name => "routes", :match_requests_on => [:uri, :method, :body] }
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("routes", { priority: 10,
16
- description: 'Integration Test Route',
17
- expression: "match_recipient(\"#{@forward_to}\")",
18
- action: "forward(\"#{@recipient}\")" })
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["message"]).to eq("Route has been created")
22
- expect(result.body["route"]["description"]).to eq("Integration Test Route")
23
- expect(result.body["route"]["actions"]).to include("forward(\"#{@recipient}\")")
24
- expect(result.body["route"]["expression"]).to include("match_recipient(\"#{@forward_to}\")")
25
- expect(result.body["route"]["priority"]).to eq(10)
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("routes", { priority: 10,
30
- description: 'Integration Test Route',
31
- expression: "match_recipient(\"#{@forward_to}\")",
32
- action: ["forward(\"#{@recipient}\")", "stop()"] })
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["message"]).to eq("Route has been created")
36
- expect(result.body["route"]["description"]).to eq("Integration Test Route")
37
- expect(result.body["route"]["actions"].count).to eq 2
38
- expect(result.body["route"]["actions"][0]).to include("forward(\"#{@recipient}\")")
39
- expect(result.body["route"]["actions"][1]).to include("stop()")
40
- expect(result.body["route"]["expression"]).to include("match_recipient(\"#{@forward_to}\")")
41
- expect(result.body["route"]["priority"]).to eq(10)
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("routes", {:limit => 50})
47
+ result = @mg_obj.get('routes', { limit: 50 })
46
48
 
47
49
  result.to_h!
48
- expect(result.body["total_count"]).to be > 0
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("routes", {:limit => 1})
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["route"]["description"]).to eq("Integration Test Route")
59
- expect(result.body["route"]["actions"]).to include("forward(\"#{@recipient}\")")
60
- expect(result.body["route"]["expression"]).to include("match_recipient(\"#{@forward_to}\")")
61
- expect(result.body["route"]["priority"]).to eq(10)
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("routes", {:limit => 1})
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}", {:priority => 10,
69
- :description => 'Integration Test Route Update',
70
- :expression => "match_recipient(\"#{@forward_to}\")",
71
- :action => "forward(\"#{@recipient}\")"})
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["message"]).to eq("Route has been updated")
75
- expect(result.body["description"]).to eq("Integration Test Route Update")
76
- expect(result.body["actions"]).to include("forward(\"#{@recipient}\")")
77
- expect(result.body["expression"]).to include("match_recipient(\"#{@forward_to}\")")
78
- expect(result.body["priority"]).to eq(10)
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("routes", {:limit => 1})
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 = { :cassette_name => "stats" }
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", {:limit => 50, :skip => 10, :event => 'sent'})
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 = { :cassette_name => "subaccounts" }
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({"subaccounts"=>[{"id"=>"xxx", "name"=>"test-ruby-lib", "status"=>"open"}], "total"=>1})
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({"subaccount"=>{"id"=>"xxx", "name"=>"test.subaccount", "status"=>"open"}})
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({"subaccount"=>{"id"=>"xxx", "name"=>"test-ruby-lib", "status"=>"open"}})
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({"subaccount"=>{"id"=>"xxx", "name"=>"test-ruby-lib", "status"=>"open"}})
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({"subaccount"=>{"id"=>"xxx", "name"=>"test-ruby-lib", "status"=>"disabled"}})
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,12 +1,13 @@
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 = { :cassette_name => 'suppressions' }
8
+ vcr_opts = { cassette_name: 'suppressions' }
7
9
 
8
10
  describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts do
9
-
10
11
  before(:all) do
11
12
  @mg_obj = Mailgun::Client.new(APIKEY)
12
13
  @suppress = Mailgun::Suppressions.new(@mg_obj, TESTDOMAIN)
@@ -18,10 +19,10 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
18
19
  bounces = []
19
20
  @addresses.each do |addr|
20
21
  bounces.push({
21
- :address => addr,
22
- :code => 500,
23
- :error => 'integration testing',
24
- })
22
+ address: addr,
23
+ code: 500,
24
+ error: 'integration testing'
25
+ })
25
26
  end
26
27
 
27
28
  response, nested = @suppress.create_bounces bounces
@@ -35,9 +36,9 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
35
36
  it 'raises ParameterError if no bounce[:address] is present' do
36
37
  bounces = []
37
38
  bounces.push({
38
- :code => 500,
39
- :error => 'integration testing',
40
- })
39
+ code: 500,
40
+ error: 'integration testing'
41
+ })
41
42
 
42
43
  expect { @suppress.create_bounces bounces }.to raise_error(Mailgun::ParameterError)
43
44
  end
@@ -56,9 +57,9 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
56
57
  unsubscribes = []
57
58
  @addresses.each do |addr|
58
59
  unsubscribes.push({
59
- :address => addr,
60
- :tag => 'integration',
61
- })
60
+ address: addr,
61
+ tag: 'integration'
62
+ })
62
63
  end
63
64
 
64
65
  response, nested = @suppress.create_unsubscribes unsubscribes
@@ -73,9 +74,9 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
73
74
  unsubscribes = []
74
75
  @addresses.each do |addr|
75
76
  unsubscribes.push({
76
- :address => addr,
77
- :tags => ['integration'],
78
- })
77
+ address: addr,
78
+ tags: ['integration']
79
+ })
79
80
  end
80
81
 
81
82
  response, nested = @suppress.create_unsubscribes unsubscribes
@@ -89,8 +90,8 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
89
90
  it 'raises ParameterError if no unsubscribe[:address] is present' do
90
91
  unsubscribes = []
91
92
  unsubscribes.push({
92
- :tag => 'integration',
93
- })
93
+ tag: 'integration'
94
+ })
94
95
 
95
96
  expect { @suppress.create_unsubscribes unsubscribes }.to raise_error(Mailgun::ParameterError)
96
97
  end
@@ -108,7 +109,7 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
108
109
  it 'can batch-add complaints' do
109
110
  complaints = []
110
111
  @addresses.each do |addr|
111
- complaints.push :address => addr
112
+ complaints.push address: addr
112
113
  end
113
114
 
114
115
  response, nested = @suppress.create_complaints complaints
@@ -122,8 +123,8 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
122
123
  it 'raises ParameterError if no complaint[:address] is present' do
123
124
  complaints = []
124
125
  complaints.push({
125
- :tag => 'integration',
126
- })
126
+ tag: 'integration'
127
+ })
127
128
 
128
129
  expect { @suppress.create_complaints complaints }.to raise_error(Mailgun::ParameterError)
129
130
  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 = { :cassette_name => "templates" }
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) { "integration-test.domain.invalid" }
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
- comment: 'test comment',
25
- headers: '{"Subject": "{{subject}}"}',
26
- tag: 'V1'
26
+ comment: 'test comment',
27
+ headers: '{"Subject": "{{subject}}"}',
28
+ tag: 'V1'
27
29
  }
28
30
  )
29
31
 
30
- expect(result['template']["name"]).to eq('test.template')
31
- expect(result['template']["description"]).to eq("Test")
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("template")
40
- expect(result["template"]["name"]).to eq(template_name)
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']["version"]['tag']).to eq(tag)
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["template"]["version"]['tag']).to eq(tag)
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["template"]["versions"].first).to include('tag')
126
+ expect(result['template']['versions'].first).to include('tag')
125
127
  end
126
128
  end
127
129
 
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'mailgun'
3
5
 
4
- vcr_opts = { :cassette_name => "unsubscribes" }
6
+ vcr_opts = { cassette_name: 'unsubscribes' }
5
7
 
6
8
  describe 'For the Unsubscribes endpoint', order: :defined, vcr: vcr_opts do
7
9
  before(:all) do
@@ -14,22 +16,22 @@ describe 'For the Unsubscribes endpoint', order: :defined, vcr: vcr_opts do
14
16
  result = @mg_obj.post "#{@domain}/unsubscribes", address: @email, tag: '*'
15
17
 
16
18
  result.to_h!
17
- expect(result.body["message"]).to eq("Address has been added to the unsubscribes table")
18
- expect(result.body["address"]).to eq(@email)
19
+ expect(result.body['message']).to eq('Address has been added to the unsubscribes table')
20
+ expect(result.body['address']).to eq(@email)
19
21
  end
20
22
 
21
23
  it 'get an unsubscribee.' do
22
24
  result = @mg_obj.get "#{@domain}/unsubscribes/#{@email}"
23
25
 
24
26
  result.to_h!
25
- expect(result.body["address"]).to eq(@email)
27
+ expect(result.body['address']).to eq(@email)
26
28
  end
27
29
 
28
30
  it 'gets a list of unsubscribes.' do
29
31
  result = @mg_obj.get "#{@domain}/unsubscribes"
30
32
 
31
33
  result.to_h!
32
- expect(result.body["items"].length).to be > 0
34
+ expect(result.body['items'].length).to be > 0
33
35
  end
34
36
 
35
37
  it 'removes an unsubscribee' do
@@ -37,6 +39,6 @@ describe 'For the Unsubscribes endpoint', order: :defined, vcr: vcr_opts do
37
39
 
38
40
  result.to_h!
39
41
  expect(result.body['address']).to eq(@email)
40
- expect(result.body["message"]).to eq("Unsubscribe event has been removed")
42
+ expect(result.body['message']).to eq('Unsubscribe event has been removed')
41
43
  end
42
44
  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 = { :cassette_name => "webhooks" }
6
+ vcr_opts = { cassette_name: 'webhooks' }
5
7
 
6
8
  describe 'For the webhooks endpoint', order: :defined, vcr: vcr_opts do
7
9
  before(:all) do
@@ -13,42 +15,41 @@ describe 'For the webhooks endpoint', order: :defined, vcr: vcr_opts do
13
15
 
14
16
  it 'creates a webhook' do
15
17
  result = @mg_obj.post("domains/#{@domain}/webhooks", { id: @testhook,
16
- url: "http://example.com/mailgun/events/#{@testhook}" } )
18
+ url: "http://example.com/mailgun/events/#{@testhook}" })
17
19
 
18
20
  result.to_h!
19
- expect(result.body["message"]).to eq("Webhook has been created")
20
- expect(result.body["webhook"]["urls"]).to include("http://example.com/mailgun/events/#{@testhook}")
21
+ expect(result.body['message']).to eq('Webhook has been created')
22
+ expect(result.body['webhook']['urls']).to include("http://example.com/mailgun/events/#{@testhook}")
21
23
  end
22
24
 
23
25
  it 'gets a webhook.' do
24
26
  result = @mg_obj.get("domains/#{@domain}/webhooks/#{@testhook}")
25
27
 
26
28
  result.to_h!
27
- expect(result.body["webhook"]["urls"]).to include("http://example.com/mailgun/events/#{@testhook}")
29
+ expect(result.body['webhook']['urls']).to include("http://example.com/mailgun/events/#{@testhook}")
28
30
  end
29
31
 
30
32
  it 'gets a list of all webhooks.' do
31
33
  result = @mg_obj.get("domains/#{@domain}/webhooks")
32
34
 
33
35
  result.to_h!
34
- expect(result.body["webhooks"]["accepted"]["urls"]).to include("http://example.com/mailgun/events/#{@testhook}")
36
+ expect(result.body['webhooks']['accepted']['urls']).to include("http://example.com/mailgun/events/#{@testhook}")
35
37
  end
36
38
 
37
39
  it 'updates a webhook.' do
38
- result = @mg_obj.put("domains/#{@domain}/webhooks/#{@testhook}", {:id => @testhook,
39
- :url => "http://example.com/mailgun/events/#{@testhookup}"})
40
+ result = @mg_obj.put("domains/#{@domain}/webhooks/#{@testhook}", { id: @testhook,
41
+ url: "http://example.com/mailgun/events/#{@testhookup}" })
40
42
 
41
43
  result.to_h!
42
- expect(result.body["message"]).to eq("Webhook has been updated")
43
- expect(result.body["webhook"]["urls"]).to include("http://example.com/mailgun/events/#{@testhookup}")
44
+ expect(result.body['message']).to eq('Webhook has been updated')
45
+ expect(result.body['webhook']['urls']).to include("http://example.com/mailgun/events/#{@testhookup}")
44
46
  end
45
47
 
46
48
  it 'removes a webhook' do
47
49
  result = @mg_obj.delete("domains/#{@domain}/webhooks/#{@testhook}")
48
50
 
49
51
  result.to_h!
50
- expect(result.body['message']).to eq("Webhook has been deleted")
52
+ expect(result.body['message']).to eq('Webhook has been deleted')
51
53
  expect(result.body['webhook']['urls']).to include("http://example.com/mailgun/events/#{@testhookup}")
52
54
  end
53
-
54
55
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,9 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- require 'bundler/setup'
4
- Bundler.setup(:development)
1
+ # frozen_string_literal: true
5
2
 
6
3
  require 'simplecov'
4
+
7
5
  SimpleCov.start do
8
- add_filter "/spec/"
6
+ add_filter '/spec/'
9
7
  end
10
8
 
11
9
  require 'mailgun'
@@ -14,22 +12,20 @@ require 'vcr'
14
12
  require 'webmock/rspec'
15
13
  require 'rspec/its'
16
14
 
17
- #WebMock.disable_net_connect!(allow_localhost: true)
15
+ # WebMock.disable_net_connect!(allow_localhost: true)
18
16
  require_relative 'unit/connection/test_client'
19
17
 
20
- RSpec.configure do |c|
21
- c.raise_errors_for_deprecations!
22
- end
18
+ RSpec.configure(&:raise_errors_for_deprecations!)
23
19
 
24
- APIHOST = "api.mailgun.net"
25
- APIVERSION = "v3"
20
+ APIHOST = 'api.mailgun.net'
21
+ APIVERSION = 'v3'
26
22
  SSL = true
27
23
 
28
24
  # For integration tests modify .ruby-env.yml
29
25
  # use .ruby-env.yml.example for an example
30
26
  # alternatively
31
27
  # set environment variables as named in .ruby-env.yml.example
32
- envfile = File.join(File.dirname(__FILE__), '..','.ruby-env.yml')
28
+ envfile = File.join(File.dirname(__FILE__), '..', '.ruby-env.yml')
33
29
  envs = File.exist?(envfile) ? YAML.load_file(envfile) : ENV
34
30
  APIKEY = envs['MAILGUN_APIKEY']
35
31
  PUB_APIKEY = envs['MAILGUN_PUB_APIKEY']