databox 0.1.2 → 0.2.1
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.
- 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
data/lib/databox/integration.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
class Databox::Integration < Databox::Client
|
2
|
-
|
3
|
-
attr_accessor :name, :list, :set_item, :date
|
4
|
-
|
5
|
-
def initialize name, options={date: nil, id: nil}
|
6
|
-
super()
|
7
|
-
@name = name
|
8
|
-
|
9
|
-
@date = options[:date] unless options[:date].nil?
|
10
|
-
@token = options[:id] unless options[:id].nil?
|
11
|
-
|
12
|
-
@list = []
|
13
|
-
@set_item = nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def save
|
17
|
-
if push(to_data).success?
|
18
|
-
@list = []
|
19
|
-
@set_item = nil
|
20
|
-
true
|
21
|
-
else
|
22
|
-
false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
class Databox::Messages < Databox::Integration
|
29
|
-
|
30
|
-
def add message, icon
|
31
|
-
@list.push [message, icon]
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_data
|
35
|
-
[
|
36
|
-
{ key: "#{name}", value: list.map(&:first) },
|
37
|
-
{ key: "#{name}@icons", value: list.map{|e| e[1] } },
|
38
|
-
]
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
#TODO: Add support for icons
|
44
|
-
#TODO: Add support for changes
|
45
|
-
class Databox::Pipeline < Databox::Integration
|
46
|
-
|
47
|
-
def add message, value
|
48
|
-
@list.push [message, value]
|
49
|
-
end
|
50
|
-
|
51
|
-
def to_data
|
52
|
-
[
|
53
|
-
{ key: "#{name}@labels", value: list.map(&:first) },
|
54
|
-
{ key: "#{name}@values", value: list.map{|e| e[1] } },
|
55
|
-
]
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
#TODO: Add support for icons
|
64
|
-
#TODO: Add support for changes
|
65
|
-
class Databox::Funnel < Databox::Pipeline; end;
|
66
|
-
class Databox::Pie < Databox:: Pipeline; end;
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
class Databox::Progress < Databox::Integration
|
71
|
-
|
72
|
-
def add *args
|
73
|
-
raise "Progress does not support add!"
|
74
|
-
end
|
75
|
-
|
76
|
-
def set message, max, value
|
77
|
-
@set_item = [message, max, value]
|
78
|
-
end
|
79
|
-
|
80
|
-
def to_data
|
81
|
-
[
|
82
|
-
{ key: "#{name}@label", value: @set_item.first },
|
83
|
-
{ key: "#{name}@max_value", value: @set_item[1] },
|
84
|
-
{ key: "#{name}", value: @set_item.last },
|
85
|
-
]
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
class Databox::BigNumber < Databox::Integration
|
93
|
-
def set number, date=nil
|
94
|
-
date ||= @date
|
95
|
-
@set_item = [number, date]
|
96
|
-
end
|
97
|
-
|
98
|
-
def to_data
|
99
|
-
out = {key: name, value: @set_item.first}
|
100
|
-
out.merge!({date: @set_item[1]}) unless @set_item[1].nil?
|
101
|
-
out
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
class Databox::LineChart < Databox::Integration
|
108
|
-
|
109
|
-
def add value, date=nil
|
110
|
-
date ||= @date
|
111
|
-
@list.push [value, date]
|
112
|
-
end
|
113
|
-
|
114
|
-
def to_data
|
115
|
-
@list.map do |i|
|
116
|
-
out = {key: name, value: i.first}
|
117
|
-
out.merge!({date: i[1]}) unless i[1].nil?
|
118
|
-
out
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
class Databox::BarChart < Databox::LineChart; end;
|
124
|
-
|
125
|
-
class Databox::Compare < Databox::LineChart; end;
|
126
|
-
|
127
|
-
class Databox::Interval < Databox::LineChart; end;
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::BarChart do
|
4
|
-
|
5
|
-
let(:chart){ Databox::BarChart.new "my_bar" }
|
6
|
-
|
7
|
-
context "simple" do
|
8
|
-
before {
|
9
|
-
stub_request(:post, /push/)
|
10
|
-
.to_return { request_from "bar_chart_simple" }
|
11
|
-
}
|
12
|
-
|
13
|
-
before do
|
14
|
-
chart.add 2000, "2014-01-29"
|
15
|
-
chart.add 1600, "2014-02-01"
|
16
|
-
chart.add 999, "2014-02-03"
|
17
|
-
end
|
18
|
-
|
19
|
-
it { expect(chart.save).to be_true }
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::BigNumber do
|
4
|
-
|
5
|
-
let(:number){ Databox::BigNumber.new "just_number" }
|
6
|
-
|
7
|
-
context "simple" do
|
8
|
-
before {
|
9
|
-
stub_request(:post, /push/)
|
10
|
-
.to_return { request_from "big_number_simple" }
|
11
|
-
}
|
12
|
-
|
13
|
-
before { number.set 5000, "2014-02-03T00:00:00" }
|
14
|
-
it { expect(number.to_data[:date]).not_to be_nil }
|
15
|
-
it { expect(number.save).to be_true }
|
16
|
-
end
|
17
|
-
|
18
|
-
context "without date" do
|
19
|
-
before { number.set 5000 }
|
20
|
-
it { expect(number.to_data[:date]).to be_nil }
|
21
|
-
end
|
22
|
-
|
23
|
-
context "with constructor" do
|
24
|
-
let(:number_2){ Databox::BigNumber.new "just_number", date: "2014-01-26T00:00:00" }
|
25
|
-
before{ number_2.set 60000 }
|
26
|
-
it { expect(number_2.to_data[:date]).not_to be_nil }
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::Compare do
|
4
|
-
|
5
|
-
let(:compare){ Databox::Compare.new "my_compare" }
|
6
|
-
|
7
|
-
context "simple" do
|
8
|
-
before {
|
9
|
-
stub_request(:post, /push/)
|
10
|
-
.to_return { request_from "compare_simple" }
|
11
|
-
}
|
12
|
-
|
13
|
-
before do
|
14
|
-
compare.add 2000, "2014-01-25"
|
15
|
-
compare.add 1600, "2014-01-26"
|
16
|
-
end
|
17
|
-
|
18
|
-
it { expect(compare.save).to be_true }
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
data/spec/databox/funnel_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::Funnel do
|
4
|
-
|
5
|
-
before do
|
6
|
-
Databox.configure do |c|
|
7
|
-
c.token = "218oxlmk3ikkogo0"
|
8
|
-
c.key = "3s70rekrhcmcgkccssckc448kgw04ssk"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:funnel){ Databox::Funnel.new "little_funnel" }
|
13
|
-
|
14
|
-
context "simple" do
|
15
|
-
before {
|
16
|
-
stub_request(:post, /push/)
|
17
|
-
.to_return { request_from "funnel_simple" }
|
18
|
-
}
|
19
|
-
|
20
|
-
before do
|
21
|
-
funnel.add "Requests sent", 2000
|
22
|
-
funnel.add "New Accounts", 1600
|
23
|
-
funnel.add "Viewed results", 999
|
24
|
-
end
|
25
|
-
|
26
|
-
it { expect(funnel.save).to be_true }
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::Integration do
|
4
|
-
|
5
|
-
context "token" do
|
6
|
-
subject { Databox::Integration.new(nil, id: "some fake token") }
|
7
|
-
it { expect(subject.token).to eq "some fake token" }
|
8
|
-
it { expect(Databox::Integration.new(nil).token).not_to be_nil }
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::Interval do
|
4
|
-
|
5
|
-
let(:interval){ Databox::Interval.new "my_interval" }
|
6
|
-
|
7
|
-
context "simple" do
|
8
|
-
before {
|
9
|
-
stub_request(:post, /push/)
|
10
|
-
.to_return { request_from "interval_simple" }
|
11
|
-
}
|
12
|
-
|
13
|
-
before do
|
14
|
-
interval.add 2000, "2014-01-25"
|
15
|
-
interval.add 1600, "2014-01-26"
|
16
|
-
interval.add 2200, "2014-01-27"
|
17
|
-
end
|
18
|
-
|
19
|
-
it { expect(interval.save).to be_true }
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::LineChart do
|
4
|
-
|
5
|
-
let(:chart){ Databox::LineChart.new "my_line" }
|
6
|
-
|
7
|
-
context "simple" do
|
8
|
-
before {
|
9
|
-
stub_request(:post, /push/)
|
10
|
-
.to_return { request_from "line_chart_simple" }
|
11
|
-
}
|
12
|
-
|
13
|
-
before do
|
14
|
-
chart.add 2000, "2014-01-29"
|
15
|
-
chart.add 1600, "2014-02-01"
|
16
|
-
chart.add 999, "2014-02-03"
|
17
|
-
end
|
18
|
-
|
19
|
-
it { expect(chart.save).to be_true }
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::Messages do
|
4
|
-
|
5
|
-
let(:messages){ Databox::Messages.new("just_messages") }
|
6
|
-
|
7
|
-
context "add messages" do
|
8
|
-
it { expect(messages.name).to eq "just_messages" }
|
9
|
-
|
10
|
-
it {
|
11
|
-
expect { messages.add("Just message", "Number") }
|
12
|
-
.to change { messages.list.size }.from(0).to(1)
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
context "save" do
|
17
|
-
context "simple" do
|
18
|
-
before {
|
19
|
-
stub_request(:post, /push/)
|
20
|
-
.to_return { request_from "simple_message" }
|
21
|
-
}
|
22
|
-
|
23
|
-
before { messages.add("I was here", "USD") }
|
24
|
-
|
25
|
-
it {
|
26
|
-
expect { messages.save }
|
27
|
-
.to change { messages.list.size }.to(0)
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
context "multiple" do
|
32
|
-
before {
|
33
|
-
stub_request(:post, /push/)
|
34
|
-
.to_return { request_from "multiple_message" }
|
35
|
-
}
|
36
|
-
|
37
|
-
before do
|
38
|
-
messages.add("I was here", "Number")
|
39
|
-
messages.add("This is test", "EUR")
|
40
|
-
end
|
41
|
-
|
42
|
-
it {
|
43
|
-
expect { messages.save }
|
44
|
-
.to change { messages.list.size }.to(0)
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
data/spec/databox/pie_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::Pie do
|
4
|
-
|
5
|
-
let(:pie){ Databox::Pie.new "my_pie" }
|
6
|
-
|
7
|
-
context "simple" do
|
8
|
-
before {
|
9
|
-
stub_request(:post, /push/)
|
10
|
-
.to_return { request_from "pie_simple" }
|
11
|
-
}
|
12
|
-
|
13
|
-
before do
|
14
|
-
pie.add "A", 3_014
|
15
|
-
pie.add "B", 29_496
|
16
|
-
pie.add "C", 9_121
|
17
|
-
pie.add "D", 20_390
|
18
|
-
pie.add "E", 7_423
|
19
|
-
end
|
20
|
-
|
21
|
-
it { expect(pie.save).to be_true }
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::Pipeline do
|
4
|
-
|
5
|
-
let(:pipeline){ Databox::Pipeline.new "pipe_visits" }
|
6
|
-
|
7
|
-
context "simple" do
|
8
|
-
before {
|
9
|
-
stub_request(:post, /push/)
|
10
|
-
.to_return { request_from "multiple_message" }
|
11
|
-
}
|
12
|
-
|
13
|
-
before do
|
14
|
-
pipeline.add "Step I.", 2000
|
15
|
-
pipeline.add "Step II.", 1600
|
16
|
-
pipeline.add "Step III.", 999
|
17
|
-
pipeline.add "Step IV.", 100
|
18
|
-
end
|
19
|
-
|
20
|
-
it { expect(pipeline.save).to be_true }
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Databox::Progress do
|
4
|
-
|
5
|
-
let(:progress){ Databox::Progress.new "my_progress" }
|
6
|
-
|
7
|
-
context "simple" do
|
8
|
-
before {
|
9
|
-
stub_request(:post, /push/)
|
10
|
-
.to_return { request_from "progress_simple" }
|
11
|
-
}
|
12
|
-
|
13
|
-
before do
|
14
|
-
progress.set "33% done", 100, 33
|
15
|
-
end
|
16
|
-
|
17
|
-
it { expect(progress.save).to be_true }
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
HTTP/1.1 200 OK
|
2
|
-
Server: nginx/1.4.4
|
3
|
-
Date: Mon, 03 Feb 2014 16:38:19 GMT
|
4
|
-
Content-Type: application/json
|
5
|
-
Transfer-Encoding: chunked
|
6
|
-
Connection: keep-alive
|
7
|
-
Vary: Accept-Encoding
|
8
|
-
X-Powered-By: PHP/5.4.23
|
9
|
-
Set-Cookie: zep_uid=kir9md6qrahslhdk382jnce183; path=/
|
10
|
-
Expires: Thu, 19 Nov 1981 08:52:00 GMT
|
11
|
-
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
12
|
-
Pragma: no-cache
|
13
|
-
|
14
|
-
{"response":{"type":"success","message":"Items stored: 3"}}
|