Class: CS::EndPoint::SensorData
- Inherits:
-
Object
- Object
- CS::EndPoint::SensorData
show all
- Includes:
- CS::EndPoint
- Defined in:
- lib/cs/end_point/sensor_data.rb
Overview
This object represent a sensor data point usage example:
client = CS::Client.new
client.login('username', 'password')
# Find the first position sensor
sensor = client.sensors.find_by_name(/position/).first
# save data point
data = sensor.data.build
data.date = Time.now
data.value = {"lux": 1}
data.save!
# more compact version
sensor.data.build(date: Time.now, value: {"lux => 1}).save!
Instance Attribute Summary collapse
Attributes included from CS::EndPoint
#session
Instance Method Summary
collapse
#create, #create!, #delete, #delete!, #duplicate, #initialize, #inspect, #parameter, #reload, #reload!, #retrieve, #save, #save!, #update, #url_for
Methods included from Serializer
#from_hash, #to_h
Instance Attribute Details
#month ⇒ Object
Returns the value of attribute month.
24
25
26
|
# File 'lib/cs/end_point/sensor_data.rb', line 24
def month
@month
end
|
#week ⇒ Object
Returns the value of attribute week.
24
25
26
|
# File 'lib/cs/end_point/sensor_data.rb', line 24
def week
@week
end
|
#year ⇒ Object
Returns the value of attribute year.
24
25
26
|
# File 'lib/cs/end_point/sensor_data.rb', line 24
def year
@year
end
|
Instance Method Details
#date_human ⇒ Object
46
47
48
|
# File 'lib/cs/end_point/sensor_data.rb', line 46
def date_human
Time.new(@date)
end
|
#delete_url ⇒ Object
76
77
78
|
# File 'lib/cs/end_point/sensor_data.rb', line 76
def delete_url
"/sensors/#{sensor_id}/data/#{id}.json"
end
|
#get_url ⇒ Object
68
69
70
|
# File 'lib/cs/end_point/sensor_data.rb', line 68
def get_url
"/sensors/#{sensor_id}/data/#{id}.json"
end
|
#post_url ⇒ Object
64
65
66
|
# File 'lib/cs/end_point/sensor_data.rb', line 64
def post_url
"/sensors/#{sensor_id}/data.json"
end
|
#put_url ⇒ Object
72
73
74
|
# File 'lib/cs/end_point/sensor_data.rb', line 72
def put_url
"/sensors/#{sensor_id}/data/#{id}.json"
end
|
#retrieve! ⇒ Object
there is no currently end point for geting data by id
51
52
53
|
# File 'lib/cs/end_point/sensor_data.rb', line 51
def retrieve!
raise Error::NotImplementedError, "There is no current end point to get sensor data by id"
end
|
60
61
62
|
# File 'lib/cs/end_point/sensor_data.rb', line 60
def ()
.scan(/.*\/sensors\/(.*)\/(.*)/)[1] if
end
|
#to_cs_value ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/cs/end_point/sensor_data.rb', line 29
def to_cs_value
param = self.to_h(false)
param.delete(:sensor_id)
value = param[:value]
if value
param[:value] = value.to_json unless value.kind_of?(String) || value.kind_of?(Numeric)
end
param[:date] = CS::Time.new(date).to_f if param[:date]
param
end
|
#to_parameters ⇒ Object
42
43
44
|
# File 'lib/cs/end_point/sensor_data.rb', line 42
def to_parameters
{data: [to_cs_value]}
end
|
#update! ⇒ Object
there is no currently end point for updating data
56
57
58
|
# File 'lib/cs/end_point/sensor_data.rb', line 56
def update!
raise Error::NotImplementedError, "There is no current end point to update sensor data by id"
end
|