mailgun-ruby 1.4.1 → 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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/README.md +1 -1
  4. data/Rakefile +5 -3
  5. data/docs/AnalyticsTags.md +63 -0
  6. data/lib/mailgun/address.rb +5 -5
  7. data/lib/mailgun/chains.rb +2 -3
  8. data/lib/mailgun/client.rb +47 -51
  9. data/lib/mailgun/domains/domains.rb +7 -8
  10. data/lib/mailgun/events/events.rb +4 -3
  11. data/lib/mailgun/exceptions/exceptions.rb +12 -15
  12. data/lib/mailgun/helpers/api_version_checker.rb +6 -1
  13. data/lib/mailgun/lists/opt_in_handler.rb +4 -6
  14. data/lib/mailgun/logs/logs.rb +4 -2
  15. data/lib/mailgun/messages/batch_message.rb +8 -9
  16. data/lib/mailgun/messages/message_builder.rb +36 -24
  17. data/lib/mailgun/metrics/metrics.rb +6 -4
  18. data/lib/mailgun/response.rb +11 -9
  19. data/lib/mailgun/subaccounts/subaccounts.rb +13 -8
  20. data/lib/mailgun/suppressions.rb +36 -43
  21. data/lib/mailgun/tags/analytics_tags.rb +33 -2
  22. data/lib/mailgun/tags/tags.rb +25 -17
  23. data/lib/mailgun/templates/templates.rb +40 -29
  24. data/lib/mailgun/version.rb +3 -1
  25. data/lib/mailgun/webhooks/webhooks.rb +22 -19
  26. data/lib/mailgun-ruby.rb +2 -0
  27. data/lib/mailgun.rb +4 -4
  28. data/lib/railgun/attachment.rb +9 -14
  29. data/lib/railgun/errors.rb +2 -3
  30. data/lib/railgun/mailer.rb +35 -39
  31. data/lib/railgun/railtie.rb +2 -0
  32. data/lib/railgun.rb +2 -0
  33. data/mailgun.gemspec +12 -11
  34. data/spec/integration/analytics_tags_spec.rb +54 -0
  35. data/spec/integration/bounces_spec.rb +12 -11
  36. data/spec/integration/campaign_spec.rb +20 -18
  37. data/spec/integration/complaints_spec.rb +8 -6
  38. data/spec/integration/domains_spec.rb +6 -6
  39. data/spec/integration/email_validation_spec.rb +35 -34
  40. data/spec/integration/events_spec.rb +7 -5
  41. data/spec/integration/list_members_spec.rb +27 -26
  42. data/spec/integration/list_spec.rb +22 -21
  43. data/spec/integration/logs_spec.rb +48 -46
  44. data/spec/integration/mailer_spec.rb +7 -3
  45. data/spec/integration/mailgun_spec.rb +82 -90
  46. data/spec/integration/metrics_spec.rb +130 -130
  47. data/spec/integration/routes_spec.rb +41 -40
  48. data/spec/integration/stats_spec.rb +4 -2
  49. data/spec/integration/subaccounts_spec.rb +9 -10
  50. data/spec/integration/suppressions_spec.rb +21 -20
  51. data/spec/integration/templates_spec.rb +14 -12
  52. data/spec/integration/unsubscribes_spec.rb +8 -6
  53. data/spec/integration/webhook_spec.rb +13 -12
  54. data/spec/spec_helper.rb +8 -8
  55. data/spec/unit/connection/test_client.rb +61 -55
  56. data/spec/unit/events/events_spec.rb +25 -22
  57. data/spec/unit/exceptions/exceptions_spec.rb +8 -7
  58. data/spec/unit/lists/opt_in_handler_spec.rb +8 -6
  59. data/spec/unit/mailgun_spec.rb +64 -63
  60. data/spec/unit/messages/batch_message_spec.rb +15 -15
  61. data/spec/unit/messages/message_builder_spec.rb +98 -94
  62. data/spec/unit/railgun/content_type_spec.rb +24 -23
  63. data/spec/unit/railgun/mailer_spec.rb +58 -58
  64. data/vcr_cassettes/analytics_tags.yml +187 -0
  65. metadata +49 -33
  66. data/.rubocop.yml +0 -8
  67. data/.rubocop_todo.yml +0 -22
@@ -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,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
4
 
3
5
  SimpleCov.start do
4
- add_filter "/spec/"
6
+ add_filter '/spec/'
5
7
  end
6
8
 
7
9
  require 'mailgun'
@@ -10,22 +12,20 @@ require 'vcr'
10
12
  require 'webmock/rspec'
11
13
  require 'rspec/its'
12
14
 
13
- #WebMock.disable_net_connect!(allow_localhost: true)
15
+ # WebMock.disable_net_connect!(allow_localhost: true)
14
16
  require_relative 'unit/connection/test_client'
15
17
 
16
- RSpec.configure do |c|
17
- c.raise_errors_for_deprecations!
18
- end
18
+ RSpec.configure(&:raise_errors_for_deprecations!)
19
19
 
20
- APIHOST = "api.mailgun.net"
21
- APIVERSION = "v3"
20
+ APIHOST = 'api.mailgun.net'
21
+ APIVERSION = 'v3'
22
22
  SSL = true
23
23
 
24
24
  # For integration tests modify .ruby-env.yml
25
25
  # use .ruby-env.yml.example for an example
26
26
  # alternatively
27
27
  # set environment variables as named in .ruby-env.yml.example
28
- envfile = File.join(File.dirname(__FILE__), '..','.ruby-env.yml')
28
+ envfile = File.join(File.dirname(__FILE__), '..', '.ruby-env.yml')
29
29
  envs = File.exist?(envfile) ? YAML.load_file(envfile) : ENV
30
30
  APIKEY = envs['MAILGUN_APIKEY']
31
31
  PUB_APIKEY = envs['MAILGUN_PUB_APIKEY']
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
  require 'json'
3
5
 
4
6
  module Mailgun
5
7
  class UnitClient < Mailgun::Client
6
-
7
8
  attr_reader :options, :block, :body, :code, :response
8
9
 
9
10
  def initialize(endpoint, &block)
@@ -14,9 +15,10 @@ module Mailgun
14
15
  end
15
16
 
16
17
  def [](endpoint, &new_block)
17
- case
18
- when block_given? then self.class.new(endpoint, &new_block)
19
- when block then self.class.new(endpoint, &block)
18
+ if block_given?
19
+ self.class.new(endpoint, &new_block)
20
+ elsif block
21
+ self.class.new(endpoint, &block)
20
22
  else
21
23
  self.class.new(endpoint)
22
24
  end
@@ -26,10 +28,8 @@ module Mailgun
26
28
  perform_data_validation(working_domain, data)
27
29
  case data
28
30
  when Hash
29
- if data.has_key?(:message)
30
- if data[:message].is_a?(String)
31
- data[:message] = convert_string_to_file(data[:message])
32
- end
31
+ if data.key?(:message)
32
+ data[:message] = convert_string_to_file(data[:message]) if data[:message].is_a?(String)
33
33
  post("#{working_domain}/messages.mime", data)
34
34
  else
35
35
  post("#{working_domain}/messages", data)
@@ -37,80 +37,86 @@ module Mailgun
37
37
  when MessageBuilder
38
38
  post("#{working_domain}/messages", data.message)
39
39
  else
40
- raise ParameterError.new("Unknown data type for data parameter.", data)
40
+ raise ParameterError.new('Unknown data type for data parameter.', data)
41
41
  end
42
42
  end
43
43
 
44
- def post(path, data)
45
- begin
46
- Mailgun::Response.new(response_generator(@endpoint))
47
- rescue => e
48
- p e
49
- raise CommunicationError.new(e), e.response if e.respond_to? :response
50
- raise CommunicationError.new(e.message)
51
- end
44
+ def post(_path, _data)
45
+ Mailgun::Response.new(response_generator(@endpoint))
46
+ rescue StandardError => e
47
+ p e
48
+ raise CommunicationError.new(e), e.response if e.respond_to? :response
49
+
50
+ raise CommunicationError, e.message
52
51
  end
53
52
 
54
- def get(path, query_string = nil)
55
- begin
56
- Mailgun::Response.new(response_generator(@endpoint))
57
- rescue => e
58
- raise CommunicationError.new(e), e.response
59
- end
53
+ def get(_path, _query_string = nil)
54
+ Mailgun::Response.new(response_generator(@endpoint))
55
+ rescue StandardError => e
56
+ raise CommunicationError.new(e), e.response
60
57
  end
61
58
 
62
- def put(path, data)
63
- begin
64
- Mailgun::Response.new(response_generator(@endpoint))
65
- rescue => e
66
- raise CommunicationError.new(e), e.response
67
- end
59
+ def put(_path, _data)
60
+ Mailgun::Response.new(response_generator(@endpoint))
61
+ rescue StandardError => e
62
+ raise CommunicationError.new(e), e.response
68
63
  end
69
64
 
70
- def delete(path)
71
- begin
72
- Mailgun::Response.new(response_generator(@endpoint))
73
- rescue => e
74
- raise CommunicationError.new(e), e.response
75
- end
65
+ def delete(_path)
66
+ Mailgun::Response.new(response_generator(@endpoint))
67
+ rescue StandardError => e
68
+ raise CommunicationError.new(e), e.response
76
69
  end
77
70
 
78
71
  private
79
72
 
80
73
  def perform_data_validation(working_domain, data)
81
- fail ParameterError.new('Missing working domain', working_domain) unless working_domain
74
+ raise ParameterError.new('Missing working domain', working_domain) unless working_domain
82
75
  return true unless data.is_a?(Hash) && data.present?
76
+
83
77
  message = data.respond_to?(:message) ? data.message : data
84
78
 
85
- fail ParameterError.new(
86
- 'Missing `to` recipient, message should contain at least 1 recipient',
87
- working_domain
88
- ) if message.fetch('to', []).empty? && message.fetch(:to, []).empty?
89
- fail ParameterError.new(
79
+ if message.fetch('to', []).empty? && message.fetch(:to, []).empty?
80
+ raise ParameterError.new(
81
+ 'Missing `to` recipient, message should contain at least 1 recipient',
82
+ working_domain
83
+ )
84
+ end
85
+ return unless message.fetch('from', []).empty? && message.fetch(:from, []).empty?
86
+
87
+ raise ParameterError.new(
90
88
  'Missing a `from` sender, message should contain at least 1 `from` sender',
91
89
  working_domain
92
- ) if message.fetch('from', []).empty? && message.fetch(:from, []).empty?
90
+ )
93
91
  end
94
92
 
95
93
  def response_generator(resource_endpoint)
96
- if resource_endpoint == "messages"
94
+ if resource_endpoint == 'messages'
97
95
  t = Time.now
98
- id = "<#{t.to_i}.#{rand(99999999)}.5817@example.com>"
99
- return Response.from_hash({ body: JSON.generate({"message" => "Queued. Thank you.", "id" => id}) })
96
+ id = "<#{t.to_i}.#{rand(99_999_999)}.5817@example.com>"
97
+ return Response.from_hash({ body: JSON.generate({ 'message' => 'Queued. Thank you.', 'id' => id }) })
100
98
  end
101
- if resource_endpoint == "bounces"
102
- return Response.from_hash({ body: JSON.generate({"total_count" => 1, "items" => {"created_at" => "Fri, 21 Oct 2011 11:02:55 GMT", "status" => 550, "address" => "baz@example.com", "error" => "Message was not accepted -- invalid mailbox. Local mailbox baz@example.com is unavailable: user not found"}}) })
99
+ if resource_endpoint == 'bounces'
100
+ return Response.from_hash({ body: JSON.generate({ 'total_count' => 1,
101
+ 'items' => { 'created_at' => 'Fri, 21 Oct 2011 11:02:55 GMT', 'status' => 550, 'address' => 'baz@example.com',
102
+ 'error' => 'Message was not accepted -- invalid mailbox. Local mailbox baz@example.com is unavailable: user not found' } }) })
103
103
  end
104
- if resource_endpoint == "lists"
105
- return Response.from_hash({ body: JSON.generate({"member" => {"vars" => {"age" => 26}, "name" => "Foo Bar", "subscribed" => false, "address" => "bar@example.com"}, "message" => "Mailing list member has been updated"}) })
104
+ if resource_endpoint == 'lists'
105
+ return Response.from_hash({ body: JSON.generate({
106
+ 'member' => { 'vars' => { 'age' => 26 }, 'name' => 'Foo Bar', 'subscribed' => false,
107
+ 'address' => 'bar@example.com' }, 'message' => 'Mailing list member has been updated'
108
+ }) })
106
109
  end
107
- if resource_endpoint == "campaigns"
108
- return Response.from_hash({ body: JSON.generate({"message" => "Campaign has been deleted", "id" => "ABC123"}) })
109
- end
110
- if resource_endpoint == "events"
111
- return Response.from_hash({ body: JSON.generate({"items" => [], "paging" => {"next"=> "https://api.mailgun.net/v3/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIFsiZiJdLCBudWxsLCB7ImFjY291bnQuaWQiOiAiNGU4MjMwZjYxNDc2ZDg2NzEzMDBjNDc2IiwgImRvbWFpbi5uYW1lIjogInRoaXNpc2F0ZXN0ZG9tYWluZm9ybWFpbGd1bi5jb20iLCAic2V2ZXJpdHkiOiAiTk9UIGludGVybmFsIn0sIDEwMCwgbnVsbF0=", "previous"=> "https://api.mailgun.net/v2/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDdUMDA6NDU6NTEuNzQxODkyKzAwOjAwIn0sIFsicCIsICJmIl0sIG51bGwsIHsiYWNjb3VudC5pZCI6ICI0ZTgyMzBmNjE0NzZkODY3MTMwMGM0NzYiLCAiZG9tYWluLm5hbWUiOiAidGhpc2lzYXRlc3Rkb21haW5mb3JtYWlsZ3VuLmNvbSIsICJzZXZlcml0eSI6ICJOT1QgaW50ZXJuYWwifSwgMTAwLCBudWxsXQ=="}}) })
110
+ if resource_endpoint == 'campaigns'
111
+ return Response.from_hash({ body: JSON.generate({ 'message' => 'Campaign has been deleted',
112
+ 'id' => 'ABC123' }) })
112
113
  end
114
+ return unless resource_endpoint == 'events'
115
+
116
+ Response.from_hash({ body: JSON.generate({ 'items' => [],
117
+ 'paging' => {
118
+ 'next' => 'https://api.mailgun.net/v3/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIFsiZiJdLCBudWxsLCB7ImFjY291bnQuaWQiOiAiNGU4MjMwZjYxNDc2ZDg2NzEzMDBjNDc2IiwgImRvbWFpbi5uYW1lIjogInRoaXNpc2F0ZXN0ZG9tYWluZm9ybWFpbGd1bi5jb20iLCAic2V2ZXJpdHkiOiAiTk9UIGludGVybmFsIn0sIDEwMCwgbnVsbF0=', 'previous' => 'https://api.mailgun.net/v2/thisisatestdomainformailgun.com/events/W3siYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDVUMDA6NDU6NTEuNzQwOTgzKzAwOjAwIn0sIHsiYiI6ICIyMDE0LTA1LTA3VDAwOjQ1OjUxLjc0MDg5MiswMDowMCIsICJlIjogIjIwMTQtMDUtMDdUMDA6NDU6NTEuNzQxODkyKzAwOjAwIn0sIFsicCIsICJmIl0sIG51bGwsIHsiYWNjb3VudC5pZCI6ICI0ZTgyMzBmNjE0NzZkODY3MTMwMGM0NzYiLCAiZG9tYWluLm5hbWUiOiAidGhpc2lzYXRlc3Rkb21haW5mb3JtYWlsZ3VuLmNvbSIsICJzZXZlcml0eSI6ICJOT1QgaW50ZXJuYWwifSwgMTAwLCBudWxsXQ=='
119
+ } }) })
113
120
  end
114
121
  end
115
-
116
122
  end
@@ -1,31 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'The method get' do
4
6
  it 'should return a proper hash of log data.' do
5
7
  @mg_obj = Mailgun::UnitClient.new('events')
6
- events = Mailgun::Events.new(@mg_obj, "samples.mailgun.org")
7
- result = events.get()
8
+ events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
9
+ result = events.get
8
10
 
9
- expect(result.body).to include("items")
10
- expect(result.body).to include("paging")
11
+ expect(result.body).to include('items')
12
+ expect(result.body).to include('paging')
11
13
  end
12
14
  end
13
15
 
14
16
  describe 'Pagination' do
15
17
  it 'should return a proper hash of log data.' do
16
18
  @mg_obj = Mailgun::UnitClient.new('events')
17
- events = Mailgun::Events.new(@mg_obj, "samples.mailgun.org")
18
- result = events.get()
19
+ events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
20
+ result = events.get
19
21
 
20
22
  json = JSON.parse(result.body)
21
- expect(json).to include("paging")
22
- expect(json["paging"]).to include("next")
23
- expect(json["paging"]).to include("previous")
23
+ expect(json).to include('paging')
24
+ expect(json['paging']).to include('next')
25
+ expect(json['paging']).to include('previous')
24
26
  end
25
27
 
26
28
  it 'should calculate proper next-page url' do
27
- events = Mailgun::Events.new(@mg_obj, "samples.mailgun.org")
28
- output = events.send(:extract_endpoint_from, '/v3/samples.mailgun.org/events/W3siYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIHsiYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIFsiZiJdLCBudWxsLCBbWyJhY2NvdW50LmlkIiwgIjU4MDUyMTg2NzhmYTE2MTNjNzkwYjUwZiJdLCBbImRvbWFpbi5uYW1lIiwgInNhbmRib3gyOTcwMTUyYWYzZDM0NTU5YmZjN2U3MTcwM2E2Y2YyNC5tYWlsZ3VuLm9yZyJdXSwgMTAwLCBudWxsXQ==')
29
+ events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
30
+ output = events.send(:extract_endpoint_from,
31
+ '/v3/samples.mailgun.org/events/W3siYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIHsiYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIFsiZiJdLCBudWxsLCBbWyJhY2NvdW50LmlkIiwgIjU4MDUyMTg2NzhmYTE2MTNjNzkwYjUwZiJdLCBbImRvbWFpbi5uYW1lIiwgInNhbmRib3gyOTcwMTUyYWYzZDM0NTU5YmZjN2U3MTcwM2E2Y2YyNC5tYWlsZ3VuLm9yZyJdXSwgMTAwLCBudWxsXQ==')
29
32
 
30
33
  expect(output).to eq 'W3siYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIHsiYiI6ICIyMDE3LTA1LTEwVDIwOjA2OjU0LjU3NiswMDowMCIsICJlIjogIjIwMTctMDUtMDhUMjA6MDY6NTQuNTc3KzAwOjAwIn0sIFsiZiJdLCBudWxsLCBbWyJhY2NvdW50LmlkIiwgIjU4MDUyMTg2NzhmYTE2MTNjNzkwYjUwZiJdLCBbImRvbWFpbi5uYW1lIiwgInNhbmRib3gyOTcwMTUyYWYzZDM0NTU5YmZjN2U3MTcwM2E2Y2YyNC5tYWlsZ3VuLm9yZyJdXSwgMTAwLCBudWxsXQ=='
31
34
  end
@@ -34,33 +37,33 @@ end
34
37
  describe 'The method next' do
35
38
  it 'should return the next series of data.' do
36
39
  @mg_obj = Mailgun::UnitClient.new('events')
37
- events = Mailgun::Events.new(@mg_obj, "samples.mailgun.org")
38
- result = events.next()
40
+ events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
41
+ result = events.next
39
42
 
40
- expect(result.body).to include("items")
41
- expect(result.body).to include("paging")
43
+ expect(result.body).to include('items')
44
+ expect(result.body).to include('paging')
42
45
  end
43
46
  end
44
47
 
45
48
  describe 'The method previous' do
46
49
  it 'should return the previous series of data.' do
47
50
  @mg_obj = Mailgun::UnitClient.new('events')
48
- events = Mailgun::Events.new(@mg_obj, "samples.mailgun.org")
49
- result = events.previous()
51
+ events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
52
+ result = events.previous
50
53
 
51
- expect(result.body).to include("items")
52
- expect(result.body).to include("paging")
54
+ expect(result.body).to include('items')
55
+ expect(result.body).to include('paging')
53
56
  end
54
57
  end
55
58
 
56
59
  describe 'The method each' do
57
60
  it 'should iterate over all event items.' do
58
61
  @mg_obj = Mailgun::UnitClient.new('events')
59
- events = Mailgun::Events.new(@mg_obj, "samples.mailgun.org")
62
+ events = Mailgun::Events.new(@mg_obj, 'samples.mailgun.org')
60
63
  # Events from the UnitClient are actually empty.
61
64
  count = 0
62
- events.each do |e|
63
- count = count + 1
65
+ events.each do |_e|
66
+ count += 1
64
67
  end
65
68
 
66
69
  # Better than nothing..
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe Mailgun::CommunicationError do
@@ -9,22 +11,21 @@ RSpec.describe Mailgun::CommunicationError do
9
11
  end.not_to raise_error
10
12
  end
11
13
 
12
- context "when the Response body has an `Error` property" do
13
- it "uses the `Error` property as the API message" do
14
+ context 'when the Response body has an `Error` property' do
15
+ it 'uses the `Error` property as the API message' do
14
16
  subject = described_class.new('Boom!', { status: 401, body: '{"Error":"unauthorized"}' })
15
17
 
16
- expect(subject.message).to eq("Boom!: unauthorized")
18
+ expect(subject.message).to eq('Boom!: unauthorized')
17
19
  end
18
20
  end
19
21
 
20
- context "when the Response body has an `error` property" do
21
- it "uses the `Error` property as the API message" do
22
+ context 'when the Response body has an `error` property' do
23
+ it 'uses the `Error` property as the API message' do
22
24
  subject = described_class.new('Boom!', { status: 401, body: '{"error":"not found"}' })
23
25
 
24
- expect(subject.message).to eq("Boom!: not found")
26
+ expect(subject.message).to eq('Boom!: not found')
25
27
  end
26
28
  end
27
-
28
29
  end
29
30
  end
30
31
  end
@@ -1,22 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'The method generate_hash' do
4
6
  before(:each) do
5
- @mailing_list = "mylist@example.com"
6
- @secret_app_id = "mysupersecretpassword"
7
- @recipient_address = "bob@example.com"
8
- @precalculated_hash = "eyJoIjoiMmY3ZmY1MzFlOGJmMjA0OWNhMTI3ZmU4ZTQyNjZkOTljYzhkMTdk%0AMiIsInAiOiJleUpzSWpvaWJYbHNhWE4wUUdWNFlXMXdiR1V1WTI5dElpd2lj%0AaUk2SW1KdllrQmxlR0Z0Y0d4bExtTnZcbmJTSjlcbiJ9%0A"
7
+ @mailing_list = 'mylist@example.com'
8
+ @secret_app_id = 'mysupersecretpassword'
9
+ @recipient_address = 'bob@example.com'
10
+ @precalculated_hash = 'eyJoIjoiMmY3ZmY1MzFlOGJmMjA0OWNhMTI3ZmU4ZTQyNjZkOTljYzhkMTdk%0AMiIsInAiOiJleUpzSWpvaWJYbHNhWE4wUUdWNFlXMXdiR1V1WTI5dElpd2lj%0AaUk2SW1KdllrQmxlR0Z0Y0d4bExtTnZcbmJTSjlcbiJ9%0A'
9
11
  end
10
12
 
11
13
  it 'generates a web safe hash for the recipient wishing to subscribe' do
12
14
  my_hash = Mailgun::OptInHandler.generate_hash(@mailing_list, @secret_app_id, @recipient_address)
13
-
15
+
14
16
  expect(my_hash).to eq(@precalculated_hash)
15
17
  end
16
18
 
17
19
  it 'generates a web safe hash for the recipient wishing to subscribe' do
18
20
  validate_result = Mailgun::OptInHandler.validate_hash(@secret_app_id, @precalculated_hash)
19
-
21
+
20
22
  expect(validate_result.length).to eq(2)
21
23
  expect(validate_result['recipient_address']).to eq(@recipient_address)
22
24
  expect(validate_result['mailing_list']).to eq(@mailing_list)