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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ead87c79c6faa39c84983c279db131c1968c03ae
4
- data.tar.gz: 78d9920ce209f081d38328df7d36d6f199981746
3
+ metadata.gz: 5be0e0cdf9733135b317548fc9924c2bc8bdbf9b
4
+ data.tar.gz: 43efe07cf45335ad09e018bb37bb1877b6883bb7
5
5
  SHA512:
6
- metadata.gz: 2e5111ccd3751dda799a590371247f919933d2aed6f4604fe5bd459f54582825b40a78e23a25240f3a424a574fa6296cd6662c5d824b6d8ac8b0e0e31b0f68e4
7
- data.tar.gz: ff31507c823c30180b93ad98fe4cd2985f4ba44fb956acd6d73a33c8438765d83c885ae9622f444c5f410a862c97eed7e5d05a1992cdcd069f8e28d313b3ab34
6
+ metadata.gz: 1d60327e25d838c1510c637568aca70ef02341871b521321c431503ee11ef71ac1e09e2a4f824e5f40f13200f4c2cb7ca6ebf1c0447d0ed502623804719b3365
7
+ data.tar.gz: 51e8ff1d72c967fe88c8c2b3a6cbe263a79f1da28e921d9945ea4f101808db65466acc40418f0dab49b54ac95d03621ee343ae280a1595dc8e176f119ffa6fee
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## v0.2.1
6
+ ### Fixed
7
+ * Fixes Headers for case-insensitive retrieval
8
+
5
9
  ## v0.2.0
6
10
  ### Added
7
11
  * Added `WebhookAware` controller
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "guard"
25
25
  spec.add_development_dependency "guard-rspec"
26
+ spec.add_development_dependency "listen", "~> 3.0.0"
26
27
  end
@@ -35,13 +35,19 @@ module Contentful
35
35
  protected
36
36
 
37
37
  def perform(request, response)
38
- @webhook = WebhookFactory.new(request).create
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
@@ -2,7 +2,7 @@ module Contentful
2
2
  module Webhook
3
3
  # Webhook Listener
4
4
  module Listener
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
8
8
  end
@@ -4,14 +4,14 @@ module Contentful
4
4
  module Webhook
5
5
  module Listener
6
6
  module WebhookConstants
7
- WEBHOOK_TOPIC = 'X-Contentful-Topic'
8
- WEBHOOK_NAME = 'X-Contentful-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) { {'X-Contentful-Topic' => topic, 'X-Contentful-Webhook-Name' => name} }
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['X-Contentful-Topic'] = 'ContentfulManagement.Asset.publish'
95
+ headers['x-contentful-topic'] = 'ContentfulManagement.Asset.publish'
96
96
  expect(described_class.new(headers, body).entry?).to be_falsey
97
97
 
98
- headers['X-Contentful-Topic'] = 'ContentfulManagement.ContentType.publish'
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['X-Contentful-Topic'] = 'ContentfulManagement.Asset.publish'
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['X-Contentful-Topic'] = 'ContentfulManagement.ContentType.publish'
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['X-Contentful-Topic'] = 'ContentfulManagement.ContentType.publish'
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['X-Contentful-Topic'] = 'ContentfulManagement.Asset.publish'
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) { {'X-Contentful-Topic' => topic, 'X-Contentful-Webhook-Name' => name} }
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.0
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 00:00:00.000000000 Z
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: