gecko-pusher 0.0.2 → 0.0.3

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
@@ -70,7 +70,16 @@ Creating a channel returns an object that makes it easy to send messages to Geck
70
70
 
71
71
  ### Line charts
72
72
 
73
- channel.push(1,2,3,4,5)
73
+ channel.push([1,2,3,4,5]) // Push raw values, no settings
74
+ channel.push([1,2,3,4,5], colour: "#FF0000") // Push values with colour set
75
+ channel.push([1,2,3,4,5], colour: "#FF0000", axisx: ['1','2']) // Push values with colour and X-axis labels set
76
+
77
+ ### Numbers
78
+
79
+ channel.push(10) // push number
80
+ channel.push(10, 20) // push number and secondary stat
81
+ channel.push(10, "Today", 20, "Yesterday") // push number and secondary stat with descriptions
82
+ channel.push(10, 20, absolute: true, type: reverse) // push with options
74
83
 
75
84
  ## Contributing
76
85
 
data/gecko-pusher.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency "webmock", "~> 1.8.7"
24
24
  gem.add_development_dependency "guard-rspec", "~> 1.0"
25
25
  gem.add_development_dependency "rake", "~> 0.9.2.2"
26
+ gem.add_development_dependency "pry"
26
27
  end
@@ -0,0 +1,43 @@
1
+ module Gecko
2
+ module Pusher
3
+ module Channel
4
+ class Number < Base
5
+
6
+ def push(*args)
7
+ options = extract_options(args)
8
+ data = {item: extract_values(args)}
9
+ data[:type] = options[:type] unless options[:type].nil?
10
+ data[:absolute] = options[:absolute] unless options[:absolute].nil?
11
+ _push(data)
12
+ end
13
+
14
+ protected
15
+
16
+ def extract_values(args)
17
+ values = if just_values?(args)
18
+ args.map {|arg| {value: arg}}
19
+ elsif values_and_descriptions?(args)
20
+ args.each_slice(2).map {|arg|
21
+ {value: arg.first, text: arg.last}
22
+ }
23
+ end
24
+ end
25
+
26
+ def just_values?(args)
27
+ (args.length == 1 || args.length == 2) &&
28
+ args.all? {|arg| arg.is_a?(Integer)}
29
+ end
30
+
31
+ def values_and_descriptions?(args)
32
+ (args.length == 2 || args.length == 4) &&
33
+ args[0].is_a?(Integer) && args[1].is_a?(String) &&
34
+ args[2].is_a?(Integer) && args[3].is_a?(String)
35
+ end
36
+
37
+ def extract_options(args)
38
+ args.last.is_a?(Hash) ? args.pop : {}
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1 +1 @@
1
- %w{base text rag line_chart}.each {|f| require "gecko-pusher/channel/#{f}"}
1
+ %w{base text rag line_chart number}.each {|f| require "gecko-pusher/channel/#{f}"}
@@ -1,5 +1,5 @@
1
1
  module Gecko
2
2
  module Pusher
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gecko::Pusher::Channel::Rag do
4
+
5
+ before(:each) do
6
+ WebMock.reset!
7
+ Gecko::Pusher.api_key = API_KEY
8
+ @channel = Gecko::Pusher.channel(:number, WIDGET_KEY)
9
+ end
10
+
11
+ it "should initiate a number channel" do
12
+ @channel.should be_a(Gecko::Pusher::Channel::Number)
13
+ end
14
+
15
+ it "should push a single value" do
16
+ data = {
17
+ item: [
18
+ { value: 123 }
19
+ ]
20
+ }
21
+ stub = stub_gecko_post(WIDGET_KEY, data)
22
+ @channel.push(123)
23
+ stub.should have_been_requested
24
+ end
25
+ it "should push two basic values" do
26
+ data = {
27
+ item: [
28
+ { value: 123 },
29
+ { value: 456 }
30
+ ]
31
+ }
32
+ stub = stub_gecko_post(WIDGET_KEY, data)
33
+ @channel.push(123, 456)
34
+ stub.should have_been_requested
35
+ end
36
+ it "should push two values with descriptions" do
37
+ data = {
38
+ item: [
39
+ { value: 123, text: "This week" },
40
+ { value: 456, text: "Last week" }
41
+ ]
42
+ }
43
+ stub = stub_gecko_post(WIDGET_KEY, data)
44
+ @channel.push(123, "This week", 456, "Last week")
45
+ stub.should have_been_requested
46
+ end
47
+ it "should push options" do
48
+ data = {
49
+ item: [
50
+ { value: 123 },
51
+ { value: 456 }
52
+ ],
53
+ type: "reverse",
54
+ absolute: true
55
+ }
56
+ stub = stub_gecko_post(WIDGET_KEY, data)
57
+ @channel.push(123, 456, type: "reverse", absolute: true)
58
+ stub.should have_been_requested
59
+
60
+ end
61
+ end
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.2
4
+ version: 0.0.3
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-20 00:00:00.000000000 Z
12
+ date: 2012-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -123,6 +123,22 @@ dependencies:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
125
  version: 0.9.2.2
126
+ - !ruby/object:Gem::Dependency
127
+ name: pry
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
126
142
  description: Provides a simple library to send updates to Geckoboard via its push
127
143
  API.
128
144
  email:
@@ -143,10 +159,12 @@ files:
143
159
  - lib/gecko-pusher/channel.rb
144
160
  - lib/gecko-pusher/channel/base.rb
145
161
  - lib/gecko-pusher/channel/line_chart.rb
162
+ - lib/gecko-pusher/channel/number.rb
146
163
  - lib/gecko-pusher/channel/rag.rb
147
164
  - lib/gecko-pusher/channel/text.rb
148
165
  - lib/gecko-pusher/version.rb
149
166
  - spec/lib/gecko-pusher/channel/line_chart_spec.rb
167
+ - spec/lib/gecko-pusher/channel/number_spec.rb
150
168
  - spec/lib/gecko-pusher/channel/rag_spec.rb
151
169
  - spec/lib/gecko-pusher/channel/text_spec.rb
152
170
  - spec/lib/gecko-pusher/channel_spec.rb
@@ -167,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
185
  version: '0'
168
186
  segments:
169
187
  - 0
170
- hash: 205409277355117486
188
+ hash: -392887078648416788
171
189
  required_rubygems_version: !ruby/object:Gem::Requirement
172
190
  none: false
173
191
  requirements:
@@ -176,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
194
  version: '0'
177
195
  segments:
178
196
  - 0
179
- hash: 205409277355117486
197
+ hash: -392887078648416788
180
198
  requirements: []
181
199
  rubyforge_project:
182
200
  rubygems_version: 1.8.23
@@ -185,6 +203,7 @@ specification_version: 3
185
203
  summary: Provides a simple library to send updates to Geckoboard via its push API.
186
204
  test_files:
187
205
  - spec/lib/gecko-pusher/channel/line_chart_spec.rb
206
+ - spec/lib/gecko-pusher/channel/number_spec.rb
188
207
  - spec/lib/gecko-pusher/channel/rag_spec.rb
189
208
  - spec/lib/gecko-pusher/channel/text_spec.rb
190
209
  - spec/lib/gecko-pusher/channel_spec.rb