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.



97
98
99
100
101
102
103
104
105
106
# File 'lib/currentcostd/publishers/http.rb', line 97

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



108
109
110
111
112
113
114
115
# File 'lib/currentcostd/publishers/http.rb', line 108

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