ducksboard 0.1.0

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 ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gem 'httparty'
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Joseph Hsu
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.mdown ADDED
@@ -0,0 +1,52 @@
1
+ ## Ducksboard API Ruby wrapper
2
+
3
+ ### Configuration
4
+
5
+ API Key can be set in the environment
6
+
7
+ export DUCKSBOARD_API_KEY='YOURKEY'
8
+
9
+ or in an initializer
10
+
11
+ Ducksboard.api_key = 'YOURKEY'
12
+
13
+ ### Counter
14
+
15
+ widget = Ducksbaord::Counter.new(1234) # Widget numeric id
16
+ widget.value = 10
17
+ widget.save
18
+
19
+ ### Image
20
+
21
+ widget = Ducksboard::Image.new(1235)
22
+ widget.source = "https://dashboard.ducksboard.com/static/accounts/img/logo_small.png"
23
+ # or
24
+ widget.source = "~/Pictures/logo.png"
25
+ widget.caption = "Ducksboard logo!"
26
+ widget.timestamp = 1310649204
27
+ widget.save
28
+
29
+ ### Gauge
30
+
31
+ widget = DUcksboard::GRaph.new(1235)
32
+ widget.value = 0.93
33
+ widget.save
34
+
35
+ ### Graph
36
+
37
+ # remember that the graph widgets need atleast 2 points before it displays anything
38
+ widget = Ducksboard::Graph.new(1236)
39
+ widget.timestamp = Time.now.to_i
40
+ widget.value = 198
41
+ widget.save
42
+
43
+ ### Timeline
44
+
45
+ widget = Ducksbaord::Timeline.new(1237)
46
+ widget.title = "A Title"
47
+ widget.image = "http://url.to.io/some_image.gif"
48
+ # or
49
+ widget.image = :edited
50
+ # any of the following as a string or symbol: orange, red, green, created, edited or deleted
51
+ widget.content = "text content"
52
+ widget.link = "http://google.com"
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ducksboard'
3
+ s.version = '0.1.0'
4
+ s.summary = "API wrapper for ducksboard.com dashboard"
5
+ s.description = "Ruby API wrapper for ducksboard realtime dashboard using HTTParty"
6
+ s.authors = ["Joseph Hsu"]
7
+ s.email = 'jhsu.x1@gmail.com'
8
+ s.files = `git ls-files`.split("\n")
9
+ s.homepage = 'http://github.com/jhsu/ducksboard'
10
+ s.license = 'MIT'
11
+ s.required_ruby_version = '>= 1.8.7'
12
+
13
+ s.add_runtime_dependency 'httparty', '~> 0.8', '>= 0.8.1'
14
+
15
+ s.post_install_message = <<-DESC
16
+ Quack! (in real-time)"
17
+
18
+ ===
19
+
20
+ Don't forget to set your ENV variable for DUCKSBOARD_API_KEY
21
+
22
+ export DUCKSBOARD_API_KEY='YOURKEY'
23
+
24
+ or set it in your script
25
+
26
+ Ducksboard.api_key = 'YOURKEY'
27
+ DESC
28
+
29
+ end
data/lib/ducksboard.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'httparty'
2
+
3
+ module Ducksboard
4
+ class << self ; attr_accessor :api_key end
5
+ @api_key = ENV['DUCKSBOARD_API_KEY']
6
+ end
7
+
8
+ require 'ducksboard/widget'
9
+ require 'ducksboard/counter'
10
+ require 'ducksboard/gauge'
11
+ require 'ducksboard/graph'
12
+ require 'ducksboard/image'
13
+ require 'ducksboard/timeline'
@@ -0,0 +1,4 @@
1
+ module Ducksboard
2
+ class Counter < Widget
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Ducksboard
2
+ class Gauge < Widget
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module Ducksboard
2
+ class Graph < Widget
3
+ def valid?
4
+ @data[:timestamp] && @data[:value]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ require 'base64'
2
+ require 'json'
3
+ module Ducksboard
4
+ class Image < Widget
5
+
6
+ def initialize(*args)
7
+ super
8
+ @data[:value] ||={}
9
+ end
10
+
11
+ def source
12
+ @data[:value][:source]
13
+ end
14
+
15
+ def source=(image_location)
16
+ source_value = if image_location =~ /^http/
17
+ image_location
18
+ else
19
+ 'data:image/png;base64,' +
20
+ Base64.encode64(File.read(File.expand_path(image_location)))
21
+ end
22
+ @data[:value][:source] = source_value
23
+ end
24
+
25
+ def caption
26
+ @data[:value][:caption]
27
+ end
28
+
29
+ def caption=(text=nil)
30
+ @data[:value][:caption] = caption.to_s
31
+ end
32
+
33
+ def timestamp
34
+ @data[:timestamp]
35
+ end
36
+
37
+ def timestamp=(time)
38
+ @data[:timestamp] = time
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+ module Ducksboard
2
+ class Timeline < Widget
3
+
4
+ ICONS = {
5
+ :orange => "https://app.ducksboard.com/static/img/timeline/orange.gif",
6
+ :red => "https://app.ducksboard.com/static/img/timeline/red.gif",
7
+ :green => "https://app.ducksboard.com/static/img/timeline/green.gif",
8
+ :created => "https://app.ducksboard.com/static/img/timeline/created.png",
9
+ :edited => "https://app.ducksboard.com/static/img/timeline/edited.png",
10
+ :deleted => "https://app.ducksboard.com/static/img/timeline/deleted.png"
11
+ }
12
+
13
+ def title; @data[:title] end
14
+ def image; @data[:image] end
15
+ def content; @data[:image] end
16
+ def link; @data[:image] end
17
+
18
+ def title=(text)
19
+ @data[:title] = text
20
+ end
21
+
22
+ def image=(url)
23
+ @data[:image] = if url =~ /^http/
24
+ url
25
+ else
26
+ ICONS[url.to_sym]
27
+ end
28
+ end
29
+
30
+ def content=(text)
31
+ @data[:content] = text
32
+ end
33
+
34
+ def link=(url)
35
+ @data[:link] = url
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,48 @@
1
+ require 'json'
2
+ module Ducksboard
3
+ class Widget
4
+ include ::HTTParty
5
+ base_uri "https://push.ducksboard.com/values"
6
+ basic_auth Ducksboard.api_key, 'ducksboard-gem'
7
+
8
+ attr_accessor :id, :data, :type
9
+
10
+ def initialize(id, data={})
11
+ @id = id
12
+ @data = data
13
+ end
14
+
15
+ def value
16
+ @data[:value]
17
+ end
18
+
19
+ def value=(val)
20
+ @data[:value] = val
21
+ end
22
+
23
+ def timestamp
24
+ @data[:timestamp]
25
+ end
26
+
27
+ def timestamp=(time)
28
+ @data[:timestamp] = time
29
+ end
30
+
31
+ def update(data=nil)
32
+ @data = data if data
33
+ self.class.post('/' + id.to_s, :body => @data.to_json)
34
+ end
35
+
36
+ def save
37
+ if valid?
38
+ update.code.to_i == 200
39
+ else
40
+ raise "Invalid Data: #{@data.inspect}"
41
+ end
42
+ end
43
+
44
+ def valid?
45
+ true
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ducksboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joseph Hsu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-01 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70319378162520 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.8'
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 0.8.1
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: *70319378162520
28
+ description: Ruby API wrapper for ducksboard realtime dashboard using HTTParty
29
+ email: jhsu.x1@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.mdown
38
+ - ducksboard.gemspec
39
+ - lib/ducksboard.rb
40
+ - lib/ducksboard/counter.rb
41
+ - lib/ducksboard/gauge.rb
42
+ - lib/ducksboard/graph.rb
43
+ - lib/ducksboard/image.rb
44
+ - lib/ducksboard/timeline.rb
45
+ - lib/ducksboard/widget.rb
46
+ homepage: http://github.com/jhsu/ducksboard
47
+ licenses:
48
+ - MIT
49
+ post_install_message: ! " Quack! (in real-time)\"\n\n ===\n\n Don't forget to set
50
+ your ENV variable for DUCKSBOARD_API_KEY\n\n export DUCKSBOARD_API_KEY='YOURKEY'\n\n
51
+ \ or set it in your script\n\n Ducksboard.api_key = 'YOURKEY'\n"
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 1.8.7
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.10
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: API wrapper for ducksboard.com dashboard
73
+ test_files: []