mailgun_catcher 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e89041e32d638b9278e4c9b597d032a1028489f07e46aa399cb49dbb1e6b71d3
4
- data.tar.gz: 414f84ca5f27c6ea9b219e4db47d2c5b22ca899c971ba191639ed35a9195dcf8
3
+ metadata.gz: dacfa3890b0f1b49041cfcc6d749170d864471977c402a7bf3e8973a8ef287bf
4
+ data.tar.gz: b547f7780d0d99c576197568564cec4dad806bc62c858ee7c7370506b59f5074
5
5
  SHA512:
6
- metadata.gz: 776709eabd0f17164fbf155e5af9b2579d9c1fc1c5b753166ee258f7f79218cf2fd74c9c3b6ea228604f4ec16e2aa07996fbd52950d35bf25b622db8a37b55e7
7
- data.tar.gz: 2537ad6fcec36b4eab9ad84b19c08ce15aca5259cff02158c9094dfd20a14545d6c7a3cd2f4e39b72a35b8abae24b846b668790a0965437d02f0fc1f789d6a4d
6
+ metadata.gz: 7354b7c497078d2e64cf1b197e6f9a7ba0f95e85ceff64a2be66c8947baf5549b71af32f8abdc4cac69498678f5a45be9197483ba0d0c3150024bff46d43e504
7
+ data.tar.gz: 237dc959296bd08b553f052dce12935c7788be43332c400c590ed00ad2fd835ca6569529f31c3e64c032d185ea34b5df4c1e1754ad10a545809fece5e63e9c55
data/README.md CHANGED
@@ -18,9 +18,33 @@ Add to routes:
18
18
  mount MailgunCatcher::Engine, at: "/mailgun_catcher"
19
19
  ```
20
20
 
21
- Configire webhook on mailgun:
21
+ To configure an exact path for the webhooks controller create an initializer (`mailgun_catcher.rb`) with the following content:
22
+ ```ruby
23
+ MailgunCatcher::Engine.config.webhooks_path = 'custom_path'
24
+ ```
25
+ This will allow you change the default webhook route from `/webhooks` to `/custom_path`.
26
+
27
+ Configure webhook on mailgun:
22
28
  ![](http://take.ms/HZRmm)
23
29
 
30
+ ## Notifiers
31
+ Library supports event dispatching via notifier. Notifier is any object that responds to `notify` message. By default, events are notified on Bugsnag service, but you can provide your own notifier implementation by configuring `MailgunCatcher.config.notifier`.
32
+
33
+ ### Configuring custom notifier
34
+ ```ruby
35
+ class MailgunNotifier
36
+ def notify(event)
37
+ puts event
38
+ end
39
+ end
40
+ ```
41
+
42
+ register custom notifier implementation through initializer
43
+ ```ruby
44
+ MailgunCatcher.setup do |config|
45
+ config.notifiers = ["MailgunCatcher::Notifier::Bugsnag", "MailgunNotifier"]
46
+ end
47
+ ```
24
48
 
25
49
  ## Contributing
26
50
  Contribution directions go here.
@@ -1,7 +1,7 @@
1
1
  module MailgunCatcher
2
2
  class WebhooksController < MailgunCatcher::ApplicationController
3
3
  def create
4
- MailgunCatcher::Event.new(params).notify_bugsnag
4
+ MailgunCatcher::Event.new(params).notify
5
5
  head :ok
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  MailgunCatcher::Engine.routes.draw do
2
- resources :webhooks, only: [:create]
2
+ resources :webhooks, only: [:create], path: MailgunCatcher::Engine.config.webhooks_path
3
3
  end
@@ -1,7 +1,14 @@
1
+ require 'dry-configurable'
1
2
  require 'mailgun_catcher/engine'
2
3
  require 'mailgun_catcher/event'
3
- require 'mailgun_catcher/event_error'
4
+ require 'mailgun_catcher/notifier/bugsnag'
4
5
 
5
6
  module MailgunCatcher
6
- # Your code goes here...
7
+ extend Dry::Configurable
8
+
9
+ setting(:notifiers, ["MailgunCatcher::Notifier::Bugsnag"])
10
+
11
+ def self.setup
12
+ yield config
13
+ end
7
14
  end
@@ -1,5 +1,9 @@
1
1
  module MailgunCatcher
2
2
  class Engine < ::Rails::Engine
3
+ extend Dry::Configurable
4
+
5
+ setting :webhooks_path, 'webhooks'
6
+
3
7
  isolate_namespace MailgunCatcher
4
8
  end
5
9
  end
@@ -6,20 +6,28 @@ module MailgunCatcher
6
6
  @params = params.to_unsafe_h
7
7
  end
8
8
 
9
- def notify_bugsnag
10
- Bugsnag.notify(EventError.new(self))
9
+ def notify
10
+ notifiers.each { |notifier| notifier.notify(self) }
11
11
  end
12
12
 
13
13
  def error_message
14
14
  "[#{severity}] [#{reason}] #{recipient}: #{delivery_status}"
15
15
  end
16
16
 
17
+ def grouping_error_message
18
+ "[#{severity}] [#{reason}] #{recipient}"
19
+ end
20
+
17
21
  def event_data
18
22
  params.fetch('event-data', {})
19
23
  end
20
24
 
21
25
  private
22
26
 
27
+ def notifiers
28
+ MailgunCatcher.config.notifiers.map { |notifier| notifier.constantize.new }
29
+ end
30
+
23
31
  def delivery_status
24
32
  return delivery_status_message if delivery_status_message.present?
25
33
  return delivery_status_description if delivery_status_description.present?
@@ -0,0 +1,31 @@
1
+ module MailgunCatcher
2
+ module Notifier
3
+ class Bugsnag
4
+ def notify(event)
5
+ error_event = EventError.new(event)
6
+ ::Bugsnag.notify(error_event)
7
+ end
8
+ end
9
+
10
+ class EventError < StandardError
11
+ attr_reader :event
12
+
13
+ def initialize(event)
14
+ @event = event
15
+ super(event.error_message)
16
+ end
17
+
18
+ def bugsnag_meta_data
19
+ { event_details: event.event_data }
20
+ end
21
+
22
+ def bugsnag_context
23
+ 'mailgun'
24
+ end
25
+
26
+ def bugsnag_grouping_hash
27
+ event.grouping_error_message
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module MailgunCatcher
2
- VERSION = '0.2.0'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgun_catcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stjepan Hadjić
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bugsnag
@@ -24,21 +24,35 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-configurable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rails
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - "~>"
45
+ - - ">"
32
46
  - !ruby/object:Gem::Version
33
- version: '5.0'
47
+ version: '4'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">"
39
53
  - !ruby/object:Gem::Version
40
- version: '5.0'
41
- description: Engine for maingun hooks
54
+ version: '4'
55
+ description: Engine for mailgun hooks
42
56
  email:
43
57
  - d4be4st@gmail.com
44
58
  executables: []
@@ -54,14 +68,14 @@ files:
54
68
  - lib/mailgun_catcher.rb
55
69
  - lib/mailgun_catcher/engine.rb
56
70
  - lib/mailgun_catcher/event.rb
57
- - lib/mailgun_catcher/event_error.rb
71
+ - lib/mailgun_catcher/notifier/bugsnag.rb
58
72
  - lib/mailgun_catcher/version.rb
59
- homepage: https://github.com/infinum/rails-infinum-maingun_catcher
73
+ homepage: https://github.com/infinum/rails-infinum-mailgun_catcher
60
74
  licenses:
61
75
  - MIT
62
76
  metadata:
63
77
  allowed_push_host: https://rubygems.org
64
- post_install_message:
78
+ post_install_message:
65
79
  rdoc_options: []
66
80
  require_paths:
67
81
  - lib
@@ -76,9 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
90
  - !ruby/object:Gem::Version
77
91
  version: '0'
78
92
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 2.7.6
81
- signing_key:
93
+ rubygems_version: 3.0.3
94
+ signing_key:
82
95
  specification_version: 4
83
- summary: Engine for maingun hooks
96
+ summary: Engine for mailgun hooks
84
97
  test_files: []
@@ -1,22 +0,0 @@
1
- module MailgunCatcher
2
- class EventError < StandardError
3
- attr_reader :event
4
-
5
- def initialize(event)
6
- @event = event
7
- super(event.error_message)
8
- end
9
-
10
- def bugsnag_meta_data
11
- { event_details: event.event_data }
12
- end
13
-
14
- def bugsnag_context
15
- 'mailgun'
16
- end
17
-
18
- def bugsnag_grouping_hash
19
- event.error_message
20
- end
21
- end
22
- end