Class: Contentful::Webhook::Listener::Server
- Inherits:
-
Object
- Object
- Contentful::Webhook::Listener::Server
- Defined in:
- lib/contentful/webhook/listener/server.rb
Overview
Server is the responsible for handling Webhook receiver endpoints Configuration defaults are:
- port: 5678
- address: '0.0.0.0'
- logger: Contentful::Webhook::Support::NullLogger.new
- endpoints: [{
endpoint: '/receive',
controller: Contentful::Webhook::Listener::Controllers::Wait,
timeout: 300
}]
Constant Summary collapse
- DEFAULT_PORT =
5678- DEFAULT_ADDRESS =
'0.0.0.0'- DEFAULT_ENDPOINTS =
[ { endpoint: '/receive', controller: Contentful::Webhook::Listener::Controllers::Wait, timeout: 300 } ]
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#endpoints ⇒ Object
readonly
Returns the value of attribute endpoints.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Server
Returns a new instance of Server.
39 40 41 42 43 44 45 46 47 |
# File 'lib/contentful/webhook/listener/server.rb', line 39 def initialize(config = {}) @port = config.fetch(:port, DEFAULT_PORT) @address = config.fetch(:address, DEFAULT_ADDRESS) @endpoints = config.fetch(:endpoints, DEFAULT_ENDPOINTS) @logger = config.fetch( :logger, Contentful::Webhook::Listener::Support::NullLogger.new ) end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
37 38 39 |
# File 'lib/contentful/webhook/listener/server.rb', line 37 def address @address end |
#endpoints ⇒ Object (readonly)
Returns the value of attribute endpoints.
37 38 39 |
# File 'lib/contentful/webhook/listener/server.rb', line 37 def endpoints @endpoints end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
37 38 39 |
# File 'lib/contentful/webhook/listener/server.rb', line 37 def logger @logger end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
37 38 39 |
# File 'lib/contentful/webhook/listener/server.rb', line 37 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
37 38 39 |
# File 'lib/contentful/webhook/listener/server.rb', line 37 def server @server end |
Class Method Details
.start(config = {}) {|config| ... } ⇒ Object
31 32 33 34 35 |
# File 'lib/contentful/webhook/listener/server.rb', line 31 def self.start(config = {}) yield config if block_given? Thread.new { Server.new(config).start } end |
Instance Method Details
#start ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/contentful/webhook/listener/server.rb', line 49 def start logger.info "Webhook server starting at: http://#{@address}:#{@port}" @server = create_server mount_endpoints @server.start end |