mailgun-tracking 0.2.1 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/mailgun/tracking.rb +20 -26
- data/lib/mailgun/tracking/configuration.rb +40 -0
- data/lib/mailgun/tracking/middleware.rb +1 -1
- data/lib/mailgun/tracking/signature.rb +1 -1
- data/lib/mailgun/tracking/version.rb +1 -1
- data/spec/mailgun/tracking/configuration_spec.rb +37 -0
- data/spec/mailgun/tracking_spec.rb +20 -2
- data/spec/spec_helper.rb +4 -4
- metadata +12 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de33c4232c543a5487a5f9726ce816dfed2101fe
|
4
|
+
data.tar.gz: 7526a256204371b3d1582b80c8e8a138c3dd23cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 316b704da6a01bff0504a9e0cca29fc8f1cd47cbbf0f40e7d8a7bc0e94cba53a1ff6c324291a77aa57db9652ae61eeaa72b6a3848ebdbc1cc400e60afc12ac3c
|
7
|
+
data.tar.gz: 3baa76e24da2ddd0f569a1eb020dc1893ec2f2ea63bc216876a1d7401eea6a1f5918dec139aa6875483ac772d0f357ea18d10ac02dcbf2a76531d83754c4de80
|
data/lib/mailgun/tracking.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'mailgun/tracking/configuration'
|
1
2
|
require 'mailgun/tracking/exceptions'
|
2
3
|
require 'mailgun/tracking/listener'
|
3
4
|
require 'mailgun/tracking/middleware'
|
@@ -11,35 +12,28 @@ require 'mailgun/tracking/railtie' if defined?(Rails)
|
|
11
12
|
module Mailgun
|
12
13
|
# Namespace for classes and modules that handle Mailgun Webhooks.
|
13
14
|
module Tracking
|
14
|
-
|
15
|
-
|
16
|
-
class << self
|
17
|
-
# Mailgun API public key.
|
18
|
-
#
|
19
|
-
# @return [String]
|
20
|
-
attr_accessor :api_key
|
21
|
-
|
22
|
-
# Mailgun Webhook API endpoint
|
23
|
-
#
|
24
|
-
# @return [String]
|
25
|
-
attr_accessor :endpoint
|
15
|
+
module_function
|
26
16
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
17
|
+
# Default way to setup Mailgun Tracking.
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# Mailgun::Tracking.configure do |config|
|
21
|
+
# config.api_key = ENV['MAILGUN_API_KEY']
|
22
|
+
# config.endpoint = '/mailgun-tracking'
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# Mailgun::Tracking.configure(api_key: ENV['MAILGUN_API_KEY'], endpoint: '/mailgun-tracking')
|
27
|
+
#
|
28
|
+
# @param [Hash] options the options hash.
|
29
|
+
# @option options [String] :api_key Mailgun API public key.
|
30
|
+
# @option options [String] :endpoint Mailgun Webhook API endpoint.
|
31
|
+
#
|
32
|
+
# @return [void]
|
33
|
+
def configure(options = {}, &block)
|
34
|
+
Configuration.instance.configure(options, &block)
|
37
35
|
end
|
38
36
|
|
39
|
-
self.endpoint = DEFAULT_ENDPOINT
|
40
|
-
|
41
|
-
module_function
|
42
|
-
|
43
37
|
# A Notifier instance.
|
44
38
|
#
|
45
39
|
# @example
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Mailgun
|
4
|
+
module Tracking
|
5
|
+
# Stores configuration information.
|
6
|
+
class Configuration
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
DEFAULT_ENDPOINT = '/mailgun'.freeze
|
10
|
+
|
11
|
+
# Mailgun API public key.
|
12
|
+
#
|
13
|
+
# @return [String]
|
14
|
+
attr_accessor :api_key
|
15
|
+
|
16
|
+
# Mailgun Webhook API endpoint.
|
17
|
+
#
|
18
|
+
# @return [String]
|
19
|
+
attr_accessor :endpoint
|
20
|
+
|
21
|
+
# Initializes a new Configuration object.
|
22
|
+
def initialize
|
23
|
+
@endpoint = DEFAULT_ENDPOINT
|
24
|
+
end
|
25
|
+
|
26
|
+
# Sets configuration information.
|
27
|
+
#
|
28
|
+
# @option options [String] :api_key Mailgun API public key.
|
29
|
+
# @option options [String] :endpoint Mailgun Webhook API endpoint.
|
30
|
+
#
|
31
|
+
# @return [void]
|
32
|
+
def configure(options = {})
|
33
|
+
options.each_pair do |key, value|
|
34
|
+
instance_variable_set("@#{key}", value)
|
35
|
+
end
|
36
|
+
yield(self) if block_given?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -39,7 +39,7 @@ module Mailgun
|
|
39
39
|
# @return [Boolean]
|
40
40
|
def mailgun_tracking_request?
|
41
41
|
return false unless request.post?
|
42
|
-
return false unless request.path ==
|
42
|
+
return false unless request.path == Configuration.instance.endpoint
|
43
43
|
true
|
44
44
|
end
|
45
45
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Mailgun::Tracking::Configuration do
|
4
|
+
subject(:configuration) { described_class.instance }
|
5
|
+
|
6
|
+
it 'always refers to the same instance' do
|
7
|
+
expect(configuration).to eql(described_class.instance)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#configure' do
|
11
|
+
let(:options) do
|
12
|
+
{
|
13
|
+
api_key: 'key-csyaunqpfvy6buznrm9ddyu4y7jakuc6',
|
14
|
+
endpoint: '/new-mailgun-tracking'
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:ensure_configuration_via_options) do
|
19
|
+
configuration.configure(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:ensure_configuration_via_block) do
|
23
|
+
configuration.configure do |config|
|
24
|
+
config.api_key = options[:api_key]
|
25
|
+
config.endpoint = options[:endpoint]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def ensure_expect_to_change_state
|
30
|
+
expect { yield }.to change(configuration, :api_key)
|
31
|
+
.to(options[:api_key]).and change(configuration, :endpoint).to(options[:endpoint])
|
32
|
+
end
|
33
|
+
|
34
|
+
it { ensure_expect_to_change_state { ensure_configuration_via_options } }
|
35
|
+
it { ensure_expect_to_change_state { ensure_configuration_via_block } }
|
36
|
+
end
|
37
|
+
end
|
@@ -2,9 +2,27 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe Mailgun::Tracking do
|
4
4
|
describe '.configure' do
|
5
|
-
|
5
|
+
let(:configuration) { instance_double(Mailgun::Tracking::Configuration) }
|
6
|
+
let(:options) do
|
7
|
+
{
|
8
|
+
api_key: 'key-qblubkqnkdn4lfes5oscf57ryllaia42',
|
9
|
+
endpoint: '/mailgun-tracking'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow(configuration).to receive(:configure)
|
15
|
+
allow(Mailgun::Tracking::Configuration).to receive(:instance) { configuration }
|
16
|
+
end
|
17
|
+
|
18
|
+
it do
|
19
|
+
described_class.configure(options)
|
20
|
+
expect(configuration).to have_received(:configure).with(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'setup block yields Mailgun::Tracking::Configuration' do
|
6
24
|
described_class.configure do |config|
|
7
|
-
expect(
|
25
|
+
expect(config).to eq(Mailgun::Tracking::Configuration.instance)
|
8
26
|
end
|
9
27
|
end
|
10
28
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,13 +9,13 @@ require_relative 'support/shared_examples/subscriber'
|
|
9
9
|
|
10
10
|
SimpleCov.start
|
11
11
|
|
12
|
-
Mailgun::Tracking.configure do |config|
|
13
|
-
config.api_key = 'key-qblubkqnkdn4lfes5oscf57ryllaia42'
|
14
|
-
end
|
15
|
-
|
16
12
|
RSpec.configure do |config|
|
17
13
|
config.include(RackHelpers)
|
18
14
|
|
15
|
+
config.before(:each) do
|
16
|
+
Mailgun::Tracking.configure(api_key: 'key-qblubkqnkdn4lfes5oscf57ryllaia42', endpoint: '/mailgun')
|
17
|
+
end
|
18
|
+
|
19
19
|
config.expect_with :rspec do |c|
|
20
20
|
c.syntax = :expect
|
21
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailgun-tracking
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Chubchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Integration with Mailgun Webhooks
|
14
14
|
email:
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- lib/generators/mailgun/tracking/install_generator.rb
|
21
21
|
- lib/generators/mailgun/tracking/templates/mailgun_tracking.rb.erb
|
22
22
|
- lib/mailgun/tracking.rb
|
23
|
+
- lib/mailgun/tracking/configuration.rb
|
23
24
|
- lib/mailgun/tracking/exceptions.rb
|
24
25
|
- lib/mailgun/tracking/listener.rb
|
25
26
|
- lib/mailgun/tracking/middleware.rb
|
@@ -31,6 +32,7 @@ files:
|
|
31
32
|
- lib/mailgun/tracking/subscriber/evented.rb
|
32
33
|
- lib/mailgun/tracking/version.rb
|
33
34
|
- spec/fixtures/delivered.json
|
35
|
+
- spec/mailgun/tracking/configuration_spec.rb
|
34
36
|
- spec/mailgun/tracking/listener_spec.rb
|
35
37
|
- spec/mailgun/tracking/middleware_spec.rb
|
36
38
|
- spec/mailgun/tracking/notifier_spec.rb
|
@@ -63,21 +65,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
65
|
version: '0'
|
64
66
|
requirements: []
|
65
67
|
rubyforge_project:
|
66
|
-
rubygems_version: 2.
|
68
|
+
rubygems_version: 2.6.12
|
67
69
|
signing_key:
|
68
70
|
specification_version: 4
|
69
71
|
summary: Integration with Mailgun Webhooks
|
70
72
|
test_files:
|
73
|
+
- spec/fixtures/delivered.json
|
74
|
+
- spec/mailgun/tracking/configuration_spec.rb
|
75
|
+
- spec/mailgun/tracking/listener_spec.rb
|
76
|
+
- spec/mailgun/tracking/middleware_spec.rb
|
77
|
+
- spec/mailgun/tracking/notifier_spec.rb
|
71
78
|
- spec/mailgun/tracking/signature_spec.rb
|
72
79
|
- spec/mailgun/tracking/subscriber/all_messages_spec.rb
|
73
80
|
- spec/mailgun/tracking/subscriber/evented_spec.rb
|
74
81
|
- spec/mailgun/tracking/subscriber_spec.rb
|
75
|
-
- spec/mailgun/tracking/listener_spec.rb
|
76
|
-
- spec/mailgun/tracking/notifier_spec.rb
|
77
|
-
- spec/mailgun/tracking/middleware_spec.rb
|
78
82
|
- spec/mailgun/tracking_spec.rb
|
79
|
-
- spec/
|
83
|
+
- spec/spec_helper.rb
|
80
84
|
- spec/support/fixture.rb
|
85
|
+
- spec/support/rack_helpers.rb
|
81
86
|
- spec/support/shared_examples/subscriber.rb
|
82
|
-
- spec/fixtures/delivered.json
|
83
|
-
- spec/spec_helper.rb
|