Class: Geckoboard::Push
- Inherits:
-
Object
- Object
- Geckoboard::Push
- Includes:
- HTTParty
- Defined in:
- lib/geckoboard/push.rb
Defined Under Namespace
Classes: Error
Instance 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(api_key, 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, prefix = nil) ⇒ 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(text_red, red, text_amber, amber, text_green, 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(api_key, widget_key) ⇒ Push
Initializes the push object for a specific widget
18 19 20 21 |
# File 'lib/geckoboard/push.rb', line 18 def initialize(api_key, ) @api_key = api_key @widget_key = end |
Instance Attribute Details
#api_key ⇒ Object
API configuration
8 9 10 |
# File 'lib/geckoboard/push.rb', line 8 def api_key @api_key end |
#api_version ⇒ Object
Returns the value of attribute api_version.
9 10 11 |
# File 'lib/geckoboard/push.rb', line 9 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
88 89 90 91 92 93 94 95 96 |
# File 'lib/geckoboard/push.rb', line 88 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
79 80 81 |
# File 'lib/geckoboard/push.rb', line 79 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
63 64 65 |
# File 'lib/geckoboard/push.rb', line 63 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, prefix = nil) ⇒ Object
Value and previous value should be numeric values
32 33 34 35 36 |
# File 'lib/geckoboard/push.rb', line 32 def number_and_secondary_value(value, previous_value, prefix = nil) item = {:text => "", :value => value} item.merge!({:prefix => prefix}) if prefix self.push(:item => [item, {: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)
71 72 73 74 75 76 |
# File 'lib/geckoboard/push.rb', line 71 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
24 25 26 27 28 29 |
# File 'lib/geckoboard/push.rb', line 24 def push(data) raise Geckoboard::Push::Error.new("Api key not configured.") if @api_key.nil? || @api_key.empty? result = JSON.parse(self.class.post("/#{@api_version || 'v1'}/send/#{@widget_key}", {:body => {:api_key => @api_key, :data => data}.to_json})) raise Geckoboard::Push::Error.new(result["error"]) unless result["success"] result["success"] end |
#rag(text_red, red, text_amber, amber, text_green, green) ⇒ Object
Red, amber and green should be values
57 58 59 |
# File 'lib/geckoboard/push.rb', line 57 def rag(text_red, red, text_amber, amber, text_green, green) self.push(:item => [{:value => red, :text => text_red}, {:value => amber, :text => text_amber}, {:value => green, :text => text_green}]) end |
#text(items) ⇒ Object
Items should be an array of hashes, each hash containing:
-
text
-
type (should be either :alert, or :info, optional)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/geckoboard/push.rb', line 41 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 |