contentful-webhook-listener 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/contentful-webhook-listener.gemspec +1 -0
- data/lib/contentful/webhook/listener/controllers/webhook_aware.rb +10 -4
- data/lib/contentful/webhook/listener/version.rb +1 -1
- data/lib/contentful/webhook/listener/webhooks.rb +3 -3
- data/spec/contentful/webhook/listener/webhooks_spec.rb +8 -8
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5be0e0cdf9733135b317548fc9924c2bc8bdbf9b
|
4
|
+
data.tar.gz: 43efe07cf45335ad09e018bb37bb1877b6883bb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d60327e25d838c1510c637568aca70ef02341871b521321c431503ee11ef71ac1e09e2a4f824e5f40f13200f4c2cb7ca6ebf1c0447d0ed502623804719b3365
|
7
|
+
data.tar.gz: 51e8ff1d72c967fe88c8c2b3a6cbe263a79f1da28e921d9945ea4f101808db65466acc40418f0dab49b54ac95d03621ee343ae280a1595dc8e176f119ffa6fee
|
data/CHANGELOG.md
CHANGED
@@ -35,13 +35,19 @@ module Contentful
|
|
35
35
|
protected
|
36
36
|
|
37
37
|
def perform(request, response)
|
38
|
-
|
38
|
+
begin
|
39
|
+
@webhook = WebhookFactory.new(request).create
|
40
|
+
rescue Exception => e
|
41
|
+
logger.error e
|
42
|
+
response.body = "Not a Webhook"
|
43
|
+
response.status = 400
|
44
|
+
return
|
45
|
+
end
|
46
|
+
|
39
47
|
super(request, response)
|
48
|
+
|
40
49
|
logger.debug "Webhook Data: {id: #{webhook.id}, space_id: #{webhook.space_id}, kind: #{webhook.kind}, event: #{webhook.event}}"
|
41
50
|
send(webhook.event)
|
42
|
-
rescue
|
43
|
-
response.body = "Not a Webhook"
|
44
|
-
response.status = 400
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
@@ -4,14 +4,14 @@ module Contentful
|
|
4
4
|
module Webhook
|
5
5
|
module Listener
|
6
6
|
module WebhookConstants
|
7
|
-
WEBHOOK_TOPIC = '
|
8
|
-
WEBHOOK_NAME = '
|
7
|
+
WEBHOOK_TOPIC = 'x-contentful-topic'
|
8
|
+
WEBHOOK_NAME = 'x-contentful-webhook-name'
|
9
9
|
end
|
10
10
|
|
11
11
|
class WebhookFactory
|
12
12
|
def initialize(request)
|
13
13
|
@headers = {}
|
14
|
-
request.each { |header, value| @headers[header] = value }
|
14
|
+
request.each { |header, value| @headers[header.downcase] = value }
|
15
15
|
@body = JSON.load(request.body)
|
16
16
|
end
|
17
17
|
|
@@ -52,7 +52,7 @@ describe Contentful::Webhook::Listener::BaseWebhook do
|
|
52
52
|
let(:body) { {'sys' => { 'id' => 'foo', 'space' => { 'sys' => { 'id' => 'space_foo' } } }, 'fields' => {} } }
|
53
53
|
let(:topic) { 'ContentfulManagement.Entry.publish' }
|
54
54
|
let(:name) { 'WebhookName' }
|
55
|
-
let(:headers) { {'
|
55
|
+
let(:headers) { {'x-contentful-topic' => topic, 'x-contentful-webhook-name' => name} }
|
56
56
|
subject { described_class.new(headers, body) }
|
57
57
|
|
58
58
|
describe 'attributes' do
|
@@ -92,34 +92,34 @@ describe Contentful::Webhook::Listener::BaseWebhook do
|
|
92
92
|
expect(described_class.new(headers, body).entry?).to be_truthy
|
93
93
|
end
|
94
94
|
it 'false when kind != Entry' do
|
95
|
-
headers['
|
95
|
+
headers['x-contentful-topic'] = 'ContentfulManagement.Asset.publish'
|
96
96
|
expect(described_class.new(headers, body).entry?).to be_falsey
|
97
97
|
|
98
|
-
headers['
|
98
|
+
headers['x-contentful-topic'] = 'ContentfulManagement.ContentType.publish'
|
99
99
|
expect(described_class.new(headers, body).entry?).to be_falsey
|
100
100
|
end
|
101
101
|
end
|
102
102
|
describe '#asset?' do
|
103
103
|
it 'true when kind == Asset' do
|
104
|
-
headers['
|
104
|
+
headers['x-contentful-topic'] = 'ContentfulManagement.Asset.publish'
|
105
105
|
expect(described_class.new(headers, body).asset?).to be_truthy
|
106
106
|
end
|
107
107
|
it 'false when kind != Asset' do
|
108
108
|
expect(described_class.new(headers, body).asset?).to be_falsey
|
109
109
|
|
110
|
-
headers['
|
110
|
+
headers['x-contentful-topic'] = 'ContentfulManagement.ContentType.publish'
|
111
111
|
expect(described_class.new(headers, body).asset?).to be_falsey
|
112
112
|
end
|
113
113
|
end
|
114
114
|
describe '#content_type?' do
|
115
115
|
it 'true when kind == ContentType' do
|
116
|
-
headers['
|
116
|
+
headers['x-contentful-topic'] = 'ContentfulManagement.ContentType.publish'
|
117
117
|
expect(described_class.new(headers, body).content_type?).to be_truthy
|
118
118
|
end
|
119
119
|
it 'false when kind != ContentType' do
|
120
120
|
expect(described_class.new(headers, body).content_type?).to be_falsey
|
121
121
|
|
122
|
-
headers['
|
122
|
+
headers['x-contentful-topic'] = 'ContentfulManagement.Asset.publish'
|
123
123
|
expect(described_class.new(headers, body).content_type?).to be_falsey
|
124
124
|
end
|
125
125
|
end
|
@@ -131,7 +131,7 @@ describe Contentful::Webhook::Listener::FieldWebhook do
|
|
131
131
|
let(:body) { {'sys' => { 'id' => 'foo', 'space' => { 'sys' => { 'id' => 'space_foo' } } }, 'fields' => {} } }
|
132
132
|
let(:topic) { 'ContentfulManagement.Entry.publish' }
|
133
133
|
let(:name) { 'WebhookName' }
|
134
|
-
let(:headers) { {'
|
134
|
+
let(:headers) { {'x-contentful-topic' => topic, 'x-contentful-webhook-name' => name} }
|
135
135
|
subject { described_class.new(headers, body) }
|
136
136
|
|
137
137
|
describe 'attributes' do
|
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.2.
|
4
|
+
version: 0.2.1
|
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-04-
|
11
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: listen
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
83
97
|
description: A Simple HTTP Webserver with pluggable behavior for listening to Contentful
|
84
98
|
API Webhooks
|
85
99
|
email:
|