class Ducksboard::Widget
Constants
- PULL_URI
- PUSH_URI
Attributes
data[RW]
id[RW]
type[RW]
Public Class Methods
new(id, data={})
click to toggle source
# File lib/ducksboard/widget.rb, line 8 def initialize(id, data={}) @id = id @data = data end
Public Instance Methods
last_values(number_of_values=3)
click to toggle source
# File lib/ducksboard/widget.rb, line 48 def last_values(number_of_values=3) pull("last?count=#{number_of_values}") end
save()
click to toggle source
# File lib/ducksboard/widget.rb, line 36 def save if valid? update.code.to_i == 200 else raise "Invalid Data: #{@data.inspect}" end end
since(seconds_ago=3600)
click to toggle source
# File lib/ducksboard/widget.rb, line 52 def since(seconds_ago=3600) pull("since?seconds=#{seconds_ago.to_i}") end
timespan(timespan=:monthly, timezone="UTC")
click to toggle source
# File lib/ducksboard/widget.rb, line 56 def timespan(timespan=:monthly, timezone="UTC") pull("timespan?timespan=#{timespan.to_s}&timezone=#{timezone}") end
timestamp()
click to toggle source
# File lib/ducksboard/widget.rb, line 21 def timestamp @data[:timestamp] end
timestamp=(time)
click to toggle source
# File lib/ducksboard/widget.rb, line 25 def timestamp=(time) @data[:timestamp] = time end
update(data=nil)
click to toggle source
# File lib/ducksboard/widget.rb, line 29 def update(data=nil) @data = data if data self.class.post("#{PUSH_URI}/#{@id.to_s}", :basic_auth => auth, :body => @data.to_json) end
valid?()
click to toggle source
# File lib/ducksboard/widget.rb, line 44 def valid? true end
value()
click to toggle source
# File lib/ducksboard/widget.rb, line 13 def value @data[:value] end
value=(val)
click to toggle source
# File lib/ducksboard/widget.rb, line 17 def value=(val) @data[:value] = val end
Private Instance Methods
auth()
click to toggle source
# File lib/ducksboard/widget.rb, line 65 def auth() {:username => ::Ducksboard.api_key, :password => "ducksboard-gem"} end
pull(service_uri)
click to toggle source
# File lib/ducksboard/widget.rb, line 69 def pull(service_uri) response = self.class.get("#{PULL_URI}/#{@id.to_s}/#{service_uri}", :basic_auth => auth) if response.code.to_i == 200 JSON.parse(response.body) else raise "Unexpected response code: #{response.code}; body: #{response.body}" end end