webhooker 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/spring.rb +1 -0
- data/lib/webhooker/model.rb +29 -14
- data/lib/webhooker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa012c157d6e655bcff57c6b26f13271f985d15c
|
4
|
+
data.tar.gz: 427f3ca404f29df767107703dacccc530214b9cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 938bef6ad7061bd233449f6017ee1bd472f209e82ab8ccef88bd8839a89ca5f8c605347b5006f21486bf2077270ec7df73f7398912e84faeb44a8d0567a444ca
|
7
|
+
data.tar.gz: ce5f0f1c0668f13e50a23426a80d50b4f30faed92979a3d163210c972dae6699e0b0be03712549e9a32e9a14539109e63463c6f0d15ef3374e851200b70f83fa
|
data/config/spring.rb
CHANGED
data/lib/webhooker/model.rb
CHANGED
@@ -5,21 +5,34 @@ module Webhooker
|
|
5
5
|
module Model
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
attrs = attrs.slice(*self.class.webhook_attributes)
|
12
|
-
end
|
8
|
+
def _trigger_webhook_on_create
|
9
|
+
_trigger_webhook :create
|
10
|
+
end
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Subscriber.find_each do |subscriber|
|
21
|
-
TriggerJob.perform_later subscriber, data
|
12
|
+
def _trigger_webhook_on_update
|
13
|
+
filtered_changes =
|
14
|
+
if self.class.webhook_attributes
|
15
|
+
changes.slice(*self.class.webhook_attributes)
|
16
|
+
else
|
17
|
+
changes
|
22
18
|
end
|
19
|
+
if filtered_changes.present?
|
20
|
+
_trigger_webhook :update, changes: filtered_changes
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def _trigger_webhook_on_destroy
|
25
|
+
_trigger_webhook :destroy
|
26
|
+
end
|
27
|
+
|
28
|
+
def _trigger_webhook action, data = {}
|
29
|
+
data = {
|
30
|
+
resource: model_name.element,
|
31
|
+
action: action.to_s,
|
32
|
+
attributes: attributes.as_json,
|
33
|
+
}.merge(data)
|
34
|
+
Subscriber.find_each do |subscriber|
|
35
|
+
TriggerJob.perform_later subscriber, data
|
23
36
|
end
|
24
37
|
end
|
25
38
|
|
@@ -27,8 +40,10 @@ module Webhooker
|
|
27
40
|
attr_accessor :webhook_attributes
|
28
41
|
|
29
42
|
def webhooks *args
|
30
|
-
after_save :_trigger_webhook
|
31
43
|
options = args.extract_options!
|
44
|
+
(options[:on] || %i(create update destroy)).each do |action|
|
45
|
+
send :"after_#{action}", :"_trigger_webhook_on_#{action}"
|
46
|
+
end
|
32
47
|
@webhook_attributes = options[:attributes].try(:map, &:to_s)
|
33
48
|
end
|
34
49
|
end
|
data/lib/webhooker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webhooker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kayhide
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|