Class: DNSUpdater::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsupdater/web.rb

Overview

HTTP updater web server

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configFile) ⇒ Web

Returns a new instance of Web.



11
12
13
14
# File 'lib/dnsupdater/web.rb', line 11

def initialize(configFile)
    @Config = Config.new(configFile)
    @HTTP = Updaters::HTTP.new(@Config)
end

Class Method Details

.getServerConfig(webConfig, protocol, params) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dnsupdater/web.rb', line 35

def self.getServerConfig(webConfig, protocol, params)
    webConfig.setTargetProtocol(:http, protocol)

    config = Hash[webConfig['HTTP'].map { |k, v| [k.to_sym, v] }]

    config[:Host] = Addressable::IDNA.to_ascii(params[:Server]) unless params[:Server].to_s.empty?
    config[:Port] = params[:Port] if params[:Port].to_i.positive?
    config[:environment] = 'production'

    config
end

.startServer(configFile, protocol, params) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/dnsupdater/web.rb', line 26

def self.startServer(configFile, protocol, params)
    web = new(configFile)
    config = getServerConfig(web.getConfig, protocol, params)

    Rack::Handler::Puma.run(web, config)
rescue IOError, SocketError, SystemCallError => e
    raise Error, self.class.name + ': ' + e.message
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
# File 'lib/dnsupdater/web.rb', line 20

def call(env)
    @HTTP.call(env)
rescue RuntimeError => e
    @HTTP.class.formatResponse(500, e.message)
end

#getConfigObject



16
17
18
# File 'lib/dnsupdater/web.rb', line 16

def getConfig
    @Config
end