Class: Sensr::Device

Inherits:
SensrObject show all
Defined in:
lib/sensr/device.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SensrObject

#attributes, #attributes=, #id, #method_missing

Constructor Details

#initialize(id, hash) ⇒ Device

:nodoc:



4
5
6
7
8
# File 'lib/sensr/device.rb', line 4

def initialize(id, hash) # :nodoc:
  new_hash = hash["device"]
  new_hash["id"] = id if new_hash && new_hash.size > 0 && new_hash["id"].nil?
  super(new_hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sensr::SensrObject

Class Method Details

.find(id) ⇒ Object

Find a device by id

Attributes

  • id id of the device to be returned



13
14
15
16
# File 'lib/sensr/device.rb', line 13

def self.find(id)
  response = Sensr.request(:get, Sensr.api_base_url + '/devices/' + id.to_s, nil)
  Device.new(id, response)
end

Instance Method Details

#saveObject

Save any updated device attributes



19
20
21
22
23
24
25
# File 'lib/sensr/device.rb', line 19

def save
  response = Sensr.request(:put, 
                           Sensr.api_base_url + '/devices/' + self.attributes["id"].to_s, 
                           nil, 
                           self.attributes)
  self.attributes = response["device"]
end