Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rvm:
- "1.9.3"
- jruby-19mode
- rbx-19mode
- jruby-18mode
- "1.8.7"
8 changes: 8 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 1.0.0.beta.1

- All slot interactions now go through `Ducksboard::Slot`

Breaking Changes:

- Breaks anything depending on slot type specific classes

# 0.1.5

- #6 Fixed push requests
97 changes: 32 additions & 65 deletions README.mdown
Original file line number Diff line number Diff line change
@@ -1,84 +1,51 @@
## Ducksboard API Ruby wrapper

[![Code Climate](https://codeclimate.com/github/jhsu/ducksboard.png)](https://codeclimate.com/github/jhsu/ducksboard)
[![Build Status](https://travis-ci.org/jhsu/ducksboard.png?branch=simple-slot-push)](https://travis-ci.org/jhsu/ducksboard)

### Configuration

API Key can be set in the environment
API Key can be set in the environment (such as `~/.bashrc`).

export DUCKSBOARD_API_KEY='YOURKEY'

or in an initializer
or in an initializer (such as `config/initializers/ducksboard.rb`)

Ducksboard.api_key = 'YOURKEY'

### Box

widget = Ducksboard::Box.new(1234) # Widget numeric id
widget.value = 10
widget.save

### Counter

widget = Ducksboard::Counter.new(1234)
widget.value = 10
widget.save

### Image

widget = Ducksboard::Image.new(1235)
widget.source = "https://dashboard.ducksboard.com/static/accounts/img/logo_small.png"
# or
widget.source = "~/Pictures/logo.png"
widget.caption = "Ducksboard logo!"
widget.timestamp = 1310649204
widget.save

### Gauge

widget = Ducksboard::Gauge.new(1235)
widget.value = 0.93
widget.save

### Graph

# remember that the graph widgets need atleast 2 points before it displays anything
widget = Ducksboard::Graph.new(1236)
widget.timestamp = Time.now.to_i
widget.value = 198
widget.save
### Sending Data (Push API)

### Pin
Data can be sent to slots in formats specified in the [Ducksboard API
documentation](http://dev.ducksboard.com/apidoc/slot-kinds).

widget = Ducksboard::Pin.new(1234)
widget.value = 10
widget.save
```ruby
# Update the value a slot (ie. counter)
slot = Ducksboard::Slot.new(123)
slot.update(:value => 20)

### Timeline
# Update a leaderboard
slot = Ducksboard::Slot.new("leaderboard")
slot.update(:value => {
:boards => [
{:name => "person 1", values => [123, 24.5]},
{:name => "person 2", values => [224, 21.0]}
]
})
```

widget = Ducksboard::Timeline.new(1237)
widget.title = "A Title"
widget.image = "http://url.to.io/some_image.gif"
# or
widget.image = :edited
# any of the following as a string or symbol: orange, red, green, created, edited or deleted
widget.content = "text content"
widget.link = "http://google.com"
### Pulling Data (Pull API)

### Leaderboard
Fetching data from a slot on Ducksboard. Several convinience methods are
provided to fetch data through the [Ducksboard HTTP Pull
API](http://dev.ducksboard.com/apidoc/pull-api-http/#resource-endpoints). Each
pull returns a hash of data with a data at `response['data']`.

widget1 = Ducksboard::Leaderboard.new(56803)
widget1.linha = [{"name" => 'Titulo 1', "values" => [12,13,14]},
{"name" => 'Titulo 2', "values" => [12,13,142]},
]
widget1.save
```ruby
slot = Ducksboard::Slot.new(123)
slot.last(:count => 15)

### Pull API
slot.since(:seconds => 5 * 60)

# You can use the HTTP Pull API to retrieve historical data from any widget.
# It will be returned in a map as per the API (http://dev.ducksboard.com/apidoc/pull-api-http)
slot.timespan(:timespan => "weekly", :timezone => "UTC")
```

widget = Ducksboard::Gauge.new(1235)
data = widget.since(300)['data']
# or
data = widget.last_values(15)
# or
data = widget.timespan(:daily, "Europe/London")
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs << "test" << "lib"
t.test_files = FileList['test/*_test.rb']
t.test_files = FileList['test/**/*_test.rb']
end

task :default => :test
11 changes: 9 additions & 2 deletions ducksboard.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require File.join(File.dirname(__FILE__), 'lib/ducksboard/version')

Gem::Specification.new do |s|
s.name = 'ducksboard'
s.version = '0.1.5'
s.version = Ducksboard::VERSION
s.summary = "API wrapper for ducksboard.com dashboard"
s.description = "Ruby API wrapper for ducksboard realtime dashboard using HTTParty"
s.authors = ["Joseph Hsu"]
Expand All @@ -10,9 +12,14 @@ Gem::Specification.new do |s|
s.license = 'MIT'
s.required_ruby_version = '>= 1.8.7'

s.add_runtime_dependency 'httparty', '~> 0.8', '>= 0.8.1'
s.add_runtime_dependency 'addressable', '~> 2.3', '>= 2.3.3'
s.add_runtime_dependency 'httparty', '~> 0.10', '>= 0.10.2'
s.add_runtime_dependency 'json', '~> 1.7', '>= 1.7.7'
s.add_development_dependency 'rake', '~> 10.0'
s.add_development_dependency 'minitest', '~> 4.6.2'
s.add_development_dependency 'webmock', '~> 1.11', '>= 1.11.0'
s.add_development_dependency 'mocha', '~> 0.13', '>= 0.13.3'
s.add_development_dependency 'pry', '~> 0.9', '>= 0.9.2'

s.post_install_message = <<-DESC
Quack! (in real-time)"
Expand Down
15 changes: 6 additions & 9 deletions lib/ducksboard.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'httparty'
require "addressable/uri"

module Ducksboard
class << self ; attr_accessor :api_key end
Expand All @@ -7,12 +8,8 @@ def self.api_key
end
end

require 'ducksboard/widget'
require 'ducksboard/box'
require 'ducksboard/counter'
require 'ducksboard/gauge'
require 'ducksboard/graph'
require 'ducksboard/image'
require 'ducksboard/pin'
require 'ducksboard/timeline'
require 'ducksboard/leaderboard'
require 'ducksboard/version'
require 'ducksboard/request'
require 'ducksboard/push'
require 'ducksboard/pull'
require 'ducksboard/slot'
8 changes: 0 additions & 8 deletions lib/ducksboard/box.rb

This file was deleted.

4 changes: 0 additions & 4 deletions lib/ducksboard/counter.rb

This file was deleted.

4 changes: 0 additions & 4 deletions lib/ducksboard/gauge.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/ducksboard/graph.rb

This file was deleted.

42 changes: 0 additions & 42 deletions lib/ducksboard/image.rb

This file was deleted.

20 changes: 0 additions & 20 deletions lib/ducksboard/leaderboard.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/ducksboard/pin.rb

This file was deleted.

49 changes: 49 additions & 0 deletions lib/ducksboard/pull.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Ducksboard
module Pull
include ::HTTParty
include Request
PULL_URL = "https://pull.ducksboard.com/values"

# Get the last :count values.
#
# options - A hash of options:
# count - A integer of the last :count values to fetch.
#
# Returns a hash response.
def last(options={})
get("last", options)
end

# Get data since timestamp.
#
# options - A hash of options:
# seconds - A start time in secods.
#
# Returns a hash response.
def since(options={})
get("since", options)
end

# Get data summarized by timespan.
#
# options - A hash of options:
# timespan - A string timespan.
# timezone - A string timezone (default: UTC).
#
# Returns a hash response.
def timespan(options={})
get("timespan", options)
end

protected

# Internal: Get request for data.
#
# endpoint - string.
def get(endpoint, params={})
uri = Addressable::URI.new
uri.query_values = params
HTTParty.get("#{PULL_URL}/#{id}/#{endpoint}?#{uri.query}", :basic_auth => auth)
end
end
end
Loading