Class: Sensr::Camera
- Inherits:
-
SensrObject
- Object
- SensrObject
- Sensr::Camera
- Defined in:
- lib/sensr/camera.rb
Class Method Summary collapse
-
.create(atts) ⇒ Object
Create a new camera from a hash of attributes.
-
.find(id) ⇒ Object
Find a camera by id.
-
.owned ⇒ Object
Get an array of cameras owned by the current user.
-
.shared ⇒ Object
Get an array of cameras shared with the current user.
Instance Method Summary collapse
-
#day(epoch_time = "") ⇒ Object
Get a summary of the day specified by epoch_time.
-
#destroy ⇒ Object
Delete the camera.
-
#hour(epoch_time = "") ⇒ Object
Get a summary of the hour specified by epoch_time.
-
#initialize(hash) ⇒ Camera
constructor
Create a new camera object from the attribute hash returned by a camera API call.
-
#latest ⇒ Object
Get the camera’s latest image.
-
#ledoff ⇒ Object
Turn the camera’s led off.
-
#ledon ⇒ Object
Turn the camera’s led on.
-
#localtime(epoch_time) ⇒ Object
Convert an epoch time to a date in the camera’s timezone.
-
#month(epoch_time = "") ⇒ Object
Get a summary of the month specified by epoch_time.
-
#save ⇒ Object
Save any changed parameters to the camera.
-
#week(epoch_time = "") ⇒ Object
Get a summary of the week specified by epoch_time.
-
#zoomin ⇒ Object
Send a zoom in request to the camera.
-
#zoomout ⇒ Object
Send a zoom out request to the camera.
Methods inherited from SensrObject
#attributes, #attributes=, #id, #method_missing
Constructor Details
#initialize(hash) ⇒ Camera
Create a new camera object from the attribute hash returned by a camera API call.
105 106 107 108 109 |
# File 'lib/sensr/camera.rb', line 105 def initialize(hash) # :nodoc: new_hash = hash["camera"] new_hash["urls"] = hash["urls"] 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
.create(atts) ⇒ Object
Create a new camera from a hash of attributes. The attributes “name”, “sens”, and “model” may be set.
26 27 28 29 |
# File 'lib/sensr/camera.rb', line 26 def self.create(atts) response = Sensr.request(:post, Sensr.api_base_url + '/cameras/create' , nil, atts) Camera.new(response) end |
.find(id) ⇒ Object
Find a camera by id. Only cameras owned by the current user and public cameras will be returned.
Attributes
-
id
The id of the camera to return
6 7 8 9 |
# File 'lib/sensr/camera.rb', line 6 def self.find(id) response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + id.to_s, nil) Camera.new(response) end |
Instance Method Details
#day(epoch_time = "") ⇒ Object
Get a summary of the day specified by epoch_time. If no time is provided, return the last day which has data.
Attributes
-
epoch_time
A unix timestamp
79 80 81 |
# File 'lib/sensr/camera.rb', line 79 def day(epoch_time = "") response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + self.id.to_s + "/day/" + epoch_time.to_s , nil) end |
#destroy ⇒ Object
Delete the camera
40 41 42 |
# File 'lib/sensr/camera.rb', line 40 def destroy response = Sensr.request(:delete, Sensr.api_base_url + '/cameras/' + self.attributes["id"].to_s , nil) end |
#hour(epoch_time = "") ⇒ Object
Get a summary of the hour specified by epoch_time. If no time is provided, return the last hour which has data.
Attributes
-
epoch_time
A unix timestamp
86 87 88 |
# File 'lib/sensr/camera.rb', line 86 def hour(epoch_time = "") response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + self.id.to_s + "/hour/" + epoch_time.to_s , nil) end |
#latest ⇒ Object
Get the camera’s latest image
52 53 54 |
# File 'lib/sensr/camera.rb', line 52 def latest response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + self.id.to_s + "/latest" , nil) end |
#ledoff ⇒ Object
Turn the camera’s led off
72 73 74 |
# File 'lib/sensr/camera.rb', line 72 def ledoff response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + self.id.to_s + "/ledoff" , nil) end |
#ledon ⇒ Object
Turn the camera’s led on
67 68 69 |
# File 'lib/sensr/camera.rb', line 67 def ledon response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + self.id.to_s + "/ledon" , nil) end |
#localtime(epoch_time) ⇒ Object
Convert an epoch time to a date in the camera’s timezone.
Attributes
-
epoch_time
A unix timestamp
47 48 49 |
# File 'lib/sensr/camera.rb', line 47 def localtime(epoch_time) response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + self.id.to_s + "/localtime/" + epoch_time.to_s , nil) end |
#month(epoch_time = "") ⇒ Object
Get a summary of the month specified by epoch_time. If no time is provided, return the last month which has data.
Attributes
-
epoch_time
A unix timestamp
100 101 102 |
# File 'lib/sensr/camera.rb', line 100 def month(epoch_time = "") response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + self.id.to_s + "/month/" + epoch_time.to_s , nil) end |
#save ⇒ Object
Save any changed parameters to the camera.
32 33 34 35 36 37 |
# File 'lib/sensr/camera.rb', line 32 def save response = Sensr.request(:post, Sensr.api_base_url + '/cameras/update' , nil, self.attributes) new_cam = response["camera"] new_cam["urls"] = response["urls"] self.attributes = new_cam end |
#week(epoch_time = "") ⇒ Object
Get a summary of the week specified by epoch_time. If no time is provided, return the last week which has data.
Attributes
-
epoch_time
A unix timestamp
93 94 95 |
# File 'lib/sensr/camera.rb', line 93 def week(epoch_time = "") response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + self.id.to_s + "/week/" + epoch_time.to_s , nil) end |
#zoomin ⇒ Object
Send a zoom in request to the camera
57 58 59 |
# File 'lib/sensr/camera.rb', line 57 def zoomin response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + self.id.to_s + "/zoomin" , nil) end |
#zoomout ⇒ Object
Send a zoom out request to the camera
62 63 64 |
# File 'lib/sensr/camera.rb', line 62 def zoomout response = Sensr.request(:get, Sensr.api_base_url + '/cameras/' + self.id.to_s + "/zoomout" , nil) end |