contentful-webhook-listener 0.2.1 → 0.3.0
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/CHANGELOG.md +4 -0
- data/lib/contentful/webhook/listener/controllers/base.rb +10 -1
- data/lib/contentful/webhook/listener/controllers/wait.rb +2 -0
- data/lib/contentful/webhook/listener/controllers/webhook_aware.rb +11 -9
- data/lib/contentful/webhook/listener/version.rb +1 -1
- data/lib/contentful/webhook/listener/webhooks.rb +2 -0
- data/spec/contentful/webhook/listener/controllers/webhook_aware_spec.rb +1 -1
- data/spec/contentful/webhook/listener/webhooks_spec.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f6ded8f1bbba252903740a01f7d5ab58bee71e2
|
4
|
+
data.tar.gz: c62f6b5fe90567201e1cca0f1a447e76f5377c0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c1f7fe9ef0c72d0f79f09776cd10e8e839d76bf170549ca6ba232e221acfa349e4d328fa51c96a9c59a5b1920b45130d06c52f2448399c2d519c9b9cb7f539c
|
7
|
+
data.tar.gz: dd9b4feedaf0d2e05bfafbf094bcd339be0f9b2978a5ae05b56ba6ad79331e1d68e92597129b3ed64ab91d7a9628a8df6ae3051ac548866aa64e0b1d66452a54
|
data/CHANGELOG.md
CHANGED
@@ -18,8 +18,12 @@ module Contentful
|
|
18
18
|
response.body = ''
|
19
19
|
response.status = 200
|
20
20
|
|
21
|
+
pre_perform(request, response)
|
22
|
+
|
23
|
+
return if response.status != 200
|
24
|
+
|
21
25
|
Thread.new do
|
22
|
-
|
26
|
+
perform(request, response)
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
@@ -28,6 +32,11 @@ module Contentful
|
|
28
32
|
|
29
33
|
protected
|
30
34
|
|
35
|
+
def pre_perform(_request, _response)
|
36
|
+
ensure
|
37
|
+
_response
|
38
|
+
end
|
39
|
+
|
31
40
|
def perform(_request, _response)
|
32
41
|
fail 'must implement'
|
33
42
|
end
|
@@ -34,20 +34,22 @@ module Contentful
|
|
34
34
|
|
35
35
|
protected
|
36
36
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
37
|
+
def pre_perform(request, response)
|
38
|
+
@webhook = WebhookFactory.new(request).create
|
39
|
+
rescue Exception => e
|
40
|
+
logger.error 'Not a Webhook. Stacktrace: '
|
41
|
+
logger.error e
|
42
|
+
response.body = "Not a Webhook"
|
43
|
+
response.status = 400
|
44
|
+
end
|
46
45
|
|
46
|
+
def perform(request, response)
|
47
47
|
super(request, response)
|
48
48
|
|
49
49
|
logger.debug "Webhook Data: {id: #{webhook.id}, space_id: #{webhook.space_id}, kind: #{webhook.kind}, event: #{webhook.event}}"
|
50
50
|
send(webhook.event)
|
51
|
+
ensure
|
52
|
+
response
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
@@ -28,6 +28,8 @@ module Contentful
|
|
28
28
|
def webhook_class_name
|
29
29
|
event_name = @headers[::Contentful::Webhook::Listener::WebhookConstants::WEBHOOK_TOPIC].split('.')[-1].split('_').collect(&:capitalize).join
|
30
30
|
"Contentful::Webhook::Listener::#{event_name}Webhook"
|
31
|
+
rescue Exception
|
32
|
+
fail 'Could not detect Webhook class'
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -18,7 +18,7 @@ describe Contentful::Webhook::Listener::Controllers::WebhookAware do
|
|
18
18
|
|
19
19
|
it 'returns 400 Bad Request on non-webhook call' do
|
20
20
|
response = MockResponse.new
|
21
|
-
subject.respond(RequestDummy.new(nil, "foo"), response)
|
21
|
+
subject.respond(RequestDummy.new(nil, "foo"), response)
|
22
22
|
|
23
23
|
expect(response.status).to eq(400)
|
24
24
|
expect(response.body).to eq('Not a Webhook')
|
@@ -44,6 +44,12 @@ describe Contentful::Webhook::Listener::WebhookFactory do
|
|
44
44
|
expect(webhook).to be_a Contentful::Webhook::Listener::DeleteWebhook
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
describe 'errors' do
|
49
|
+
it 'raises an error when it cant detect webhook' do
|
50
|
+
expect { described_class.new(RequestDummy.new({}, body)).create }.to raise_error "Could not detect Webhook class"
|
51
|
+
end
|
52
|
+
end
|
47
53
|
end
|
48
54
|
end
|
49
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful-webhook-listener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH (David Litvak Bruno)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.5.
|
153
|
+
rubygems_version: 2.5.1
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: A Simple HTTP Webserver with pluggable behavior for listening to Contentful
|