contentful-webhook-listener 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a2be61a4cf62efe827b97bf7dbf43d8191e75df8
4
+ data.tar.gz: 16b18e95e56e0371971fc203e1f0002cf20559e7
5
+ SHA512:
6
+ metadata.gz: 9d745232369334ff7f9688afddd3943954adeec048d7c7dc44c1fbf72bcb7c27f53716a1ad4a5bf6e83cf8e57f0cd102f939b2a4a357818f65395f84034b7596
7
+ data.tar.gz: b796a3748378a5dd8dadbe0502482a3c636841ef7f461042185b2bce9731a64badee7c5770be1c9e3d200c49dbdf1bab0cf61dea372d17c61570d4735a8daad1
@@ -0,0 +1,42 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ /.config
5
+ Gemfile.lock
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+ *.bundle
14
+ *.so
15
+ *.o
16
+ *.a
17
+ mkmf.log
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+
24
+ ## Documentation cache and generated files:
25
+ /.yardoc/
26
+ /_yardoc/
27
+ /doc/
28
+ /rdoc/
29
+
30
+ ## Environment normalisation:
31
+ /.bundle/
32
+ /vendor/bundle
33
+ /lib/bundler/man/
34
+
35
+ # for a library or gem, you might want to ignore these files since the code is
36
+ # intended to run in multiple environments; otherwise, check them in:
37
+ # Gemfile.lock
38
+ # .ruby-version
39
+ # .ruby-gemset
40
+
41
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
42
+ .rvmrc
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - jruby-19mode
5
+
6
+ env: TEST=true
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+ ### Added
5
+ * Web Server
6
+ * Base Controller Classes
@@ -0,0 +1,43 @@
1
+ # Contributing
2
+ In the spirit of [free software][free-sw], **everyone** is encouraged to help
3
+ improve this project.
4
+
5
+ [free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
6
+
7
+ Here are some ways *you* can contribute:
8
+
9
+ * by using alpha, beta, and prerelease versions
10
+ * by reporting bugs
11
+ * by suggesting new features
12
+ * by writing or editing documentation
13
+ * by writing specifications
14
+ * by writing code ( **no patch is too small** : fix typos, add comments, clean up inconsistent whitespace )
15
+ * by refactoring code
16
+ * by closing [issues][]
17
+ * by reviewing patches
18
+
19
+ [issues]: https://github.com/contentful/contentful-webhook-listener.rb/issues
20
+
21
+ ## Submitting an Issue
22
+ We use the [GitHub issue tracker][issues] to track bugs and features. Before
23
+ submitting a bug report or feature request, check to make sure it hasn't
24
+ already been submitted. When submitting a bug report, please include a [Gist][]
25
+ that includes a stack trace and any details that may be necessary to reproduce
26
+ the bug, including your gem version, Ruby version, and operating system.
27
+ Ideally, a bug report should include a pull request with failing specs.
28
+
29
+ [gist]: https://gist.github.com/
30
+
31
+ ## Submitting a Pull Request
32
+ 1. [Fork the repository.][fork]
33
+ 2. [Create a topic branch.][branch]
34
+ 3. Add specs for your unimplemented feature or bug fix.
35
+ 4. Run `bundle exec rake test`. If your specs pass, return to step 3.
36
+ 5. Implement your feature or bug fix.
37
+ 6. Run `bundle exec rake test`. If your specs fail, return to step 5.
38
+ 7. Add, commit, and push your changes.
39
+ 8. [Submit a pull request.][pr]
40
+
41
+ [fork]: http://help.github.com/fork-a-repo/
42
+ [branch]: http://learn.github.com/p/branching.html
43
+ [pr]: http://help.github.com/send-pull-requests/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in contentful-webhook-listener.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Contentful
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 David Litvak Bruno
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ [![Build Status](https://travis-ci.org/contentful/contentful-webhook-listener.rb.svg)](https://travis-ci.org/contentful/contentful-webhook-listener.rb)
2
+
3
+ # Contentful Webhook Listener
4
+
5
+ A Simple HTTP Webserver with pluggable behavior for listening to API Webhooks
6
+
7
+ ## Contentful
8
+ [Contentful](http://www.contentful.com) is a content management platform for web applications,
9
+ mobile apps and connected devices. It allows you to create, edit & manage content in the cloud
10
+ and publish it anywhere via powerful API. Contentful offers tools for managing editorial
11
+ teams and enabling cooperation between organizations.
12
+
13
+ ## What does `contentful-webhook-listener` do?
14
+ The aim of `contentful-webhook-listener` is to have developers setting up their Contentful
15
+ Webhooks for triggering background jobs.
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ gem 'contentful-webhook-listener'
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install contentful-webhook-listener
30
+
31
+ ## Usage
32
+
33
+ Require gem:
34
+
35
+ ```ruby
36
+ require 'contentful/webhook/listener'
37
+ ```
38
+
39
+ Create your own Controllers:
40
+
41
+ ```ruby
42
+ class MyController < Contentful::Webhook::Listener::Controllers::Wait
43
+ def perform(request, response)
44
+ super(request, response)
45
+ "do your process..." # This will run on a brackground Thread
46
+ end
47
+ end
48
+ ```
49
+
50
+ Configure and start your Webhook Listener
51
+
52
+ ```ruby
53
+ require 'logger'
54
+
55
+ Contentful::Webhook::Listener::Server.start do |config|
56
+ config[:port] = 5678 # Optional
57
+ config[:address] = "0.0.0.0" # Optional
58
+ config[:logger] = Logger.new(STDOUT) # Optional, will use a NullLogger by default
59
+ config[:endpoints] = [
60
+ {
61
+ endpoint: "/receive", # Where your server will listen
62
+ controller: MyController, # The controller that will process the endpoint
63
+ timeout: 15 # If using Wait, will wait `X` seconds before executing
64
+ }
65
+ ]
66
+ end
67
+ ```
68
+
69
+ You can add multiple endpoints, each with it's own Controller.
70
+
71
+ ## Contributing
72
+
73
+ 1. Fork it ( https://github.com/[my-github-username]/contentful-webhook-listener/fork )
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create a new Pull Request
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :install
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'contentful/webhook/listener/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "contentful-webhook-listener"
8
+ spec.version = Contentful::Webhook::Listener::VERSION
9
+ spec.authors = ["Contentful GmbH (David Litvak Bruno)"]
10
+ spec.email = ["david.litvak@contentful.com"]
11
+ spec.summary = %q{A Simple HTTP Webserver with pluggable behavior for listening to Contentful API Webhooks}
12
+ spec.description = %q{A Simple HTTP Webserver with pluggable behavior for listening to Contentful API Webhooks}
13
+ spec.homepage = "https://github.com/contentful/contentful-webhook-listener.rb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +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"
@@ -0,0 +1,2 @@
1
+ require "contentful/webhook/listener/controllers/base"
2
+ require "contentful/webhook/listener/controllers/wait"
@@ -0,0 +1,28 @@
1
+ require "webrick"
2
+
3
+ module Contentful
4
+ module Webhook
5
+ module Listener
6
+ module Controllers
7
+ class Base < WEBrick::HTTPServlet::AbstractServlet
8
+ def respond(request, response)
9
+ response.body = ""
10
+ response.status = 200
11
+
12
+ Thread.new do
13
+ perform(request, response)
14
+ end
15
+ end
16
+
17
+ alias_method :do_GET, :respond
18
+ alias_method :do_POST, :respond
19
+
20
+ protected
21
+ def perform(request, response)
22
+ raise "must implement"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ require "thread"
2
+
3
+ module Contentful
4
+ module Webhook
5
+ module Listener
6
+ module Controllers
7
+ class Wait < Base
8
+ attr_reader :timeout
9
+
10
+ def initialize(server, wh_timeout, *options)
11
+ super(server, options)
12
+ @timeout = wh_timeout
13
+ end
14
+
15
+ protected
16
+ def perform(request, response)
17
+ sleep(self.timeout)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,51 @@
1
+ require 'thread'
2
+ require 'webrick'
3
+ require 'stringio'
4
+ require "contentful/webhook/listener/controllers/base"
5
+
6
+ module Contentful
7
+ module Webhook
8
+ module Listener
9
+ class Server
10
+ DEFAULT_PORT = 5678
11
+ DEFAULT_ADDRESS = "0.0.0.0"
12
+ DEFAULT_ENDPOINTS = [
13
+ {
14
+ endpoint: "/receive",
15
+ controller: Contentful::Webhook::Listener::Controllers::Base,
16
+ timeout: 300
17
+ }
18
+ ]
19
+
20
+ def self.start(config = {})
21
+ yield config if block_given?
22
+
23
+ Thread.new { Server.new(config).start }
24
+ end
25
+
26
+ attr_reader :port, :address, :endpoints, :logger
27
+
28
+ def initialize(config = {})
29
+ @port = config.fetch(:port, DEFAULT_PORT)
30
+ @address = config.fetch(:address, DEFAULT_ADDRESS)
31
+ @endpoints = config.fetch(:endpoints, DEFAULT_ENDPOINTS)
32
+ @logger = config.fetch(:logger, Contentful::Webhook::Listener::Support::NullLogger.new)
33
+ end
34
+
35
+ def start
36
+ @server = WEBrick::HTTPServer.new(:Port => @port, :BindAddress => @address, :AccessLog => [], :Logger => @logger)
37
+
38
+ logger.info "Webhook server starting at: http://#{@address}:#{@port}"
39
+ logger.info "Available Endpoints:"
40
+ @endpoints.each do |endpoint_config|
41
+ @server.mount endpoint_config[:endpoint], endpoint_config[:controller], endpoint_config[:timeout]
42
+
43
+ logger.info "\t#{endpoint_config[:endpoint]} - Controller: #{endpoint_config[:controller].name} - Timeout: #{endpoint_config[:timeout]}"
44
+ end
45
+
46
+ @server.start
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1 @@
1
+ require "contentful/webhook/listener/support/null_logger.rb"
@@ -0,0 +1,18 @@
1
+ module Contentful
2
+ module Webhook
3
+ module Listener
4
+ module Support
5
+ class NullLogger
6
+ def write(body)
7
+ nil
8
+ end
9
+
10
+ alias_method :info, :write
11
+ alias_method :debug, :write
12
+ alias_method :warn, :write
13
+ alias_method :error, :write
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module Contentful
2
+ module Webhook
3
+ module Listener
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contentful-webhook-listener
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Contentful GmbH (David Litvak Bruno)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A Simple HTTP Webserver with pluggable behavior for listening to Contentful
42
+ API Webhooks
43
+ email:
44
+ - david.litvak@contentful.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - CHANGELOG.md
52
+ - CONTRIBUTING.md
53
+ - Gemfile
54
+ - LICENSE
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - contentful-webhook-listener.gemspec
59
+ - lib/contentful/webhook/listener.rb
60
+ - lib/contentful/webhook/listener/controllers.rb
61
+ - lib/contentful/webhook/listener/controllers/base.rb
62
+ - lib/contentful/webhook/listener/controllers/wait.rb
63
+ - lib/contentful/webhook/listener/server.rb
64
+ - lib/contentful/webhook/listener/support.rb
65
+ - lib/contentful/webhook/listener/support/null_logger.rb
66
+ - lib/contentful/webhook/listener/version.rb
67
+ homepage: https://github.com/contentful/contentful-webhook-listener.rb
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.2.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: A Simple HTTP Webserver with pluggable behavior for listening to Contentful
91
+ API Webhooks
92
+ test_files: []