databox 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.pryrc +7 -0
- data/.ruby-version +1 -1
- data/.travis.yml +4 -7
- data/README.md +40 -149
- data/databox.gemspec +7 -17
- data/example.rb +17 -0
- data/lib/databox.rb +8 -22
- data/lib/databox/client.rb +42 -61
- data/lib/databox/configuration.rb +3 -8
- data/lib/databox/version.rb +1 -1
- data/spec/databox/client_spec.rb +42 -85
- data/spec/databox_spec.rb +9 -0
- data/spec/spec_helper.rb +3 -32
- metadata +26 -160
- data/lib/databox/integration.rb +0 -127
- data/spec/databox/bar_chart_spec.rb +0 -23
- data/spec/databox/big_number_spec.rb +0 -29
- data/spec/databox/compare_spec.rb +0 -22
- data/spec/databox/funnel_spec.rb +0 -30
- data/spec/databox/integration_spec.rb +0 -11
- data/spec/databox/interval_spec.rb +0 -23
- data/spec/databox/line_chart_spec.rb +0 -23
- data/spec/databox/messages_spec.rb +0 -52
- data/spec/databox/pie_spec.rb +0 -25
- data/spec/databox/pipeline_spec.rb +0 -24
- data/spec/databox/progress_spec.rb +0 -20
- data/spec/requests/bar_chart_simple.txt +0 -14
- data/spec/requests/big_number_simple.txt +0 -14
- data/spec/requests/compare_simple.txt +0 -14
- data/spec/requests/funnel_simple.txt +0 -14
- data/spec/requests/interval_simple.txt +0 -14
- data/spec/requests/invalid_push.txt +0 -19
- data/spec/requests/line_chart_simple.txt +0 -14
- data/spec/requests/logs.txt +0 -14
- data/spec/requests/multiple_message.txt +0 -14
- data/spec/requests/pie_simple.txt +0 -14
- data/spec/requests/pipeline_simple.txt +0 -14
- data/spec/requests/progress_simple.txt +0 -14
- data/spec/requests/simple_message.txt +0 -14
- data/spec/requests/simple_push.txt +0 -14
- data/test_rvms.sh +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6e85fe8361df5f8a6e5e222fded72b065e72a06
|
4
|
+
data.tar.gz: 831e85f19a7a8162c5c1bc77d95601f45f8f9807
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a175fdc88f0efdd14afed93bb1d3db17edc7714633702a7731f5ce1f390f1db1edbc5f836f654167fc75ef12d8cf4263594fa725b38385ef9d32d58e9359713b
|
7
|
+
data.tar.gz: 32e2097b929ea498c8b5205eef0ad9c7ec62b58789fd11dc49fde733caa1a05389a026c70b5a3afcd5beb5ff7c5bfa776410845771b8bd709d0e89f4ee304966
|
data/.gitignore
CHANGED
data/.pryrc
ADDED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.2.2
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
# Databox
|
1
|
+
# Databox bindings for Ruby
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Build Status][travis-badge]][travis]
|
4
4
|
|
5
5
|
Ruby Gem for [Databox](http://databox.com/) - Mobile Executive Dashboard.
|
6
6
|
|
7
|
-
- By [Oto Brglez](https://github.com/otobrglez)
|
8
|
-
|
9
7
|
## Installation
|
10
8
|
|
11
9
|
Add this line to your application's Gemfile:
|
@@ -20,175 +18,68 @@ Or install it yourself as:
|
|
20
18
|
|
21
19
|
$ gem install databox
|
22
20
|
|
23
|
-
##
|
24
|
-
|
25
|
-
Before using Databox gem you have to initialize it with key and token. There are 3 ways how you can do initialization.
|
26
|
-
|
27
|
-
- Within simple initializer
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
Databox.configure do |c|
|
31
|
-
c.token = "YOUR_TOKEN"
|
32
|
-
c.key = "YOUR_KEY"
|
33
|
-
end
|
34
|
-
```
|
35
|
-
|
36
|
-
- By setting system ```ENV``` variables ```DATABOX_KEY``` and ```DATABOX_TOKEN```
|
37
|
-
|
38
|
-
- If your are using custom integration with different key please use ```id```.
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
chart = Databox::LineChart.new "my_line", id: "OTHER_KEY"
|
42
|
-
```
|
43
|
-
|
44
|
-
Databox gem support following widgets
|
45
|
-
|
46
|
-
| Widget | Implemented | Example | Databox Documentation
|
47
|
-
| --------------- | :-----------: | ------------------------------ | ----------------------
|
48
|
-
| Big Number | Yes | [Example](#big-number) | [Basic Widgets / Big Number](https://developers.databox.com/push/v1/widgets/main/#big-number)
|
49
|
-
| Compare | Yes | [Example](#compare) | [Basic Widgets / Compare](https://developers.databox.com/push/v1/widgets/main/#compare)
|
50
|
-
| Internal | Yes | [Example](#interval) | [Basic Widgets / Interval Values](https://developers.databox.com/push/v1/widgets/main/#interval-values)
|
51
|
-
| Line Chart | Yes | [Example](#line-chart) | [Basic Widgets / Line Chart](https://developers.databox.com/push/v1/widgets/main/#line-chart-and-bar-chart)
|
52
|
-
| Bar Chart | Yes | [Example](#bar-chart) | [Basic Widgets / Bar Chart](https://developers.databox.com/push/v1/widgets/main/#line-chart-and-bar-chart)
|
53
|
-
| Pipeline | Yes | [Example](#pipeline) | [Pipeline](https://developers.databox.com/push/v1/widgets/pipeline/)
|
54
|
-
| Funnel | Yes | [Example](#funnel) | [Funnel](https://developers.databox.com/push/v1/widgets/funnel/)
|
55
|
-
| Pie | Yes | [Example](#pie) | [Pie](https://developers.databox.com/push/v1/widgets/pie/)
|
56
|
-
| Progress | Yes | [Example](#progress) | [Progress](https://developers.databox.com/push/v1/widgets/progress/)
|
57
|
-
| Table | No | |
|
58
|
-
| Messages | Yes | [Example](#messages) | [Messages](https://developers.databox.com/push/v1/widgets/messages/)
|
21
|
+
## Initialisation
|
59
22
|
|
23
|
+
Before pushing data to Databox you have to initialize it with token.
|
60
24
|
|
61
|
-
### Big Number
|
62
25
|
```ruby
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
# You can set date on initialize
|
68
|
-
number_dated = Databox::BigNumber.new "just_number", date: "2014-02-03"
|
69
|
-
# Or when setting number
|
70
|
-
number_dated.set 10_000, "2014-02-03"
|
71
|
-
number_dated.save
|
72
|
-
|
26
|
+
Databox.configure do |c|
|
27
|
+
c.push_token = "YOUR_TOKEN"
|
28
|
+
end
|
73
29
|
```
|
74
30
|
|
75
|
-
|
76
|
-
```ruby
|
77
|
-
chart = Databox::LineChart.new "my_line"
|
78
|
-
chart.add 40, "2014-01-29"
|
79
|
-
chart.add 100, "2014-02-01"
|
80
|
-
chart.add 500, "2014-02-02"
|
81
|
-
chart.add 20, "2014-02-03"
|
82
|
-
chart.save
|
31
|
+
## Usage
|
83
32
|
|
84
|
-
|
33
|
+
Pushing data directly to Databox with help of `push` method:
|
85
34
|
|
86
|
-
### Bar Chart
|
87
35
|
```ruby
|
88
|
-
|
89
|
-
chart.add 40, "2014-01-29"
|
90
|
-
chart.add 100, "2014-02-01"
|
91
|
-
chart.add 500, "2014-02-02"
|
92
|
-
chart.add 20, "2014-02-03"
|
93
|
-
chart.save
|
94
|
-
```
|
36
|
+
client = Databox::Client.new
|
95
37
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
compare.add 20, "2014-02-03"
|
103
|
-
compare.save
|
104
|
-
```
|
38
|
+
client.push(key: 'sales.total', value: 3000)
|
39
|
+
client.push(key: 'temp.boston', value: 52.0)
|
40
|
+
client.push(key: 'temp.boston', value: 52.0, date: '2015-01-01 17:00:00')
|
41
|
+
client.push(key: 'temp.boston', value: 52.0, attributes: {
|
42
|
+
location: 'boston-south'
|
43
|
+
})
|
105
44
|
|
106
|
-
### Interval
|
107
|
-
```ruby
|
108
|
-
interval = Databox::BarChart.new "my_interval"
|
109
|
-
interval.add 40, "2014-01-29"
|
110
|
-
interval.add 100, "2014-02-01"
|
111
|
-
interval.add 500, "2014-02-02"
|
112
|
-
interval.add 20, "2014-02-03"
|
113
|
-
interval.save
|
114
45
|
```
|
115
46
|
|
116
|
-
|
117
|
-
```ruby
|
118
|
-
pipeline = Databox::Pipeline.new "pipe_visits"
|
119
|
-
pipeline.add "Negotiation", 1_121_603
|
120
|
-
pipeline.add "Proposal", 3_245_927
|
121
|
-
pipeline.add "Solution", 10_726_397
|
122
|
-
pipeline.save
|
123
|
-
```
|
124
|
-
|
125
|
-
### Funnel
|
126
|
-
```ruby
|
127
|
-
funnel = Databox::Funnel.new "funnel_simple"
|
128
|
-
funnel.add "Requests sent", 33_342
|
129
|
-
funnel.add "New Accounts", 25_350
|
130
|
-
funnel.add "Viewed results", 8_930
|
131
|
-
funnel.add "Return Visits", 3_580
|
132
|
-
funnel.save
|
133
|
-
```
|
47
|
+
Inserting multiple matrices with one `insert_all`:
|
134
48
|
|
135
|
-
### Pie
|
136
49
|
```ruby
|
137
|
-
|
138
|
-
pie.add "A", 3_014
|
139
|
-
pie.add "B", 29_496
|
140
|
-
pie.add "C", 9_121
|
141
|
-
pie.add "D", 20_390
|
142
|
-
pie.add "E", 7_423
|
143
|
-
pie.save
|
144
|
-
```
|
145
|
-
|
146
|
-
### Progress
|
147
|
-
```ruby
|
148
|
-
progress = Databox::Progress.new "my_progress"
|
149
|
-
progress.set "33% done", 100, 33
|
150
|
-
pie.save
|
151
|
-
```
|
50
|
+
client = Databox::Client.new
|
152
51
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
messages.add "Second message"
|
159
|
-
messages.save
|
52
|
+
client.insert_all [
|
53
|
+
{key: 'temp.boston', value: 52},
|
54
|
+
{key: 'temp.boston', value: 50, date: '2015-01-01 17:00:00'},
|
55
|
+
{key: 'temp.ny', value: 49}
|
56
|
+
]
|
160
57
|
```
|
161
58
|
|
162
|
-
|
163
|
-
|
164
|
-
You can also use Databox::Client directly to insert raw KPIs. This is done by invoking Databox::Client and pushing Hash or Array of Hashes to it.
|
59
|
+
Retrieving information from last push with `last_push`:
|
165
60
|
|
166
61
|
```ruby
|
167
|
-
client
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
62
|
+
client.last_push
|
63
|
+
|
64
|
+
# =>
|
65
|
+
#[{
|
66
|
+
# "push"=>"{\"data\":[{\"$sales.total\":2000}]}",
|
67
|
+
# "err"=>"[]",
|
68
|
+
# "no_err"=>0,
|
69
|
+
# "datetime"=>"2015-06-05T10:21:23.861Z",
|
70
|
+
# "keys"=>"[\"132|sales.total\"]"
|
71
|
+
#}]
|
176
72
|
```
|
177
73
|
|
178
|
-
## Versions
|
179
|
-
|
180
|
-
[Databox](https://github.com/otobrglez/databox) is tested on following Ruby versions
|
181
|
-
|
182
|
-
- MRI 1.9.3
|
183
|
-
- MRI 2.0.0
|
184
|
-
|
185
74
|
## Resources
|
186
75
|
|
187
76
|
- [Databox Web App](https://app.databox.com/)
|
188
77
|
- [Databox Developers Portal](https://developers.databox.com/)
|
189
78
|
|
79
|
+
## Author & License
|
80
|
+
|
81
|
+
- [Oto Brglez](https://github.com/otobrglez)
|
82
|
+
- Comes with `MIT` license and terms
|
190
83
|
|
191
|
-
[
|
192
|
-
[
|
193
|
-
[travis-badge]: https://secure.travis-ci.org/otobrglez/databox.png?branch=master
|
194
|
-
[travis]: http://travis-ci.org/otobrglez/databox
|
84
|
+
[travis-badge]: https://secure.travis-ci.org/databox/databox-ruby.png?branch=v2
|
85
|
+
[travis]: http://travis-ci.org/databox/databox-ruby
|
data/databox.gemspec
CHANGED
@@ -4,35 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'databox/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'databox'
|
8
8
|
spec.version = Databox::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Oto Brglez']
|
10
|
+
spec.email = ['otobrglez@gmail.com']
|
11
11
|
spec.description = %q{Ruby Gem for Databox - Mobile Executive Dashboard.}
|
12
12
|
spec.summary = %q{API wrapper for Databox}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/databox/databox-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
|
22
|
-
spec.add_dependency "httparty"
|
23
|
-
|
24
|
-
#TODO: Use multi_json spec.add_dependency "multi_json"
|
21
|
+
spec.add_dependency 'httparty'
|
25
22
|
|
26
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
27
24
|
spec.add_development_dependency "rake"
|
28
25
|
spec.add_development_dependency "rspec"
|
29
26
|
spec.add_development_dependency "shoulda-matchers"
|
30
|
-
spec.add_development_dependency "webmock"
|
31
|
-
spec.add_development_dependency "dotenv"
|
32
|
-
spec.add_development_dependency "guard"
|
33
|
-
spec.add_development_dependency "guard-rspec"
|
34
27
|
spec.add_development_dependency "pry"
|
35
|
-
spec.add_development_dependency "simplecov"
|
36
|
-
spec.add_development_dependency "coveralls"
|
37
|
-
|
38
28
|
end
|
data/example.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pp'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'databox'
|
5
|
+
|
6
|
+
Databox.configure do |c|
|
7
|
+
c.push_token = ENV["DATABOX_PUSH_TOKEN"]
|
8
|
+
end
|
9
|
+
|
10
|
+
client = Databox::Client.new()
|
11
|
+
|
12
|
+
3.times do |t|
|
13
|
+
client.push("example.ruby", t*100, (DateTime.now - t).strftime('%Y-%m-%d'))
|
14
|
+
end
|
15
|
+
|
16
|
+
pp client.last_push(3)
|
17
|
+
|
data/lib/databox.rb
CHANGED
@@ -1,34 +1,21 @@
|
|
1
|
-
require "httparty"
|
2
|
-
|
3
1
|
module Databox
|
4
|
-
autoload :VERSION,
|
5
|
-
autoload :Client,
|
6
|
-
autoload :Configuration,
|
7
|
-
autoload :Integration, "databox/integration"
|
8
|
-
|
9
|
-
autoload :BigNumber, "databox/integration"
|
10
|
-
autoload :LineChart, "databox/integration"
|
11
|
-
autoload :BarChart, "databox/integration"
|
12
|
-
autoload :Compare, "databox/integration"
|
13
|
-
autoload :Interval, "databox/integration"
|
14
|
-
|
15
|
-
autoload :Pipeline, "databox/integration"
|
16
|
-
autoload :Funnel, "databox/integration"
|
17
|
-
autoload :Pie, "databox/integration"
|
18
|
-
autoload :Progress, "databox/integration"
|
19
|
-
autoload :Messages, "databox/integration"
|
20
|
-
|
2
|
+
autoload :VERSION, 'databox/version'
|
3
|
+
autoload :Client, 'databox/client'
|
4
|
+
autoload :Configuration, 'databox/configuration'
|
21
5
|
|
22
6
|
class << self
|
23
7
|
attr_accessor :configuration
|
24
8
|
|
25
9
|
def configured?
|
26
10
|
return false if configuration.nil?
|
27
|
-
[
|
11
|
+
[
|
12
|
+
configuration.push_host,
|
13
|
+
configuration.push_token
|
14
|
+
].compact.size == 2
|
28
15
|
end
|
29
16
|
|
30
17
|
def client
|
31
|
-
@client ||=
|
18
|
+
@client ||= ::Client.new
|
32
19
|
end
|
33
20
|
end
|
34
21
|
|
@@ -36,5 +23,4 @@ module Databox
|
|
36
23
|
self.configuration ||= Configuration.new
|
37
24
|
yield configuration if block_given?
|
38
25
|
end
|
39
|
-
|
40
26
|
end
|
data/lib/databox/client.rb
CHANGED
@@ -1,90 +1,71 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
|
1
4
|
class Databox::Client
|
2
5
|
include HTTParty
|
3
6
|
format :json
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
debug_output if ENV["HTTPARTY_DEBUG"] == "1"
|
8
|
-
|
7
|
+
headers 'User-Agent' => "Databox/#{Databox::VERSION} (Ruby)"
|
8
|
+
debug_output if [1, "1"].include?(ENV["HTTPARTY_DEBUG"])
|
9
9
|
default_timeout 1 if ENV["DATABOX_MODE"] == "test"
|
10
10
|
|
11
|
-
attr_accessor :
|
12
|
-
def token
|
13
|
-
@token || Databox.configuration.token
|
14
|
-
end
|
15
|
-
|
16
|
-
def key; Databox.configuration.key end
|
17
|
-
def url; Databox.configuration.url end
|
11
|
+
attr_accessor :last_push_content
|
18
12
|
|
19
13
|
def initialize
|
20
14
|
Databox.configure unless Databox.configured?
|
21
15
|
|
22
|
-
self.class.base_uri
|
23
|
-
self.class.basic_auth
|
16
|
+
self.class.base_uri push_host
|
17
|
+
self.class.basic_auth push_token, ''
|
18
|
+
self.class.headers 'Content-Type' => 'application/json'
|
19
|
+
self
|
24
20
|
end
|
25
21
|
|
26
|
-
def
|
27
|
-
|
28
|
-
data = [data] unless data.is_a?(Array)
|
29
|
-
handle self.class.post("/push/custom/#{self.token}", body: { data: data }.to_json)
|
30
|
-
end
|
22
|
+
def push_host
|
23
|
+
Databox.configuration.push_host
|
31
24
|
end
|
32
25
|
|
33
|
-
def
|
34
|
-
|
26
|
+
def push_token
|
27
|
+
Databox.configuration.push_token
|
35
28
|
end
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
response.parsed_response["error"]["type"]+" - "+
|
42
|
-
response.parsed_response["error"]["message"]
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
output = response.parsed_response
|
30
|
+
# Sends data to actual end-point.
|
31
|
+
def raw_push(path='/', data=nil)
|
32
|
+
handle self.class.post(path, data.nil? ? {} : {body: JSON.dump({data: data})})
|
33
|
+
end
|
47
34
|
|
48
|
-
|
49
|
-
|
50
|
-
elsif output.is_a?(Array)
|
51
|
-
output.map { |item| Databox::Response.new(item) }
|
52
|
-
else
|
53
|
-
output
|
54
|
-
end
|
35
|
+
def handle(response)
|
36
|
+
response.parsed_response
|
55
37
|
end
|
56
38
|
|
57
|
-
def
|
58
|
-
|
59
|
-
validate(dp)
|
60
|
-
end if data.is_a?(Array)
|
39
|
+
def process_kpi(options={})
|
40
|
+
options.delete_if { |k, _| [:date, 'date'].include?(k) }
|
61
41
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
# errors.push("Value is required") if data[:value].nil?
|
42
|
+
%i{key value}.each do |k|
|
43
|
+
raise("Missing '#{k}'") if (options[k] || options[k.to_s]).nil?
|
44
|
+
end
|
66
45
|
|
67
|
-
|
68
|
-
|
46
|
+
options["$#{(options['key'] || options[:key])}"] = options['value'] || options[:value]
|
47
|
+
options.delete_if { |k, _| [:key, 'key', :value, 'value'].include?(k) }
|
69
48
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
49
|
+
attributes = options[:attributes] || options['attributes']
|
50
|
+
unless attributes.nil?
|
51
|
+
[:attributes, 'attributes'].each {|k| options.delete(k) }
|
52
|
+
attributes.each { |k,v| options[k] = v }
|
74
53
|
end
|
75
54
|
|
76
|
-
|
55
|
+
options
|
77
56
|
end
|
78
|
-
end
|
79
57
|
|
80
|
-
|
81
|
-
|
82
|
-
|
58
|
+
def push(kpi={})
|
59
|
+
self.last_push_content = raw_push('/', [process_kpi(kpi)])
|
60
|
+
self.last_push_content['status'] == 'ok'
|
61
|
+
end
|
83
62
|
|
84
|
-
|
63
|
+
def insert_all(rows=[])
|
64
|
+
self.last_push_content = raw_push('/', rows.map {|r| process_kpi(r) })
|
65
|
+
self.last_push_content['status'] == 'ok'
|
66
|
+
end
|
85
67
|
|
86
|
-
|
87
|
-
|
88
|
-
self.type == "success"
|
68
|
+
def last_push(n=1)
|
69
|
+
raw_push "/lastpushes/#{n}"
|
89
70
|
end
|
90
71
|
end
|