class DNSUpdater::Web

HTTP updater web server

Public Class Methods

getServerConfig(webConfig, protocol, params) click to toggle source
# 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
new(configFile) click to toggle source
# File lib/dnsupdater/web.rb, line 11
def initialize(configFile)
    @Config = Config.new(configFile)
    @HTTP = Updaters::HTTP.new(@Config)
end
startServer(configFile, protocol, params) click to toggle source
# 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

Public Instance Methods

call(env) click to toggle source
# File lib/dnsupdater/web.rb, line 20
def call(env)
    @HTTP.call(env)
rescue RuntimeError => e
    @HTTP.class.formatResponse(500, e.message)
end
getConfig() click to toggle source
# File lib/dnsupdater/web.rb, line 16
def getConfig
    @Config
end