Class: FluksoLocal::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/msg-flukso-localinterface/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ Query

Returns a new instance of Query.



7
8
9
# File 'lib/msg-flukso-localinterface/query.rb', line 7

def initialize(location)
  @location=location;
end

Instance Method Details

#getRawReadings(sensor_id) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/msg-flukso-localinterface/query.rb', line 10

def getRawReadings(sensor_id)
  page="/sensor/#{sensor_id}"
  values=nil
  begin
  Net::HTTP.start(@location.host) do |http|
    puts "retrieving #{page}" if $verbose
    response=http.get(page);
    puts "Raw Response:" if $verbose
    puts response.body if $verbose
    values=response.body
  end
  rescue StandardError => bang
    puts "Cannot query flukso: #{bang}"
  end
  return values 
end

#getReadings(sensor_id) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/msg-flukso-localinterface/query.rb', line 26

def getReadings(sensor_id)
  # todo: make appropriate nil values
  retval=Hash.new
  values=getRawReadings(sensor_id);
  if values != nil
    tmp=JSON.parse(values);
    tmp.each{|value|
      timestamp=value[0]
      value=value[1]
      #puts "Found #{timestamp} => #{value}"
      retval[timestamp]=value;
    }
  end
  jj retval if $verbose;
  return retval;
end