Class: Contentful::Webhook::Listener::Server

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#addressObject (readonly)

Returns the value of attribute address.



37
38
39
# File 'lib/contentful/webhook/listener/server.rb', line 37

def address
  @address
end

#endpointsObject (readonly)

Returns the value of attribute endpoints.



37
38
39
# File 'lib/contentful/webhook/listener/server.rb', line 37

def endpoints
  @endpoints
end

#loggerObject (readonly)

Returns the value of attribute logger.



37
38
39
# File 'lib/contentful/webhook/listener/server.rb', line 37

def logger
  @logger
end

#portObject (readonly)

Returns the value of attribute port.



37
38
39
# File 'lib/contentful/webhook/listener/server.rb', line 37

def port
  @port
end

#serverObject (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

Yields:

  • (config)


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

#startObject



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