Class: Geckoboard::Push
- Inherits:
-
Object
- Object
- Geckoboard::Push
- Includes:
- HTTParty
- Defined in:
- lib/geckoboard/push.rb
Defined Under Namespace
Classes: Error
Class Attribute Summary collapse
-
.api_key ⇒ Object
API configuration.
-
.api_version ⇒ Object
Returns the value of attribute api_version.
Instance Method Summary collapse
-
#funnel(items, reverse = false, hide_percentage = false) ⇒ Object
Items should be an array of hashes, each hash containing: - value (numeric value) - label (optional) Reverse defaults to false, and when true flips the colours on the widget Hide percentage defaults to false, and when true hides the percentage value on the widget.
-
#geckometer(value, min, max) ⇒ Object
Value, min and max should be numeric values.
-
#initialize(widget_key) ⇒ Push
constructor
Initializes the push object for a specific widget.
-
#line(values, colour = nil, x_axis = nil, y_axis = nil) ⇒ Object
Values should be an array of numeric values Colour, x_axis and y_axis are optional settings.
-
#number_and_secondary_value(value, previous_value) ⇒ Object
Value and previous value should be numeric values.
-
#pie(items) ⇒ Object
Items should be an array of hashes, each hash containing: - value (numeric value) - label (optional) - colour (optional).
-
#push(data) ⇒ Object
Makes a call to Geckoboard to push data to the current widget.
-
#rag(red, amber, green) ⇒ Object
Red, amber and green should be values.
-
#text(items) ⇒ Object
Items should be an array of hashes, each hash containing: - text - type (should be either :alert, or :info, optional).
Constructor Details
#initialize(widget_key) ⇒ Push
Initializes the push object for a specific widget
20 21 22 |
# File 'lib/geckoboard/push.rb', line 20 def initialize() @widget_key = end |
Class Attribute Details
.api_key ⇒ Object
API configuration
9 10 11 |
# File 'lib/geckoboard/push.rb', line 9 def api_key @api_key end |
.api_version ⇒ Object
Returns the value of attribute api_version.
10 11 12 |
# File 'lib/geckoboard/push.rb', line 10 def api_version @api_version end |
Instance Method Details
#funnel(items, reverse = false, hide_percentage = false) ⇒ Object
Items should be an array of hashes, each hash containing:
-
value (numeric value)
-
label (optional)
Reverse defaults to false, and when true flips the colours on the widget Hide percentage defaults to false, and when true hides the percentage value on the widget
87 88 89 90 91 92 93 94 95 |
# File 'lib/geckoboard/push.rb', line 87 def funnel(items, reverse = false, hide_percentage = false) data = items.collect do |item| {:value => item[:value], :label => item[:label]} end opts = {:item => data} opts[:type] = "reverse" if reverse opts[:percentage] = "hide" if hide_percentage self.push(opts) end |
#geckometer(value, min, max) ⇒ Object
Value, min and max should be numeric values
78 79 80 |
# File 'lib/geckoboard/push.rb', line 78 def geckometer(value, min, max) self.push(:item => value, :min => {:value => min}, :max => {:value => max}) end |
#line(values, colour = nil, x_axis = nil, y_axis = nil) ⇒ Object
Values should be an array of numeric values Colour, x_axis and y_axis are optional settings
62 63 64 |
# File 'lib/geckoboard/push.rb', line 62 def line(values, colour = nil, x_axis = nil, y_axis = nil) self.push(:item => values, :settings => {:axisx => x_axis, :axisy => y_axis, :colour => colour}) end |
#number_and_secondary_value(value, previous_value) ⇒ Object
Value and previous value should be numeric values
33 34 35 |
# File 'lib/geckoboard/push.rb', line 33 def number_and_secondary_value(value, previous_value) self.push(:item => [{:text => "", :value => value}, {:text => "", :value => previous_value}]) end |
#pie(items) ⇒ Object
Items should be an array of hashes, each hash containing:
-
value (numeric value)
-
label (optional)
-
colour (optional)
70 71 72 73 74 75 |
# File 'lib/geckoboard/push.rb', line 70 def pie(items) data = items.collect do |item| {:value => item[:value], :label => item[:label], :colour => item[:colour]} end self.push(:item => data) end |
#push(data) ⇒ Object
Makes a call to Geckoboard to push data to the current widget
25 26 27 28 29 30 |
# File 'lib/geckoboard/push.rb', line 25 def push(data) raise Geckoboard::Push::Error.new("Api key not configured.") if Geckoboard::Push.api_key.nil? || Geckoboard::Push.api_key.empty? result = JSON.parse(self.class.post("/#{Geckoboard::Push.api_version || 'v1'}/send/#{@widget_key}", {:body => {:api_key => Geckoboard::Push.api_key, :data => data}.to_json})) raise Geckoboard::Push::Error.new(result["error"]) unless result["success"] result["success"] end |
#rag(red, amber, green) ⇒ Object
Red, amber and green should be values
56 57 58 |
# File 'lib/geckoboard/push.rb', line 56 def rag(red, amber, green) self.push(:item => [{:value => red}, {:value => amber}, {:value => green}]) end |
#text(items) ⇒ Object
Items should be an array of hashes, each hash containing:
-
text
-
type (should be either :alert, or :info, optional)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/geckoboard/push.rb', line 40 def text(items) data = items.collect do |item| type = case item[:type] when :alert 1 when :info 2 else 0 end {:text => item[:text], :type => type} end self.push(:item => data) end |