gecko-pusher 0.0.3 → 0.0.4

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/README.md CHANGED
@@ -81,6 +81,39 @@ Creating a channel returns an object that makes it easy to send messages to Geck
81
81
  channel.push(10, "Today", 20, "Yesterday") // push number and secondary stat with descriptions
82
82
  channel.push(10, 20, absolute: true, type: reverse) // push with options
83
83
 
84
+ ### Maps
85
+
86
+ For basic, uncoloured, uniformly sized points, the API is dirt simple:
87
+
88
+ channel.push("192.168.0.1") // Push IP address
89
+ channel.push([-51.424, 0.02323]) // Push Lat/Long
90
+ channel.push({city_name: "London", country_code: "GB"}) // Push address
91
+ channel.push("host.dsci.it") // Push hostname
92
+ channel.push("192.168.0.1", [-51.424, 0.02323]...) // Push any combination of above as multiple args
93
+
94
+ If you want to embellish points with additional styling information, you have to do a bit more work, with each element
95
+ an array, the first element being as above, the second element being the point options. You can mix/match the two ways - the API
96
+ will figure it out:
97
+
98
+ channel.push(["192.168.0.1", {colour: "FF0000", size: 3}]) // Push IP address
99
+ channel.push([[-51.424, 0.02323], {size: 8}]) // Push Lat/Long
100
+ channel.push([{city_name: "London", country_code: "GB"}, {...}]) // Push address
101
+ channel.push(["host.dsci.it", {colour: "00FF00"}]) // Push hostname
102
+ channel.push(["192.168.0.1", {colour: "FF0000", size: 3}],
103
+ [[-51.424, 0.02323], {size: 8}]) // Push any combination of above as multiple args
104
+
105
+ channel.push("192.168.0.1",
106
+ [{city_name: "London", country_code: "GB"}, {...}],
107
+ ["host.dsci.it", {colour: "00FF00"}],
108
+ [-51.424, 0.02323],
109
+ ...)
110
+
111
+ ### Gecko Meter
112
+
113
+ channel.push(10, 0, 20) // Push basic value, min, max
114
+ channel.push(10, 0, "Min", 20, "Max") // Push values with descriptions
115
+ channel.push(10, 0, "Min", 20, "Max", type: "reverse") // Push values, descriptions and options
116
+
84
117
  ## Contributing
85
118
 
86
119
  1. Fork it
@@ -22,6 +22,10 @@ module Gecko
22
22
  end
23
23
  end
24
24
 
25
+ def extract_options(args)
26
+ args.last.is_a?(Hash) ? args.pop : {}
27
+ end
28
+
25
29
  end
26
30
  end
27
31
  end
@@ -0,0 +1,47 @@
1
+ module Gecko
2
+ module Pusher
3
+ module Channel
4
+ class GeckoMeter < Base
5
+
6
+ def push(*args)
7
+ options = extract_options(args)
8
+ data = extract_values(args)
9
+ data[:type] = options[:type] unless options[:type].nil?
10
+ _push(data)
11
+ end
12
+
13
+ protected
14
+
15
+ def extract_values(args)
16
+ if just_values?(args)
17
+ {
18
+ item: args[0],
19
+ min: { value: args[1] },
20
+ max: { value: args[2]}
21
+ }
22
+ elsif values_and_descriptions?(args)
23
+ {
24
+ item: args[0],
25
+ min: { value: args[1], text: args[2] },
26
+ max: { value: args[3], text: args[4] }
27
+ }
28
+ else
29
+ raise ArgumentError
30
+ end
31
+ end
32
+
33
+ def just_values?(values)
34
+ values.length == 3 &&
35
+ values.all? {|a| a.is_a?(Integer)}
36
+ end
37
+
38
+ def values_and_descriptions?(values)
39
+ values.length == 5 &&
40
+ values[0].is_a?(Integer) &&
41
+ values[1].is_a?(Integer) && values[2].is_a?(String) &&
42
+ values[3].is_a?(Integer) && values[4].is_a?(String)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,60 @@
1
+ module Gecko
2
+ module Pusher
3
+ module Channel
4
+ class Map < Base
5
+
6
+ def push(*args)
7
+ data = args.map {|arg|
8
+ point_data, options = if arg.is_a?(Array) &&
9
+ arg.length == 2 &&
10
+ arg.last.is_a?(Hash)
11
+ [arg.first, check_options(arg.last)]
12
+ else
13
+ [arg, {}]
14
+ end
15
+
16
+ if ip_address?(point_data)
17
+ {ip: point_data}.merge(options)
18
+ elsif lat_long?(point_data)
19
+ {latitude: point_data[0].to_s, longitude: point_data[1].to_s}.merge(options)
20
+ elsif address?(point_data)
21
+ {city: point_data}.merge(options)
22
+ elsif hostname?(point_data)
23
+ {host: point_data}.merge(options)
24
+ end
25
+ }
26
+
27
+ _push({points: { point: data}})
28
+ end
29
+
30
+ protected
31
+
32
+ def check_options(options)
33
+ raise ArgumentError unless options.keys.all? {|k|
34
+ [:color, :size, :cssClass].include?(k)
35
+ }
36
+ options
37
+ end
38
+
39
+ def ip_address?(point_data)
40
+ point_data.is_a?(String) &&
41
+ point_data =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/
42
+ end
43
+
44
+ def lat_long?(point_data)
45
+ point_data.length == 2 &&
46
+ point_data.all? { |p| p.is_a? Float }
47
+ end
48
+
49
+ def address?(point_data)
50
+ point_data.is_a?(Hash) &&
51
+ point_data.keys.all? {|k| [:city_name, :region_code, :country_code].include?(k)}
52
+ end
53
+
54
+ def hostname?(point_data)
55
+ point_data.is_a?(String)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -33,10 +33,6 @@ module Gecko
33
33
  args[0].is_a?(Integer) && args[1].is_a?(String) &&
34
34
  args[2].is_a?(Integer) && args[3].is_a?(String)
35
35
  end
36
-
37
- def extract_options(args)
38
- args.last.is_a?(Hash) ? args.pop : {}
39
- end
40
36
  end
41
37
  end
42
38
  end
@@ -14,7 +14,7 @@ module Gecko
14
14
  _push(data)
15
15
  end
16
16
 
17
- private
17
+ protected
18
18
 
19
19
  def is_basic_rag?(*args)
20
20
  args.length == 3 && args.all? {|arg| arg.is_a? Integer}
@@ -0,0 +1,8 @@
1
+ module Gecko
2
+ module Pusher
3
+ module Channel
4
+ class RagCol < Rag
5
+ end
6
+ end
7
+ end
8
+ end
@@ -1 +1 @@
1
- %w{base text rag line_chart number}.each {|f| require "gecko-pusher/channel/#{f}"}
1
+ %w{base text rag rag_col line_chart number map gecko_meter}.each {|f| require "gecko-pusher/channel/#{f}"}
@@ -1,5 +1,5 @@
1
1
  module Gecko
2
2
  module Pusher
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
data/lib/gecko-pusher.rb CHANGED
@@ -39,3 +39,7 @@ module Gecko
39
39
  end
40
40
  end
41
41
  end
42
+
43
+ if ENV['GECKO_PUSHER_APIKEY']
44
+ Gecko::Pusher::api_key = ENV['GECKO_PUSHER_APIKEY']
45
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gecko::Pusher::Channel::GeckoMeter do
4
+
5
+ before(:each) do
6
+ WebMock.reset!
7
+ Gecko::Pusher.api_key = API_KEY
8
+ @channel = Gecko::Pusher.channel(:gecko_meter, WIDGET_KEY)
9
+ end
10
+
11
+ it "should initiate a gecko meter channel" do
12
+ @channel.should be_a(Gecko::Pusher::Channel::GeckoMeter)
13
+ end
14
+
15
+ it "should push basic value, min and max" do
16
+ data = {
17
+ item: 10,
18
+ min: { value: 0 },
19
+ max: { value: 20 }
20
+ }
21
+ stub = stub_gecko_post(WIDGET_KEY, data)
22
+ @channel.push(10, 0, 20)
23
+ stub.should have_been_requested
24
+ end
25
+
26
+ it "should push values with descriptions" do
27
+ data = {
28
+ item: 10,
29
+ min: { value: 0, text: "Min" },
30
+ max: { value: 20, text: "Max" }
31
+ }
32
+ stub = stub_gecko_post(WIDGET_KEY, data)
33
+ @channel.push(10, 0, "Min", 20, "Max")
34
+ stub.should have_been_requested
35
+ end
36
+
37
+ it "should allow type option to be passed" do
38
+ data = {
39
+ item: 10,
40
+ min: { value: 0 },
41
+ max: { value: 20 },
42
+ type: "reverse"
43
+ }
44
+ stub = stub_gecko_post(WIDGET_KEY, data)
45
+ @channel.push(10, 0, 20, type: "reverse")
46
+ stub.should have_been_requested
47
+ end
48
+
49
+ it "should raise an ArgumentError for invalid arguments" do
50
+ expect {
51
+ @channel.push("an invalid argument")
52
+ }.should raise_error(ArgumentError)
53
+ end
54
+
55
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gecko::Pusher::Channel::Map do
4
+
5
+ before(:each) do
6
+ WebMock.reset!
7
+ Gecko::Pusher.api_key = API_KEY
8
+ @channel = Gecko::Pusher.channel(:map, WIDGET_KEY)
9
+ end
10
+
11
+ it "should initiate a map channel" do
12
+ @channel.should be_a(Gecko::Pusher::Channel::Map)
13
+ end
14
+
15
+ context "pushing simple values" do
16
+
17
+ it "should push an IP address" do
18
+ data = {
19
+ points: {
20
+ point: [
21
+ {ip: "1.2.3.4"}
22
+ ]
23
+ }
24
+ }
25
+ stub = stub_gecko_post(WIDGET_KEY, data)
26
+ @channel.push("1.2.3.4")
27
+ stub.should have_been_requested
28
+ end
29
+
30
+ it "should push a lat/long" do
31
+ data = {
32
+ points: {
33
+ point: [
34
+ {latitude: "51.0001",longitude: "-51.0001"}
35
+ ]
36
+ }
37
+ }
38
+ stub = stub_gecko_post(WIDGET_KEY, data)
39
+ @channel.push([51.0001, -51.0001])
40
+ stub.should have_been_requested
41
+ end
42
+
43
+ it "should push an address" do
44
+ data = {
45
+ points: {
46
+ point: [
47
+ {city: {
48
+ city_name: "London",
49
+ country_code: "GB"
50
+ }}
51
+ ]
52
+ }
53
+ }
54
+ stub = stub_gecko_post(WIDGET_KEY, data)
55
+ @channel.push({city_name: "London", country_code: "GB"})
56
+ stub.should have_been_requested
57
+ end
58
+
59
+ it "should push a hostname" do
60
+ data = {
61
+ points: {
62
+ point: [
63
+ {host: "gecko.dsci.it"}
64
+ ]
65
+ }
66
+ }
67
+ stub = stub_gecko_post(WIDGET_KEY, data)
68
+ @channel.push("gecko.dsci.it")
69
+ stub.should have_been_requested
70
+ end
71
+
72
+ it "should push multiple values" do
73
+ data = {
74
+ points: {
75
+ point: [
76
+ {host: "gecko.dsci.it"},
77
+ {ip: "1.2.3.4"},
78
+ {latitude: "51.0001",longitude: "-51.0001"}
79
+ ]
80
+ }
81
+ }
82
+ stub = stub_gecko_post(WIDGET_KEY, data)
83
+ @channel.push(
84
+ "gecko.dsci.it",
85
+ "1.2.3.4",
86
+ [51.0001, -51.0001]
87
+ )
88
+ stub.should have_been_requested
89
+
90
+ end
91
+ end
92
+
93
+ context "pushing values with additional metadata" do
94
+
95
+ it "should raise ArgumentError if invalid point option passed" do
96
+ expect {
97
+ @channel.push(["gecko.dsci.it", {not_an_option: 8}])
98
+ }.should raise_error(ArgumentError)
99
+ end
100
+
101
+ it "should push multiple values" do
102
+ data = {
103
+ points: {
104
+ point: [
105
+ {host: "gecko.dsci.it", size: 8},
106
+ {ip: "1.2.3.4", color: "ff0000"},
107
+ {latitude: "51.0001",longitude: "-51.0001", cssClass: "classname"}
108
+ ]
109
+ }
110
+ }
111
+ stub = stub_gecko_post(WIDGET_KEY, data)
112
+ @channel.push(
113
+ ["gecko.dsci.it", {size: 8}],
114
+ ["1.2.3.4", {color: "ff0000"}],
115
+ [[51.0001, -51.0001], {cssClass: "classname"}]
116
+ )
117
+ stub.should have_been_requested
118
+
119
+ end
120
+
121
+ end
122
+
123
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Gecko::Pusher::Channel::Rag do
3
+ describe Gecko::Pusher::Channel::Number do
4
4
 
5
5
  before(:each) do
6
6
  WebMock.reset!
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gecko::Pusher::Channel::RagCol do
4
+
5
+ before(:each) do
6
+ WebMock.reset!
7
+ Gecko::Pusher.api_key = API_KEY
8
+ @channel = Gecko::Pusher.channel(:rag_col, WIDGET_KEY)
9
+ end
10
+
11
+ it "should initiate a RAG Column channel" do
12
+ @channel.should be_a(Gecko::Pusher::Channel::RagCol)
13
+ end
14
+
15
+ it "should push RAG values" do
16
+ data = {
17
+ item: [
18
+ { value: 100 },
19
+ { value: 200 },
20
+ { value: 300 }
21
+ ]
22
+ }
23
+ stub = stub_gecko_post(WIDGET_KEY, data)
24
+ @channel.push(100, 200, 300)
25
+ stub.should have_been_requested
26
+ end
27
+
28
+ it "should push RAG values and descriptions" do
29
+ data = {
30
+ item: [
31
+ { value: 100, text: "red description" },
32
+ { value: 200, text: "amber description" },
33
+ { value: 300, text: "green description" }
34
+ ]
35
+ }
36
+ stub = stub_gecko_post(WIDGET_KEY, data)
37
+ @channel.push(100, "red description",
38
+ 200, "amber description",
39
+ 300, "green description")
40
+ stub.should have_been_requested
41
+ end
42
+ end
43
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gecko-pusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-25 00:00:00.000000000 Z
12
+ date: 2012-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -158,13 +158,19 @@ files:
158
158
  - lib/gecko-pusher.rb
159
159
  - lib/gecko-pusher/channel.rb
160
160
  - lib/gecko-pusher/channel/base.rb
161
+ - lib/gecko-pusher/channel/gecko_meter.rb
161
162
  - lib/gecko-pusher/channel/line_chart.rb
163
+ - lib/gecko-pusher/channel/map.rb
162
164
  - lib/gecko-pusher/channel/number.rb
163
165
  - lib/gecko-pusher/channel/rag.rb
166
+ - lib/gecko-pusher/channel/rag_col.rb
164
167
  - lib/gecko-pusher/channel/text.rb
165
168
  - lib/gecko-pusher/version.rb
169
+ - spec/lib/gecko-pusher/channel/gecko_meter_spec.rb
166
170
  - spec/lib/gecko-pusher/channel/line_chart_spec.rb
171
+ - spec/lib/gecko-pusher/channel/map_spec.rb
167
172
  - spec/lib/gecko-pusher/channel/number_spec.rb
173
+ - spec/lib/gecko-pusher/channel/rag_col_spec.rb
168
174
  - spec/lib/gecko-pusher/channel/rag_spec.rb
169
175
  - spec/lib/gecko-pusher/channel/text_spec.rb
170
176
  - spec/lib/gecko-pusher/channel_spec.rb
@@ -185,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
191
  version: '0'
186
192
  segments:
187
193
  - 0
188
- hash: -392887078648416788
194
+ hash: 211583460469092842
189
195
  required_rubygems_version: !ruby/object:Gem::Requirement
190
196
  none: false
191
197
  requirements:
@@ -194,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
200
  version: '0'
195
201
  segments:
196
202
  - 0
197
- hash: -392887078648416788
203
+ hash: 211583460469092842
198
204
  requirements: []
199
205
  rubyforge_project:
200
206
  rubygems_version: 1.8.23
@@ -202,8 +208,11 @@ signing_key:
202
208
  specification_version: 3
203
209
  summary: Provides a simple library to send updates to Geckoboard via its push API.
204
210
  test_files:
211
+ - spec/lib/gecko-pusher/channel/gecko_meter_spec.rb
205
212
  - spec/lib/gecko-pusher/channel/line_chart_spec.rb
213
+ - spec/lib/gecko-pusher/channel/map_spec.rb
206
214
  - spec/lib/gecko-pusher/channel/number_spec.rb
215
+ - spec/lib/gecko-pusher/channel/rag_col_spec.rb
207
216
  - spec/lib/gecko-pusher/channel/rag_spec.rb
208
217
  - spec/lib/gecko-pusher/channel/text_spec.rb
209
218
  - spec/lib/gecko-pusher/channel_spec.rb