Class: CurrentCostDaemon::Publishers::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/currentcostd/publishers/http.rb

Defined Under Namespace

Classes: Servlet

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Http

Returns a new instance of Http.



93
94
95
96
97
98
99
100
101
102
# File 'lib/currentcostd/publishers/http.rb', line 93

def initialize(config)
  # Initialise storage
  @watts = 0
  # Create WEBrick server
  @server = WEBrick::HTTPServer.new(:Port => config['http']['port'] )
  # Create a simple webrick servlet for HTML output
  @server.mount("/", Servlet)
  trap("INT") {@server.shutdown}
  Thread.new{@server.start}
end

Class Method Details

.config_sectionObject



31
32
33
# File 'lib/currentcostd/publishers/http.rb', line 31

def self.config_section
  'http'
end

Instance Method Details

#update(reading) ⇒ Object



104
105
106
107
108
109
# File 'lib/currentcostd/publishers/http.rb', line 104

def update(reading)
  Servlet.update(reading)
rescue
  puts "Something went wrong (http)!"
  puts $!.inspect
end