mailgun-tracking 0.2.3 → 0.2.4
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/generators/mailgun/tracking/install_generator.rb +1 -1
- data/lib/mailgun/tracking.rb +21 -17
- data/lib/mailgun/tracking/configuration.rb +0 -13
- data/lib/mailgun/tracking/notifier.rb +7 -0
- data/lib/mailgun/tracking/version.rb +48 -1
- data/spec/mailgun/tracking/configuration_spec.rb +0 -28
- data/spec/mailgun/tracking/listener_spec.rb +1 -1
- data/spec/mailgun/tracking/notifier_spec.rb +16 -0
- data/spec/mailgun/tracking/version_spec.rb +27 -0
- data/spec/mailgun/tracking_spec.rb +18 -16
- data/spec/spec_helper.rb +5 -2
- metadata +16 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef73193085f12611cf7f9c32ac0899a1ae957fda
|
4
|
+
data.tar.gz: 0e9985c4fd7f5e3141369b0a0570f469d924c3cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1fe1de3a718c8305736d3761549e970af99203f753285ca660a88483e6a48a2c5ba025e95e696b602cf07da9568c05a9c6055923cbfb15a6626971f46e34731
|
7
|
+
data.tar.gz: fd581cea2524c5ac9abd56439f01607d71d55aeae088db1feaf4eaef907aec6259f752263f5b9bfcc5f3627aedfcc49b36dae0e5d4fe708108aea64337cd36a1
|
@@ -5,7 +5,7 @@ module Mailgun
|
|
5
5
|
# @example Invokation from terminal
|
6
6
|
# rails generate mailgun:tracking:install API_KEY ENDPOINT
|
7
7
|
class InstallGenerator < Rails::Generators::Base
|
8
|
-
source_root File.expand_path('
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
9
9
|
|
10
10
|
argument :api_key, required: false
|
11
11
|
argument :endpoint, required: false
|
data/lib/mailgun/tracking.rb
CHANGED
@@ -20,24 +20,7 @@ module Mailgun
|
|
20
20
|
# Mailgun::Tracking.configure do |config|
|
21
21
|
# config.api_key = ENV['MAILGUN_API_KEY']
|
22
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)
|
35
|
-
end
|
36
|
-
|
37
|
-
# A Notifier instance.
|
38
23
|
#
|
39
|
-
# @example
|
40
|
-
# Mailgun::Tracking.configure do |config|
|
41
24
|
# config.notifier.subscribe :delivered do |payload|
|
42
25
|
# # Do something with the incoming data.
|
43
26
|
# end
|
@@ -49,9 +32,30 @@ module Mailgun
|
|
49
32
|
# end
|
50
33
|
# end
|
51
34
|
#
|
35
|
+
# @return [void]
|
36
|
+
def configure
|
37
|
+
yield(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
# A Notifier instance.
|
41
|
+
#
|
52
42
|
# @return [Mailgun::Tracking::Notifier]
|
53
43
|
def notifier
|
54
44
|
@notifier ||= Notifier.new
|
55
45
|
end
|
46
|
+
|
47
|
+
# Delegate other missing methods to configuration.
|
48
|
+
def method_missing(method_name, *arguments, &block)
|
49
|
+
if Configuration.instance.respond_to?(method_name)
|
50
|
+
Configuration.instance.public_send(method_name, *arguments, &block)
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Replaces the Object.respond_to?() method.
|
57
|
+
def respond_to_missing?(method_name, include_private = false)
|
58
|
+
Configuration.instance.respond_to?(method_name) || super
|
59
|
+
end
|
56
60
|
end
|
57
61
|
end
|
@@ -22,19 +22,6 @@ module Mailgun
|
|
22
22
|
def initialize
|
23
23
|
@endpoint = DEFAULT_ENDPOINT
|
24
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
25
|
end
|
39
26
|
end
|
40
27
|
end
|
@@ -11,6 +11,13 @@ module Mailgun
|
|
11
11
|
@listener ||= listener
|
12
12
|
end
|
13
13
|
|
14
|
+
# Returns true if there is at least one subscriber.
|
15
|
+
#
|
16
|
+
# @return [Boolean]
|
17
|
+
def empty?
|
18
|
+
listener.subscribers.empty?
|
19
|
+
end
|
20
|
+
|
14
21
|
# Adds subscriber for the specified event.
|
15
22
|
#
|
16
23
|
# @param event [Symbol, String] The name of event.
|
@@ -1,5 +1,52 @@
|
|
1
1
|
module Mailgun
|
2
2
|
module Tracking
|
3
|
-
|
3
|
+
# This module holds the Mailgun Tracking version information.
|
4
|
+
module Version
|
5
|
+
module_function
|
6
|
+
|
7
|
+
KEYS = %i[major minor patch].freeze
|
8
|
+
|
9
|
+
# Major version.
|
10
|
+
#
|
11
|
+
# @return [Integer]
|
12
|
+
def major
|
13
|
+
0
|
14
|
+
end
|
15
|
+
|
16
|
+
# Minor version.
|
17
|
+
#
|
18
|
+
# @return [Integer]
|
19
|
+
def minor
|
20
|
+
2
|
21
|
+
end
|
22
|
+
|
23
|
+
# Patch version.
|
24
|
+
#
|
25
|
+
# @return [Integer]
|
26
|
+
def patch
|
27
|
+
4
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns a hash representation of version.
|
31
|
+
#
|
32
|
+
# @return [Hash]
|
33
|
+
def to_h
|
34
|
+
Hash[KEYS.zip(to_a)]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns a string representation of version.
|
38
|
+
#
|
39
|
+
# @return [Array]
|
40
|
+
def to_a
|
41
|
+
[major, minor, patch]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns an array representation of version.
|
45
|
+
#
|
46
|
+
# @return [String]
|
47
|
+
def to_s
|
48
|
+
to_a.join('.')
|
49
|
+
end
|
50
|
+
end
|
4
51
|
end
|
5
52
|
end
|
@@ -6,32 +6,4 @@ RSpec.describe Mailgun::Tracking::Configuration do
|
|
6
6
|
it 'always refers to the same instance' do
|
7
7
|
expect(configuration).to eql(described_class.instance)
|
8
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
9
|
end
|
@@ -28,7 +28,7 @@ RSpec.describe Mailgun::Tracking::Listener do
|
|
28
28
|
|
29
29
|
before do
|
30
30
|
allow(subscriber).to receive(:call)
|
31
|
-
allow(subscriber).to receive(:subscribed_to?).with(/delivered/)
|
31
|
+
allow(subscriber).to receive(:subscribed_to?).with(/delivered/).and_return(true)
|
32
32
|
allow(Mailgun::Tracking::Subscriber).to receive(:for).with(:delivered, callable) { subscriber }
|
33
33
|
|
34
34
|
listener.add_subscriber(:delivered, callable)
|
@@ -5,6 +5,22 @@ RSpec.describe Mailgun::Tracking::Notifier do
|
|
5
5
|
|
6
6
|
let(:listener) { instance_double(Mailgun::Tracking::Listener) }
|
7
7
|
|
8
|
+
describe '#empty?' do
|
9
|
+
context 'when there is at least one subscriber' do
|
10
|
+
let(:subscriber) { instance_double(Mailgun::Tracking::Subscriber::AllMessages) }
|
11
|
+
|
12
|
+
before { allow(listener).to receive(:subscribers).and_return([subscriber]) }
|
13
|
+
|
14
|
+
it { is_expected.not_to be_empty }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when there are no subscribers' do
|
18
|
+
before { allow(listener).to receive(:subscribers).and_return([]) }
|
19
|
+
|
20
|
+
it { is_expected.to be_empty }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
8
24
|
describe '#subscribe' do
|
9
25
|
let(:callable) { proc {} }
|
10
26
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Mailgun::Tracking::Version do
|
4
|
+
before do
|
5
|
+
allow(described_class).to receive(:major).and_return(0)
|
6
|
+
allow(described_class).to receive(:minor).and_return(2)
|
7
|
+
allow(described_class).to receive(:patch).and_return(3)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.to_h' do
|
11
|
+
it 'returns a hash representation' do
|
12
|
+
expect(described_class.to_h).to eql(major: 0, minor: 2, patch: 3)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.to_a' do
|
17
|
+
it 'returns an array representation' do
|
18
|
+
expect(described_class.to_a).to eql([0, 2, 3])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.to_s' do
|
23
|
+
it 'returns a string representation' do
|
24
|
+
expect(described_class.to_s).to eql('0.2.3')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,29 +1,31 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Mailgun::Tracking do
|
4
|
+
it { is_expected.to respond_to(:api_key) }
|
5
|
+
it { is_expected.to respond_to(:endpoint) }
|
6
|
+
it { is_expected.to respond_to(:api_key=) }
|
7
|
+
it { is_expected.to respond_to(:endpoint=) }
|
8
|
+
|
4
9
|
describe '.configure' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
before do
|
11
|
+
described_class.configure do |config|
|
12
|
+
config.api_key = 'dab36017-478a-4373-9378-7070eb5968b5'
|
13
|
+
config.endpoint = '/mailgun-tracking'
|
14
|
+
|
15
|
+
config.notifier.all(proc {})
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
allow(Mailgun::Tracking::Configuration).to receive(:instance) { configuration }
|
19
|
+
it 'setups api key' do
|
20
|
+
expect(described_class.api_key).to eq('dab36017-478a-4373-9378-7070eb5968b5')
|
16
21
|
end
|
17
22
|
|
18
|
-
it do
|
19
|
-
described_class.
|
20
|
-
expect(configuration).to have_received(:configure).with(options)
|
23
|
+
it 'setups endpoint' do
|
24
|
+
expect(described_class.endpoint).to eq('/mailgun-tracking')
|
21
25
|
end
|
22
|
-
end
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
expect(described_class.notifier).to be_instance_of(Mailgun::Tracking::Notifier)
|
27
|
+
it 'adds subscribers' do
|
28
|
+
expect(described_class.notifier).not_to be_empty
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,8 +12,11 @@ SimpleCov.start
|
|
12
12
|
RSpec.configure do |config|
|
13
13
|
config.include(RackHelpers)
|
14
14
|
|
15
|
-
config.before
|
16
|
-
Mailgun::Tracking.configure
|
15
|
+
config.before do
|
16
|
+
Mailgun::Tracking.configure do |c|
|
17
|
+
c.api_key = 'key-qblubkqnkdn4lfes5oscf57ryllaia42'
|
18
|
+
c.endpoint = '/mailgun'
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
19
22
|
config.expect_with :rspec do |c|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Chubchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Integration with Mailgun Webhooks
|
14
14
|
email:
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- spec/mailgun/tracking/subscriber/all_messages_spec.rb
|
41
41
|
- spec/mailgun/tracking/subscriber/evented_spec.rb
|
42
42
|
- spec/mailgun/tracking/subscriber_spec.rb
|
43
|
+
- spec/mailgun/tracking/version_spec.rb
|
43
44
|
- spec/mailgun/tracking_spec.rb
|
44
45
|
- spec/spec_helper.rb
|
45
46
|
- spec/support/fixture.rb
|
@@ -57,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
58
|
requirements:
|
58
59
|
- - ">="
|
59
60
|
- !ruby/object:Gem::Version
|
60
|
-
version: 1.
|
61
|
+
version: 2.1.0
|
61
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
63
|
requirements:
|
63
64
|
- - ">="
|
@@ -65,22 +66,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
66
|
version: '0'
|
66
67
|
requirements: []
|
67
68
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.6.
|
69
|
+
rubygems_version: 2.6.14
|
69
70
|
signing_key:
|
70
71
|
specification_version: 4
|
71
72
|
summary: Integration with Mailgun Webhooks
|
72
73
|
test_files:
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- spec/support/rack_helpers.rb
|
76
|
+
- spec/support/fixture.rb
|
77
|
+
- spec/support/shared_examples/subscriber.rb
|
73
78
|
- spec/fixtures/delivered.json
|
79
|
+
- spec/mailgun/tracking_spec.rb
|
74
80
|
- spec/mailgun/tracking/configuration_spec.rb
|
75
|
-
- spec/mailgun/tracking/
|
76
|
-
- spec/mailgun/tracking/middleware_spec.rb
|
77
|
-
- spec/mailgun/tracking/notifier_spec.rb
|
81
|
+
- spec/mailgun/tracking/version_spec.rb
|
78
82
|
- spec/mailgun/tracking/signature_spec.rb
|
79
|
-
- spec/mailgun/tracking/
|
80
|
-
- spec/mailgun/tracking/subscriber/evented_spec.rb
|
83
|
+
- spec/mailgun/tracking/notifier_spec.rb
|
81
84
|
- spec/mailgun/tracking/subscriber_spec.rb
|
82
|
-
- spec/mailgun/
|
83
|
-
- spec/
|
84
|
-
- spec/
|
85
|
-
- spec/
|
86
|
-
- spec/support/shared_examples/subscriber.rb
|
85
|
+
- spec/mailgun/tracking/middleware_spec.rb
|
86
|
+
- spec/mailgun/tracking/listener_spec.rb
|
87
|
+
- spec/mailgun/tracking/subscriber/evented_spec.rb
|
88
|
+
- spec/mailgun/tracking/subscriber/all_messages_spec.rb
|