Class: Ducksboard::Widget
- Inherits:
-
Object
- Object
- Ducksboard::Widget
show all
- Includes:
- HTTParty
- Defined in:
- lib/ducksboard/widget.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(id, data = {}) ⇒ Widget
Returns a new instance of Widget.
9
10
11
12
|
# File 'lib/ducksboard/widget.rb', line 9
def initialize(id, data={})
@id = id
@data = data
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7
8
9
|
# File 'lib/ducksboard/widget.rb', line 7
def data
@data
end
|
#id ⇒ Object
Returns the value of attribute id.
7
8
9
|
# File 'lib/ducksboard/widget.rb', line 7
def id
@id
end
|
#type ⇒ Object
Returns the value of attribute type.
7
8
9
|
# File 'lib/ducksboard/widget.rb', line 7
def type
@type
end
|
Instance Method Details
#save ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/ducksboard/widget.rb', line 38
def save
if valid?
update.code.to_i == 200
else
raise "Invalid Data: #{@data.inspect}"
end
end
|
#timestamp ⇒ Object
22
23
24
|
# File 'lib/ducksboard/widget.rb', line 22
def timestamp
@data[:timestamp]
end
|
#timestamp=(time) ⇒ Object
26
27
28
|
# File 'lib/ducksboard/widget.rb', line 26
def timestamp=(time)
@data[:timestamp] = time
end
|
#update(data = nil) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/ducksboard/widget.rb', line 30
def update(data=nil)
@data = data if data
auth = {:username => ::Ducksboard.api_key, :password => "ducksboard-gem"}
self.class.post('/' + id.to_s,
:basic_auth => auth,
:body => @data.to_json)
end
|
#valid? ⇒ Boolean
46
47
48
|
# File 'lib/ducksboard/widget.rb', line 46
def valid?
true
end
|
#value ⇒ Object
14
15
16
|
# File 'lib/ducksboard/widget.rb', line 14
def value
@data[:value]
end
|
#value=(val) ⇒ Object
18
19
20
|
# File 'lib/ducksboard/widget.rb', line 18
def value=(val)
@data[:value] = val
end
|