gecko 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +91 -0
- data/Rakefile +2 -0
- data/gecko.gemspec +29 -0
- data/lib/gecko.rb +22 -0
- data/lib/gecko/configurator.rb +11 -0
- data/lib/gecko/graph/funnel.rb +67 -0
- data/lib/gecko/graph/geckometer.rb +39 -0
- data/lib/gecko/graph/line.rb +64 -0
- data/lib/gecko/graph/pie.rb +49 -0
- data/lib/gecko/http.rb +79 -0
- data/lib/gecko/version.rb +3 -0
- data/lib/gecko/widget.rb +75 -0
- data/lib/gecko/widget/number_secondary_stat.rb +18 -0
- data/lib/gecko/widget/rag.rb +21 -0
- data/lib/gecko/widget/rag_columns.rb +21 -0
- data/lib/gecko/widget/text.rb +67 -0
- data/spec/gecko/funnel_spec.rb +40 -0
- data/spec/gecko/geckometer_spec.rb +38 -0
- data/spec/gecko/line_spec.rb +42 -0
- data/spec/gecko/number_and_secondary_stat_spec.rb +29 -0
- data/spec/gecko/pie_spec.rb +36 -0
- data/spec/gecko/rag_spec.rb +48 -0
- data/spec/gecko/text_spec.rb +49 -0
- data/spec/gecko_spec.rb +31 -0
- data/spec/helper.rb +25 -0
- data/spec/http_spec.rb +141 -0
- data/spec/support/shared_examples_for_widget.rb +64 -0
- data/spec/widget_spec.rb +172 -0
- metadata +246 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Adam Williams
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Gecko [](https://travis-ci.org/awilliams/Gecko)
|
2
|
+
|
3
|
+
Ruby gem for working with [Geckoboard's Push API](http://docs.geckoboard.com/custom-widgets/).
|
4
|
+
|
5
|
+
Features:
|
6
|
+
* Uses Faraday gem for HTTP. You can easily swapout adapters
|
7
|
+
* Designed for use with non-blocking requests (EventMachine)
|
8
|
+
* Allows for multiple widget keys per widget object. Useful for updating widgets on multiple dashboards at once
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'gecko'
|
15
|
+
|
16
|
+
Recommended for use with Eventmachine. Add these to your Gemfile
|
17
|
+
|
18
|
+
gem 'eventmachine'
|
19
|
+
gem 'em-http-request'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install gecko
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
### Configuration
|
31
|
+
```ruby
|
32
|
+
# Configuration
|
33
|
+
Gecko.config do |c|
|
34
|
+
# Your Geckoboard API key
|
35
|
+
c.api_key = '123456'
|
36
|
+
# block invoked by Faraday#new
|
37
|
+
# Set your http adapter here, otherwise Faraday.default_adapter is used
|
38
|
+
c.http_builder { |builder|
|
39
|
+
# use EventMachine Http adapter for non-blocking updates
|
40
|
+
builder.adapter :em_http
|
41
|
+
}
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
### Update Widgets
|
46
|
+
```ruby
|
47
|
+
# Update widget
|
48
|
+
text_widget = Gecko::Widget::Text.new("1234-widget-key")
|
49
|
+
text_widget.add("some info")
|
50
|
+
text_widget.add("this is the text", :alert)
|
51
|
+
text_widget.update { |success, result, widget_key|
|
52
|
+
puts success ? "Updated" : "Error updating #{widget_key}: #{result.error}"
|
53
|
+
}
|
54
|
+
|
55
|
+
# Update widget using #config!
|
56
|
+
text_widget = Gecko::Widget::Text.new("1234-widget-key").on_update do |success, result, widget_key|
|
57
|
+
# this block is executed on every update
|
58
|
+
puts success ? "Updated" : "Error updating #{widget_key}: #{result.error}"
|
59
|
+
end
|
60
|
+
text_widget.config! do |widget|
|
61
|
+
text_widget.add("some info")
|
62
|
+
text_widget.add("this is the text", :alert)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Update multiple widgets at once - useful for same widget on various dashboards
|
66
|
+
text_widget = Gecko::Widget::Text.new("1234-widget-key", "1234-second-widget-key").on_update do |success, result, widget_key|
|
67
|
+
# this block is executed TWICE every update since there are two widgets being updated
|
68
|
+
puts success ? "Updated" : "Error updating #{widget_key}: #{result.error}"
|
69
|
+
end
|
70
|
+
text_widget.config! do |widget|
|
71
|
+
text_widget.add("some info")
|
72
|
+
text_widget.add("this is the text", :alert)
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
### Delete reset widget values
|
77
|
+
```ruby
|
78
|
+
widget = Gecko::Widget::Text.new("1234-abcdefg")
|
79
|
+
# reset clear out previous items
|
80
|
+
widget.reset.config! do |w|
|
81
|
+
widget.add("text alert", :alert)
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
1. Fork it
|
88
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
89
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
90
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
91
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/gecko.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/gecko/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Adam Williams"]
|
6
|
+
gem.email = ["pwnfactory@gmail.com"]
|
7
|
+
gem.description = %q{Ruby library for updating Geckoboard Custom Widgets. Uses Faraday for HTTP requests and designed to work with the async API}
|
8
|
+
gem.summary = %q{Ruby library for updating Geckoboard Custom Widgets}
|
9
|
+
gem.homepage = "https://github.com/awilliams/Gecko"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = []
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "gecko"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Gecko::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "faraday", "~> 0.8.4"
|
19
|
+
gem.add_dependency "faraday_middleware-multi_json", "~> 0.0.4"
|
20
|
+
gem.add_dependency "multi_json"
|
21
|
+
|
22
|
+
gem.add_development_dependency "pry"
|
23
|
+
gem.add_development_dependency "awesome_print"
|
24
|
+
gem.add_development_dependency "yajl-ruby", "~> 1.1.0"
|
25
|
+
gem.add_development_dependency "eventmachine", "~> 1.0.0"
|
26
|
+
gem.add_development_dependency "em-http-request", "~> 1.0.0"
|
27
|
+
|
28
|
+
gem.add_development_dependency 'rspec'
|
29
|
+
end
|
data/lib/gecko.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Gecko
|
2
|
+
class << self
|
3
|
+
def config
|
4
|
+
yield self.configurator if block_given?
|
5
|
+
self.configurator
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def configurator
|
11
|
+
@configurator ||= Configurator.new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require "gecko/version" unless Gecko.const_defined?(:VERSION)
|
17
|
+
require "gecko/configurator"
|
18
|
+
require "gecko/http"
|
19
|
+
require "gecko/widget"
|
20
|
+
|
21
|
+
Gecko.config.api_push_url = 'https://push.geckoboard.com/v1/send/:widget_key'
|
22
|
+
Gecko.config.http_user_agent = "Gecko Ruby Gem #{Gecko::VERSION}"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Gecko
|
2
|
+
class Configurator
|
3
|
+
attr_accessor :api_key, :api_push_url, :http_user_agent
|
4
|
+
attr_reader :connection_builder
|
5
|
+
|
6
|
+
# Block invoked with Faraday builder when creating a connection
|
7
|
+
def http_builder(&block)
|
8
|
+
@connection_builder = block || nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Gecko
|
2
|
+
class Widget
|
3
|
+
class Funnel < Widget
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
Item = Struct.new(:value, :label)
|
7
|
+
|
8
|
+
attr_reader :reverse
|
9
|
+
|
10
|
+
def initialize(*args, &block)
|
11
|
+
super
|
12
|
+
self.standard
|
13
|
+
self.show_percentage
|
14
|
+
@items = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset
|
18
|
+
@items.clear
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def standard
|
23
|
+
@reverse = :standard
|
24
|
+
end
|
25
|
+
|
26
|
+
def reverse
|
27
|
+
@reverse = :reverse
|
28
|
+
end
|
29
|
+
|
30
|
+
def show_percentage
|
31
|
+
@percentage = :show
|
32
|
+
end
|
33
|
+
|
34
|
+
def hide_percentage
|
35
|
+
@percentage = :hide
|
36
|
+
end
|
37
|
+
|
38
|
+
def each(&block)
|
39
|
+
@items.each(&block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def add(*args)
|
43
|
+
@items.push(Item.new(*args))
|
44
|
+
end
|
45
|
+
|
46
|
+
def [](index)
|
47
|
+
@items[index]
|
48
|
+
end
|
49
|
+
|
50
|
+
def []=(index, *args)
|
51
|
+
@items[index] = Item.new(*args)
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete(index)
|
55
|
+
@items.delete_at(index)
|
56
|
+
end
|
57
|
+
|
58
|
+
def data_payload
|
59
|
+
{
|
60
|
+
:type => @reverse,
|
61
|
+
:percentage => @percentage,
|
62
|
+
:item => self.map{|item| {:value => item.value, :label => item.label} }
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Gecko
|
2
|
+
class Widget
|
3
|
+
class Geckometer < Widget
|
4
|
+
EndPoint = Struct.new(:value, :text)
|
5
|
+
|
6
|
+
attr_accessor :value
|
7
|
+
attr_reader :min, :max
|
8
|
+
def initialize(*args, &block)
|
9
|
+
super
|
10
|
+
@min, @max = EndPoint.new, EndPoint.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def min_value=(value)
|
14
|
+
self.min.value = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def min_text=(text)
|
18
|
+
self.min.text = text
|
19
|
+
end
|
20
|
+
|
21
|
+
def max_value=(value)
|
22
|
+
self.max.value = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def max_text=(text)
|
26
|
+
self.max.text = text
|
27
|
+
end
|
28
|
+
|
29
|
+
def data_payload
|
30
|
+
{
|
31
|
+
:item => self.value,
|
32
|
+
:min => {:value => self.min.value, :text => self.min.text},
|
33
|
+
:max => {:value => self.max.value, :text => self.max.text}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Gecko
|
2
|
+
class Widget
|
3
|
+
class Line < Widget
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
attr_accessor :color, :x_axis, :y_axis
|
7
|
+
|
8
|
+
def initialize(*args, &block)
|
9
|
+
super
|
10
|
+
@x_axis = []
|
11
|
+
@y_axis = []
|
12
|
+
@items = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def each(&block)
|
16
|
+
@items.each(&block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def add(*args)
|
20
|
+
@items.push(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def reset
|
24
|
+
@items.clear
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_x_axis(*args)
|
29
|
+
@x_axis.push(*args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_y_axis(*args)
|
33
|
+
@y_axis.push(*args)
|
34
|
+
end
|
35
|
+
|
36
|
+
def [](index)
|
37
|
+
@items[index]
|
38
|
+
end
|
39
|
+
|
40
|
+
def []=(index, *args)
|
41
|
+
@items[index] = *args
|
42
|
+
end
|
43
|
+
|
44
|
+
def items=(array)
|
45
|
+
@items = array
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete(index)
|
49
|
+
@items.delete_at(index)
|
50
|
+
end
|
51
|
+
|
52
|
+
def data_payload
|
53
|
+
{
|
54
|
+
:item => self.to_a,
|
55
|
+
:settings => {
|
56
|
+
:axisx => self.x_axis,
|
57
|
+
:axisy => self.y_axis,
|
58
|
+
:colour => self.color
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Gecko
|
2
|
+
class Widget
|
3
|
+
class Pie < Widget
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
Item = Struct.new(:value, :label, :color)
|
7
|
+
|
8
|
+
def initialize(*args, &block)
|
9
|
+
super
|
10
|
+
@items = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def each(&block)
|
14
|
+
@items.each(&block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset
|
18
|
+
@items.clear
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def add(*args)
|
23
|
+
@items.push(Item.new(*args))
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](index)
|
27
|
+
@items[index]
|
28
|
+
end
|
29
|
+
|
30
|
+
def []=(index, *args)
|
31
|
+
@items[index] = Item.new(*args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete(index)
|
35
|
+
@items.delete_at(index)
|
36
|
+
end
|
37
|
+
|
38
|
+
def data_payload
|
39
|
+
{:item => self.map{|item| self.item_payload(item) }}
|
40
|
+
end
|
41
|
+
|
42
|
+
def item_payload(item)
|
43
|
+
h = {:value => item.value, :label => item.label}
|
44
|
+
h.merge!({:colour => item.color}) if item.color
|
45
|
+
h
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|