zaikio-webhooks 0.0.4 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -7
- data/app/controllers/zaikio/webhooks/webhooks_controller.rb +2 -1
- data/config/initializers/register_zaikio_webhooks_event_serializer.rb +1 -0
- data/lib/zaikio/webhooks.rb +2 -0
- data/lib/zaikio/webhooks/configuration.rb +1 -1
- data/lib/zaikio/webhooks/event.rb +2 -1
- data/lib/zaikio/webhooks/event_serializer.rb +17 -0
- data/lib/zaikio/webhooks/version.rb +1 -1
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80a5c7439ef2f8e609deb2f93547dfe0fd1deee14ed4edb5ccbf8d64c47805b0
|
4
|
+
data.tar.gz: 0b364bfdce4a6aa78a49baabae4a6e91761fafd2d02fad86bbceb90f669c8ac9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52b6fc351a564085b841cef8bf9a4c9a122abfb8619ed34eb418c6cec94e5435f7782d72a3f2024e5b183cf6586cdc1fe4d8bf0f35de7b0928e203b6cd7603ac
|
7
|
+
data.tar.gz: 58c166ae90fbac2c41022ceb833c8734f976c996394502f6f04addd8e5ab5a1b8373d7f0a666e2c9d09b76804d0e7ca75d26e154bc33cdcaed2326881e944484
|
data/README.md
CHANGED
@@ -34,13 +34,6 @@ Zaikio::Webhooks.configure do |config|
|
|
34
34
|
my_other_app.shared_secret = "test-secret"
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
# Perform job immediately, for all clients
|
39
|
-
Zaikio::Webhooks.on "directory.revoked_access_token", RevokeAccessTokenJob,
|
40
|
-
perform_now: true
|
41
|
-
# Only for a specific client
|
42
|
-
Zaikio::Webhooks.on "directory.machine_added", AddMachineJob,
|
43
|
-
client_name: :my_app
|
44
37
|
```
|
45
38
|
|
46
39
|
### 3. Mount Engine
|
@@ -77,3 +70,44 @@ class AddMachineJob < ApplicationJob
|
|
77
70
|
end
|
78
71
|
end
|
79
72
|
```
|
73
|
+
|
74
|
+
### 6. Add Webhook URL to Zaikio Hub
|
75
|
+
|
76
|
+
Login to [Zaikio Hub](https://directory.zaikio.com/) and go to your Apps and go to Edit App and add your webhook URL e.g. `https://mydomain.de/zaikio/webhook/my_app_name`.
|
77
|
+
|
78
|
+
Now you should receive all events you subscribed to.
|
79
|
+
|
80
|
+
### 7. Usage
|
81
|
+
|
82
|
+
When everything is set up you can register events with custom jobs, using the
|
83
|
+
`Zaikio::Webhooks.on` function. This is idempotent and can be safely re-executed.
|
84
|
+
|
85
|
+
We can setup an initializer like so:
|
86
|
+
|
87
|
+
```rb
|
88
|
+
# config/initializers/zaikio_webhooks.rb
|
89
|
+
|
90
|
+
# We need to add this special wrapper here because we're referencing autoloaded constants
|
91
|
+
# (RevokeAccessTokenJob, AddMachineJob) at boot time. For more information, see:
|
92
|
+
# https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoloading-when-the-application-boots
|
93
|
+
Rails.application.reloader.to_prepare do
|
94
|
+
# Perform job immediately, for all clients
|
95
|
+
Zaikio::Webhooks.on "directory.revoked_access_token", RevokeAccessTokenJob,
|
96
|
+
perform_now: true
|
97
|
+
# Only for a specific client
|
98
|
+
Zaikio::Webhooks.on "directory.machine_added", AddMachineJob,
|
99
|
+
client_name: :my_app
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
## Contributing
|
104
|
+
|
105
|
+
- Make your changes and submit a pull request for them
|
106
|
+
- Make sure to update `CHANGELOG.md`
|
107
|
+
|
108
|
+
To release a new version of the gem:
|
109
|
+
- Update the version in `lib/zaikio/webhooks/version.rb`
|
110
|
+
- Update `CHANGELOG.md` to include the new version and its release date
|
111
|
+
- Commit and push your changes
|
112
|
+
- Create a [new release on GitHub](https://github.com/zaikio/zaikio-webhooks/releases/new)
|
113
|
+
- CircleCI will build the Gem package and push it Rubygems for you
|
@@ -30,7 +30,8 @@ module Zaikio
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def event_params
|
33
|
-
params.permit(:id, :name, :subject, :timestamp,
|
33
|
+
params.permit(:id, :client_name, :name, :subject, :timestamp,
|
34
|
+
:version, :link, :received_at, payload: {})
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Rails.application.config.active_job.custom_serializers << Zaikio::Webhooks::EventSerializer
|
data/lib/zaikio/webhooks.rb
CHANGED
@@ -5,7 +5,8 @@ module Zaikio
|
|
5
5
|
class Event
|
6
6
|
extend Forwardable
|
7
7
|
attr_reader :data
|
8
|
-
|
8
|
+
|
9
|
+
def_delegators :data, :id, :name, :version, :payload, :link, :client_name, :to_h
|
9
10
|
|
10
11
|
def initialize(event_data)
|
11
12
|
@data = OpenStruct.new(event_data)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Zaikio
|
2
|
+
module Webhooks
|
3
|
+
class EventSerializer < ActiveJob::Serializers::ObjectSerializer
|
4
|
+
def serialize?(argument)
|
5
|
+
argument.is_a? Event
|
6
|
+
end
|
7
|
+
|
8
|
+
def serialize(event)
|
9
|
+
super(event.to_h)
|
10
|
+
end
|
11
|
+
|
12
|
+
def deserialize(data)
|
13
|
+
Event.new(data)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaikio-webhooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zaikio GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- README.md
|
42
42
|
- Rakefile
|
43
43
|
- app/controllers/zaikio/webhooks/webhooks_controller.rb
|
44
|
+
- config/initializers/register_zaikio_webhooks_event_serializer.rb
|
44
45
|
- config/routes.rb
|
45
46
|
- lib/tasks/zaikio/webhook_tasks.rake
|
46
47
|
- lib/zaikio/webhooks.rb
|
@@ -48,11 +49,14 @@ files:
|
|
48
49
|
- lib/zaikio/webhooks/configuration.rb
|
49
50
|
- lib/zaikio/webhooks/engine.rb
|
50
51
|
- lib/zaikio/webhooks/event.rb
|
52
|
+
- lib/zaikio/webhooks/event_serializer.rb
|
51
53
|
- lib/zaikio/webhooks/version.rb
|
52
|
-
homepage: https://
|
54
|
+
homepage: https://github.com/zaikio/zaikio-webhooks
|
53
55
|
licenses:
|
54
56
|
- MIT
|
55
|
-
metadata:
|
57
|
+
metadata:
|
58
|
+
changelog_uri: https://github.com/zaikio/zaikio-webhooks/blob/main/CHANGELOG.md
|
59
|
+
source_code_uri: https://github.com/zaikio/zaikio-webhooks
|
56
60
|
post_install_message:
|
57
61
|
rdoc_options: []
|
58
62
|
require_paths:
|
@@ -61,14 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
65
|
requirements:
|
62
66
|
- - ">="
|
63
67
|
- !ruby/object:Gem::Version
|
64
|
-
version:
|
68
|
+
version: 2.6.5
|
65
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
70
|
requirements:
|
67
71
|
- - ">="
|
68
72
|
- !ruby/object:Gem::Version
|
69
73
|
version: '0'
|
70
74
|
requirements: []
|
71
|
-
rubygems_version: 3.1.
|
75
|
+
rubygems_version: 3.1.4
|
72
76
|
signing_key:
|
73
77
|
specification_version: 4
|
74
78
|
summary: Handle incoming Zaikio loom webhooks
|