contentful-webhook-listener 0.0.4 → 0.1.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 +7 -0
- data/Rakefile +9 -1
- data/contentful-webhook-listener.gemspec +1 -0
- data/lib/contentful/webhook/listener/server.rb +6 -5
- data/lib/contentful/webhook/listener/version.rb +1 -1
- data/spec/contentful/webhook/listener/controllers/base_spec.rb +17 -0
- data/spec/contentful/webhook/listener/controllers/wait_spec.rb +42 -0
- data/spec/contentful/webhook/listener/server_spec.rb +69 -0
- data/spec/contentful/webhook/listener/support/null_logger_spec.rb +17 -0
- data/spec/spec_helper.rb +18 -0
- metadata +26 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8b4a6280628a73f9bbd6ca719228b5cbcbc7398
|
4
|
+
data.tar.gz: 92e8e9344d9f42c84ebea75180744f94d21fede4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e7b67146a95642319490f8664f56828063ed9d7bf79ba92977fbeec9784f86c4d1496aa07134d08332d0dc5fa6bf6192047704387f68bb65bb05fb6b4dc12bf
|
7
|
+
data.tar.gz: b659e728a75d5ca1f2addf41796f7da3e68c5be2e2fc920cb0cbfd8446833afd58c3d57836dd6a8837f86771b8c1ca69176f3f9b5a9cd84738ec0345909e6893
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
@@ -34,7 +34,7 @@ module Contentful
|
|
34
34
|
Thread.new { Server.new(config).start }
|
35
35
|
end
|
36
36
|
|
37
|
-
attr_reader :port, :address, :endpoints, :logger
|
37
|
+
attr_reader :port, :address, :endpoints, :logger, :server
|
38
38
|
|
39
39
|
def initialize(config = {})
|
40
40
|
@port = config.fetch(:port, DEFAULT_PORT)
|
@@ -49,15 +49,16 @@ module Contentful
|
|
49
49
|
def start
|
50
50
|
logger.info "Webhook server starting at: http://#{@address}:#{@port}"
|
51
51
|
|
52
|
+
@server = create_server
|
52
53
|
mount_endpoints
|
53
54
|
|
54
|
-
server.start
|
55
|
+
@server.start
|
55
56
|
end
|
56
57
|
|
57
58
|
protected
|
58
59
|
|
59
|
-
def
|
60
|
-
|
60
|
+
def create_server
|
61
|
+
WEBrick::HTTPServer.new(
|
61
62
|
Port: @port,
|
62
63
|
BindAddress: @address,
|
63
64
|
AccessLog: [],
|
@@ -68,7 +69,7 @@ module Contentful
|
|
68
69
|
def mount_endpoints
|
69
70
|
logger.info 'Available Endpoints:'
|
70
71
|
@endpoints.each do |endpoint_config|
|
71
|
-
server.mount(
|
72
|
+
@server.mount(
|
72
73
|
endpoint_config[:endpoint],
|
73
74
|
endpoint_config[:controller],
|
74
75
|
@logger,
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contentful::Webhook::Listener::Controllers::Base do
|
4
|
+
let(:server) { MockServer.new }
|
5
|
+
let(:logger) { Contentful::Webhook::Listener::Support::NullLogger.new }
|
6
|
+
let(:base) { Contentful::Webhook::Listener::Controllers::Base.new server, logger }
|
7
|
+
|
8
|
+
describe "instance methods" do
|
9
|
+
[:do_GET, :do_POST, :respond].each do |name|
|
10
|
+
it "##{name} spawn a background job" do
|
11
|
+
expect(Thread).to receive(:new)
|
12
|
+
|
13
|
+
base.send(name, MockRequest.new, MockResponse.new)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Contentful::Webhook::Listener::Controllers::Wait
|
4
|
+
@@sleeping = false
|
5
|
+
|
6
|
+
def sleep(time)
|
7
|
+
@@sleeping = true
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.sleeping
|
11
|
+
value = @@sleeping
|
12
|
+
@@sleeping = false
|
13
|
+
value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Contentful::Webhook::Listener::Controllers::Wait do
|
18
|
+
let(:server) { MockServer.new }
|
19
|
+
let(:logger) { Contentful::Webhook::Listener::Support::NullLogger.new }
|
20
|
+
let(:timeout) { 10 }
|
21
|
+
let(:wait) { Contentful::Webhook::Listener::Controllers::Wait.new server, logger, timeout }
|
22
|
+
|
23
|
+
describe "instance methods" do
|
24
|
+
[:do_GET, :do_POST, :respond].each do |name|
|
25
|
+
it "##{name} spawn a background job" do
|
26
|
+
expect(Thread).to receive(:new)
|
27
|
+
|
28
|
+
wait.send(name, MockRequest.new, MockResponse.new)
|
29
|
+
end
|
30
|
+
|
31
|
+
# This spec requires to read/erase a Class Variable
|
32
|
+
# because RSpec doesn't know how to test within spawned Threads
|
33
|
+
it "##{name} wait on background" do
|
34
|
+
wait.send(name, MockRequest.new, MockResponse.new)
|
35
|
+
|
36
|
+
sleep(0.1) # Wait for Thread to actually run
|
37
|
+
|
38
|
+
expect(wait.class.sleeping).to be_truthy
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contentful::Webhook::Listener::Server do
|
4
|
+
let(:server) { Contentful::Webhook::Listener::Server.new }
|
5
|
+
|
6
|
+
describe 'class methods' do
|
7
|
+
describe '::start' do
|
8
|
+
it 'spawns a brackground thread' do
|
9
|
+
expect(Thread).to receive(:new)
|
10
|
+
|
11
|
+
Contentful::Webhook::Listener::Server.start
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'instance methods' do
|
17
|
+
describe "#start" do
|
18
|
+
before do
|
19
|
+
expect_any_instance_of(WEBrick::HTTPServer).to receive(:start)
|
20
|
+
expect(WEBrick::Utils).to receive(:create_listeners) { [] } # Mock TCP Port binding
|
21
|
+
end
|
22
|
+
|
23
|
+
it "logs server messages" do
|
24
|
+
expect(server.logger).to receive(:info).once.ordered.with("Webhook server starting at: http://#{server.address}:#{server.port}")
|
25
|
+
expect(server.logger).to receive(:info).once.ordered.with("Available Endpoints:")
|
26
|
+
expect(server.logger).to receive(:info).once.ordered.with("\t/receive - Controller: Contentful::Webhook::Listener::Controllers::Wait - Timeout: 300")
|
27
|
+
|
28
|
+
server.start
|
29
|
+
end
|
30
|
+
|
31
|
+
it "mounts endpoints" do
|
32
|
+
expect_any_instance_of(WEBrick::HTTPServer).to receive(:mount).with(
|
33
|
+
"/receive",
|
34
|
+
Contentful::Webhook::Listener::Controllers::Wait,
|
35
|
+
Contentful::Webhook::Listener::Support::NullLogger,
|
36
|
+
300
|
37
|
+
)
|
38
|
+
|
39
|
+
server.start
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "defaults" do
|
45
|
+
it ":port" do
|
46
|
+
expect(server.port).to eq 5678
|
47
|
+
end
|
48
|
+
|
49
|
+
it ":address" do
|
50
|
+
expect(server.address).to eq "0.0.0.0"
|
51
|
+
end
|
52
|
+
|
53
|
+
it ":endpoints" do
|
54
|
+
expected = [
|
55
|
+
{
|
56
|
+
endpoint: '/receive',
|
57
|
+
controller: Contentful::Webhook::Listener::Controllers::Wait,
|
58
|
+
timeout: 300
|
59
|
+
}
|
60
|
+
]
|
61
|
+
|
62
|
+
expect(server.endpoints).to match_array expected
|
63
|
+
end
|
64
|
+
|
65
|
+
it ":logger" do
|
66
|
+
expect(server.logger).to be_a Contentful::Webhook::Listener::Support::NullLogger
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contentful::Webhook::Listener::Support::NullLogger do
|
4
|
+
let(:logger) { Contentful::Webhook::Listener::Support::NullLogger.new }
|
5
|
+
|
6
|
+
describe "instance methods" do
|
7
|
+
[:info, :debug, :warn, :error, :write].each do |name|
|
8
|
+
it "##{name} returns nil" do
|
9
|
+
expect(logger.send(name, "foo")).to eq nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "##{name} doesn't output to STDOUT" do
|
13
|
+
expect { logger.send(name, "foo") }.to_not output("foo").to_stdout
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('lib', __FILE__)
|
2
|
+
|
3
|
+
require 'contentful/webhook/listener'
|
4
|
+
require 'rspec'
|
5
|
+
require 'rspec/mocks'
|
6
|
+
|
7
|
+
class MockServer
|
8
|
+
def [](key)
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class MockRequest
|
14
|
+
end
|
15
|
+
|
16
|
+
class MockResponse
|
17
|
+
attr_accessor :status, :body
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH (David Litvak Bruno)
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: A Simple HTTP Webserver with pluggable behavior for listening to Contentful
|
42
56
|
API Webhooks
|
43
57
|
email:
|
@@ -64,6 +78,11 @@ files:
|
|
64
78
|
- lib/contentful/webhook/listener/support.rb
|
65
79
|
- lib/contentful/webhook/listener/support/null_logger.rb
|
66
80
|
- lib/contentful/webhook/listener/version.rb
|
81
|
+
- spec/contentful/webhook/listener/controllers/base_spec.rb
|
82
|
+
- spec/contentful/webhook/listener/controllers/wait_spec.rb
|
83
|
+
- spec/contentful/webhook/listener/server_spec.rb
|
84
|
+
- spec/contentful/webhook/listener/support/null_logger_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
67
86
|
homepage: https://github.com/contentful/contentful-webhook-listener.rb
|
68
87
|
licenses:
|
69
88
|
- MIT
|
@@ -89,4 +108,9 @@ signing_key:
|
|
89
108
|
specification_version: 4
|
90
109
|
summary: A Simple HTTP Webserver with pluggable behavior for listening to Contentful
|
91
110
|
API Webhooks
|
92
|
-
test_files:
|
111
|
+
test_files:
|
112
|
+
- spec/contentful/webhook/listener/controllers/base_spec.rb
|
113
|
+
- spec/contentful/webhook/listener/controllers/wait_spec.rb
|
114
|
+
- spec/contentful/webhook/listener/server_spec.rb
|
115
|
+
- spec/contentful/webhook/listener/support/null_logger_spec.rb
|
116
|
+
- spec/spec_helper.rb
|