activehook 0.1.3 → 0.1.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/README.md +11 -5
- data/lib/activehook/app/middleware.rb +13 -29
- data/lib/activehook/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: a9bdd9c58667318f072b3bb500d48e3595927593
|
4
|
+
data.tar.gz: f715fdbb3226983ab489aa310166c58b8e922481
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa8fe137d40397d8f25ea78d86a48b9041fb24374aec759112efdc48eae8b27e4fccc459efca48c9b27db9a3b4767e8de28aa345e398beae4b58ba437cc2393
|
7
|
+
data.tar.gz: 31772720c13d69ad9a4bb9445283eecab98af8294d1c487e8d74fdf31b757975a5ba80788c552b590dce004beb7ceff7d23f50de7ca7471de84a34dc066d5284
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# ActiveHook
|
2
2
|
---
|
3
3
|
|
4
|
-
Fast and simple webhook microservice for Ruby. **Please consider it under development at the moment.**
|
4
|
+
Fast and simple webhook delivery microservice for Ruby. **Please consider it under development at the moment.**
|
5
5
|
|
6
6
|
ActiveHook provides a scalable solution to your applications webhook sending needs. Its Redis-backed, with support for forking and threading - letting it send an enormous amount of webhooks in short order. Basically a much more focused version of a job processor such as Sidekiq, DelayedJob, Resque, etc. It includes the following:
|
7
7
|
|
8
|
-
- A server for the purpose of sending webhooks.
|
9
|
-
- A mixin module for the purpose of recieving and validating webhooks.
|
8
|
+
- A server for the purpose of sending webhooks. With support for retry attempts.
|
9
|
+
- A client-side mixin module for the purpose of recieving and validating webhooks.
|
10
10
|
- A piece of Rack middleware for the purpose of performing validation.
|
11
11
|
|
12
12
|
## Installation
|
@@ -155,13 +155,19 @@ end
|
|
155
155
|
|
156
156
|
Sending webhooks is one thing - ensuring they are from who we want is another.
|
157
157
|
|
158
|
-
ActiveHook includes a piece of Rack middleware for the purpose of validation. When a client attempts to validate a webhook, they are sending a message back to your server. The message includes the hooks ID as well as key. These are are then cross-referenced. If they match, we provide the AOK.
|
158
|
+
ActiveHook includes a piece of Rack middleware for the purpose of validation. When a client attempts to validate a webhook, they are sending a message back to your server. The message includes the hooks ID as well as key. These are are then cross-referenced with the server records. If they match, we provide the AOK.
|
159
|
+
|
160
|
+
We set the address that the middleware uses from our config file (App mode config described above):
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
config.validation_path = '/hooks/validate'
|
164
|
+
```
|
159
165
|
|
160
166
|
In Rails, we would add the middleware like this:
|
161
167
|
|
162
168
|
```ruby
|
163
169
|
# In config/application.rb
|
164
|
-
config.middleware.use
|
170
|
+
config.middleware.use('ActiveHook::App::Middleware')
|
165
171
|
```
|
166
172
|
|
167
173
|
Or with Rackup files:
|
@@ -1,15 +1,6 @@
|
|
1
1
|
module ActiveHook
|
2
2
|
module App
|
3
3
|
class Middleware
|
4
|
-
class << self
|
5
|
-
attr_accessor :valid, :invalid, :not_created, :created
|
6
|
-
end
|
7
|
-
|
8
|
-
@invalid = ->(_env) { [400, { "Content-Type" => "application/json" }, [{ valid: false }.to_json]] }
|
9
|
-
@valid = ->(_env) { [200, { "Content-Type" => "application/json" }, [{ valid: true }.to_json]] }
|
10
|
-
@not_created = ->(_env) { [400, { "Content-Type" => "application/json" }, [{ status: false }.to_json]] }
|
11
|
-
@created = ->(_env) { [200, { "Content-Type" => "application/json" }, [{ status: true }.to_json]] }
|
12
|
-
|
13
4
|
def initialize(app)
|
14
5
|
@app = app
|
15
6
|
end
|
@@ -18,8 +9,9 @@ module ActiveHook
|
|
18
9
|
@env = env
|
19
10
|
@req = Rack::Request.new(env)
|
20
11
|
|
21
|
-
if validation_request? then
|
22
|
-
|
12
|
+
if validation_request? then response(Validation)
|
13
|
+
#Not enabling webhook creation yet.
|
14
|
+
#elsif creation_request? then response(Creation)
|
23
15
|
else @app.call(@env)
|
24
16
|
end
|
25
17
|
end
|
@@ -32,35 +24,27 @@ module ActiveHook
|
|
32
24
|
@req.path == ActiveHook.config.creation_path && @req.post?
|
33
25
|
end
|
34
26
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def create?
|
44
|
-
if Creation.new(@req.params).start
|
45
|
-
self.class.created.call(@env)
|
46
|
-
else
|
47
|
-
self.class.not_created.call(@env)
|
48
|
-
end
|
27
|
+
def response(klass)
|
28
|
+
response =
|
29
|
+
if klass.new(@req).start then { code: 200, status: true }
|
30
|
+
else { code: 400, status: false }
|
31
|
+
end
|
32
|
+
[response[:code], { "Content-Type" => "application/json" }, [{ status: response[:status] }.to_json]]
|
49
33
|
end
|
50
34
|
end
|
51
35
|
|
52
|
-
Validation = Struct.new(:
|
36
|
+
Validation = Struct.new(:req) do
|
53
37
|
def start
|
54
|
-
hook = { id: params['id'].to_i, key: params['key'] }
|
38
|
+
hook = { id: req.params['id'].to_i, key: req.params['key'] }
|
55
39
|
ActiveHook::Validate.new(hook).perform
|
56
40
|
rescue
|
57
41
|
false
|
58
42
|
end
|
59
43
|
end
|
60
44
|
|
61
|
-
Creation = Struct.new(:
|
45
|
+
Creation = Struct.new(:req) do
|
62
46
|
def start
|
63
|
-
hook =
|
47
|
+
hook = JSON.parse(req.body.read)
|
64
48
|
ActiveHook::Hook.new(hook).perform
|
65
49
|
rescue
|
66
50
|
false
|
data/lib/activehook/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activehook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Sweeting
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|