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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2be61a4cf62efe827b97bf7dbf43d8191e75df8
4
- data.tar.gz: 16b18e95e56e0371971fc203e1f0002cf20559e7
3
+ metadata.gz: 24fa6b57b9a36276814cf1d78945c628e999b1e3
4
+ data.tar.gz: 5c2818ade815ce97b5ebc64f4ccd1ff7c95aec1d
5
5
  SHA512:
6
- metadata.gz: 9d745232369334ff7f9688afddd3943954adeec048d7c7dc44c1fbf72bcb7c27f53716a1ad4a5bf6e83cf8e57f0cd102f939b2a4a357818f65395f84034b7596
7
- data.tar.gz: b796a3748378a5dd8dadbe0502482a3c636841ef7f461042185b2bce9731a64badee7c5770be1c9e3d200c49dbdf1bab0cf61dea372d17c61570d4735a8daad1
6
+ metadata.gz: 32f2bc1c7f9353a9203cdce071cdb47f19d167ddc872d2aa15eca27b29b83920f8d00b0041276f76b8e1fe587dafeba03231fc086e2b86f8e03f8443527ed1d0
7
+ data.tar.gz: b29e84f6fe0049a1ce816ed9bd5e58f526231b0071f02671188fb01f876bd340a33be166965204eee8baa5887700b9ca6a7563df256b42a377db066cf43445b3
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Changelog
2
2
 
3
3
  ## Unreleased
4
+
5
+ ## v0.0.3
6
+ ### Fixed
7
+ * Fixed require on `Server`
8
+
9
+ ## v0.0.2 [YANKED]
10
+ ### Changed
11
+ * Refactored to comply with RuboCop
12
+
13
+ ## v0.0.1
4
14
  ### Added
5
15
  * Web Server
6
16
  * Base Controller Classes
@@ -1,4 +1,4 @@
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
+ 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 "contentful/webhook/listener/controllers/base"
2
- require "contentful/webhook/listener/controllers/wait"
1
+ require 'contentful/webhook/listener/controllers/base'
2
+ require 'contentful/webhook/listener/controllers/wait'
@@ -1,12 +1,14 @@
1
- require "webrick"
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
- def perform(request, response)
22
- raise "must implement"
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 "thread"
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 :timeout
10
+ attr_reader :webhook_timeout
9
11
 
10
12
  def initialize(server, wh_timeout, *options)
11
13
  super(server, options)
12
- @timeout = wh_timeout
14
+ @webhook_timeout = wh_timeout
13
15
  end
14
16
 
15
17
  protected
16
- def perform(request, response)
17
- sleep(self.timeout)
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 "contentful/webhook/listener/controllers/base"
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 = "0.0.0.0"
21
+ DEFAULT_ADDRESS = '0.0.0.0'
12
22
  DEFAULT_ENDPOINTS = [
13
23
  {
14
- endpoint: "/receive",
15
- controller: Contentful::Webhook::Listener::Controllers::Base,
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(:logger, Contentful::Webhook::Listener::Support::NullLogger.new)
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
- logger.info "Available Endpoints:"
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
- @server.mount endpoint_config[:endpoint], endpoint_config[:controller], endpoint_config[:timeout]
70
+ server.mount(
71
+ endpoint_config[:endpoint],
72
+ endpoint_config[:controller],
73
+ endpoint_config[:timeout]
74
+ )
42
75
 
43
- logger.info "\t#{endpoint_config[:endpoint]} - Controller: #{endpoint_config[:controller].name} - Timeout: #{endpoint_config[:timeout]}"
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
- @server.start
87
+ logger.info "\t#{endpoint_data.join(' - ')}"
47
88
  end
48
89
  end
49
90
  end
@@ -1 +1 @@
1
- require "contentful/webhook/listener/support/null_logger.rb"
1
+ require 'contentful/webhook/listener/support/null_logger.rb'
@@ -2,8 +2,9 @@ module Contentful
2
2
  module Webhook
3
3
  module Listener
4
4
  module Support
5
+ # NullLogger will silence any call to the :logger instance
5
6
  class NullLogger
6
- def write(body)
7
+ def write(_body)
7
8
  nil
8
9
  end
9
10
 
@@ -1,7 +1,8 @@
1
1
  module Contentful
2
2
  module Webhook
3
+ # Webhook Listener
3
4
  module Listener
4
- VERSION = "0.0.1"
5
+ VERSION = '0.0.3'
5
6
  end
6
7
  end
7
8
  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.0.1
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-10 00:00:00.000000000 Z
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.2.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