contentful-webhook-listener 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/contentful/webhook/listener.rb +4 -4
- data/lib/contentful/webhook/listener/controllers.rb +2 -2
- data/lib/contentful/webhook/listener/controllers/base.rb +7 -4
- data/lib/contentful/webhook/listener/controllers/wait.rb +8 -5
- data/lib/contentful/webhook/listener/server.rb +52 -11
- data/lib/contentful/webhook/listener/support.rb +1 -1
- data/lib/contentful/webhook/listener/support/null_logger.rb +2 -1
- data/lib/contentful/webhook/listener/version.rb +2 -1
- 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: 24fa6b57b9a36276814cf1d78945c628e999b1e3
|
4
|
+
data.tar.gz: 5c2818ade815ce97b5ebc64f4ccd1ff7c95aec1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32f2bc1c7f9353a9203cdce071cdb47f19d167ddc872d2aa15eca27b29b83920f8d00b0041276f76b8e1fe587dafeba03231fc086e2b86f8e03f8443527ed1d0
|
7
|
+
data.tar.gz: b29e84f6fe0049a1ce816ed9bd5e58f526231b0071f02671188fb01f876bd340a33be166965204eee8baa5887700b9ca6a7563df256b42a377db066cf43445b3
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'contentful/webhook/listener/version'
|
2
|
+
require 'contentful/webhook/listener/server'
|
3
|
+
require 'contentful/webhook/listener/controllers'
|
4
|
+
require 'contentful/webhook/listener/support'
|
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'contentful/webhook/listener/controllers/base'
|
2
|
+
require 'contentful/webhook/listener/controllers/wait'
|
@@ -1,12 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'webrick'
|
2
2
|
|
3
3
|
module Contentful
|
4
4
|
module Webhook
|
5
5
|
module Listener
|
6
6
|
module Controllers
|
7
|
+
# Abstract Base Controller
|
8
|
+
# Extend and redefine #perform to run a process in background
|
7
9
|
class Base < WEBrick::HTTPServlet::AbstractServlet
|
8
10
|
def respond(request, response)
|
9
|
-
response.body =
|
11
|
+
response.body = ''
|
10
12
|
response.status = 200
|
11
13
|
|
12
14
|
Thread.new do
|
@@ -18,8 +20,9 @@ module Contentful
|
|
18
20
|
alias_method :do_POST, :respond
|
19
21
|
|
20
22
|
protected
|
21
|
-
|
22
|
-
|
23
|
+
|
24
|
+
def perform(_request, _response)
|
25
|
+
fail 'must implement'
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
@@ -1,20 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require 'thread'
|
2
2
|
|
3
3
|
module Contentful
|
4
4
|
module Webhook
|
5
5
|
module Listener
|
6
6
|
module Controllers
|
7
|
+
# Wait Controller
|
8
|
+
# Sleeps a determined amount of `:timeout` seconds on #perform
|
7
9
|
class Wait < Base
|
8
|
-
attr_reader :
|
10
|
+
attr_reader :webhook_timeout
|
9
11
|
|
10
12
|
def initialize(server, wh_timeout, *options)
|
11
13
|
super(server, options)
|
12
|
-
@
|
14
|
+
@webhook_timeout = wh_timeout
|
13
15
|
end
|
14
16
|
|
15
17
|
protected
|
16
|
-
|
17
|
-
|
18
|
+
|
19
|
+
def perform(_request, _response)
|
20
|
+
sleep(webhook_timeout)
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
@@ -1,18 +1,28 @@
|
|
1
1
|
require 'thread'
|
2
2
|
require 'webrick'
|
3
3
|
require 'stringio'
|
4
|
-
require
|
4
|
+
require 'contentful/webhook/listener/controllers'
|
5
5
|
|
6
6
|
module Contentful
|
7
7
|
module Webhook
|
8
8
|
module Listener
|
9
|
+
# Server is the responsible for handling Webhook receiver endpoints
|
10
|
+
# Configuration defaults are:
|
11
|
+
# - port: 5678
|
12
|
+
# - address: '0.0.0.0'
|
13
|
+
# - logger: Contentful::Webhook::Support::NullLogger.new
|
14
|
+
# - endpoints: [{
|
15
|
+
# endpoint: '/receive',
|
16
|
+
# controller: Contentful::Webhook::Listener::Controllers::Wait,
|
17
|
+
# timeout: 300
|
18
|
+
# }]
|
9
19
|
class Server
|
10
20
|
DEFAULT_PORT = 5678
|
11
|
-
DEFAULT_ADDRESS =
|
21
|
+
DEFAULT_ADDRESS = '0.0.0.0'
|
12
22
|
DEFAULT_ENDPOINTS = [
|
13
23
|
{
|
14
|
-
endpoint:
|
15
|
-
controller: Contentful::Webhook::Listener::Controllers::
|
24
|
+
endpoint: '/receive',
|
25
|
+
controller: Contentful::Webhook::Listener::Controllers::Wait,
|
16
26
|
timeout: 300
|
17
27
|
}
|
18
28
|
]
|
@@ -29,21 +39,52 @@ module Contentful
|
|
29
39
|
@port = config.fetch(:port, DEFAULT_PORT)
|
30
40
|
@address = config.fetch(:address, DEFAULT_ADDRESS)
|
31
41
|
@endpoints = config.fetch(:endpoints, DEFAULT_ENDPOINTS)
|
32
|
-
@logger = config.fetch(
|
42
|
+
@logger = config.fetch(
|
43
|
+
:logger,
|
44
|
+
Contentful::Webhook::Listener::Support::NullLogger.new
|
45
|
+
)
|
33
46
|
end
|
34
47
|
|
35
48
|
def start
|
36
|
-
@server = WEBrick::HTTPServer.new(:Port => @port, :BindAddress => @address, :AccessLog => [], :Logger => @logger)
|
37
|
-
|
38
49
|
logger.info "Webhook server starting at: http://#{@address}:#{@port}"
|
39
|
-
|
50
|
+
|
51
|
+
mount_endpoints
|
52
|
+
|
53
|
+
server.start
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
def server
|
59
|
+
@server ||= WEBrick::HTTPServer.new(
|
60
|
+
Port: @port,
|
61
|
+
BindAddress: @address,
|
62
|
+
AccessLog: [],
|
63
|
+
Logger: @logger
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def mount_endpoints
|
68
|
+
logger.info 'Available Endpoints:'
|
40
69
|
@endpoints.each do |endpoint_config|
|
41
|
-
|
70
|
+
server.mount(
|
71
|
+
endpoint_config[:endpoint],
|
72
|
+
endpoint_config[:controller],
|
73
|
+
endpoint_config[:timeout]
|
74
|
+
)
|
42
75
|
|
43
|
-
|
76
|
+
log_endpoint_data(endpoint_config)
|
44
77
|
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def log_endpoint_data(endpoint_config)
|
81
|
+
endpoint_data = [
|
82
|
+
endpoint_config[:endpoint],
|
83
|
+
"Controller: #{endpoint_config[:controller].name}",
|
84
|
+
"Timeout: #{endpoint_config[:timeout]}"
|
85
|
+
]
|
45
86
|
|
46
|
-
|
87
|
+
logger.info "\t#{endpoint_data.join(' - ')}"
|
47
88
|
end
|
48
89
|
end
|
49
90
|
end
|
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'contentful/webhook/listener/support/null_logger.rb'
|
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.0.
|
4
|
+
version: 0.0.3
|
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: 2015-11-
|
11
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.4.5.1
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: A Simple HTTP Webserver with pluggable behavior for listening to Contentful
|