Class: MSG_Chumby::LastHourImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/msg-chumby-daemon/reading-importer.rb

Instance Method Summary collapse

Constructor Details

#initialize(reading_cache, sensor_id, token) ⇒ LastHourImporter

Returns a new instance of LastHourImporter.



52
53
54
55
56
57
# File 'lib/msg-chumby-daemon/reading-importer.rb', line 52

def initialize(reading_cache, sensor_id, token)
  @reading_cache=reading_cache
  auth=Flukso::TokenAuth.new(token);
  @api=Flukso::API.new(auth, BASE_URL);
  @query=Flukso::QueryReadings.new(sensor_id, :hour, :watt)
end

Instance Method Details

#doWorkObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/msg-chumby-daemon/reading-importer.rb', line 58

def doWork
  begin
    readings=@query.execute(@api);
  rescue Exception => e
    puts "Query failed: #{e}"
    puts "Used #{BASE_URL} as BASE_URL"
    exit(-10);
  end
  #puts "Got Response:"
  #readings.each{|reading|
  #  puts reading
  #}
  @reading_cache.update_last_hour(readings);
end