keen-cli 0.1.5 → 0.1.6
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 +77 -49
- data/keen-cli.gemspec +1 -1
- data/lib/keen-cli/batch_processor.rb +104 -0
- data/lib/keen-cli/cli.rb +9 -234
- data/lib/keen-cli/events.rb +70 -0
- data/lib/keen-cli/projects.rb +51 -0
- data/lib/keen-cli/queries.rb +138 -0
- data/lib/keen-cli/shared.rb +28 -0
- data/lib/keen-cli/utils.rb +18 -0
- data/lib/keen-cli/version.rb +1 -1
- data/lib/keen-cli.rb +16 -0
- data/spec/keen-cli/batch_processor_spec.rb +134 -0
- data/spec/keen-cli/cli_spec.rb +4 -161
- data/spec/keen-cli/events_spec.rb +41 -0
- data/spec/keen-cli/projects_spec.rb +42 -0
- data/spec/keen-cli/queries_spec.rb +106 -0
- data/spec/spec_helper.rb +13 -0
- metadata +17 -4
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KeenCli::CLI do
|
4
|
+
|
5
|
+
let(:project_id) { Keen.project_id }
|
6
|
+
let(:master_key) { Keen.master_key }
|
7
|
+
let(:read_key) { Keen.read_key }
|
8
|
+
let(:write_key) { Keen.write_key }
|
9
|
+
|
10
|
+
describe 'queries:run' do
|
11
|
+
it 'runs the query using certain params' do
|
12
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths"
|
13
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
14
|
+
_, options = start 'queries:run --analysis-type count --collection minecraft-deaths'
|
15
|
+
expect(_).to eq(10)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'runs the query using aliased params' do
|
19
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths"
|
20
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
21
|
+
_, options = start 'queries:run -a count -c minecraft-deaths'
|
22
|
+
expect(_).to eq(10)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'converts dashes to underscores for certain properties' do
|
26
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&group_by=foo&target_property=bar"
|
27
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
28
|
+
_, options = start 'queries:run --analysis-type count --collection minecraft-deaths --group-by foo --target-property bar'
|
29
|
+
expect(_).to eq(10)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'accepts extraction-specific properties' do
|
33
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/extraction?event_collection=minecraft-deaths&property_names=%5B%22foo%22,%22bar%22%5D&latest=1&email=bob@bob.io"
|
34
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
35
|
+
_, options = start 'queries:run --analysis-type extraction --collection minecraft-deaths --property-names foo,bar --latest 1 --email bob@bob.io'
|
36
|
+
expect(_).to eq(10)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'converts comma-delimited property names to an array' do
|
40
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/extraction?event_collection=minecraft-deaths&property_names=%5B%22foo%22,%22bar%22%5D"
|
41
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
42
|
+
_, options = start 'queries:run --analysis-type extraction --collection minecraft-deaths --property-names foo,bar'
|
43
|
+
expect(_).to eq(10)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'uses a data option to take in query JSON' do
|
47
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths"
|
48
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
49
|
+
_, options = start 'queries:run --analysis-type count --collection minecraft-deaths --data {"event_collection":"minecraft-deaths"}'
|
50
|
+
expect(_).to eq(10)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'converts a start parameter into an absolute timeframe' do
|
54
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&timeframe=%7B%22start%22:%222014-07-06T12:00:00Z%22%7D"
|
55
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
56
|
+
_, options = start 'queries:run --collection minecraft-deaths --analysis-type count --start 2014-07-06T12:00:00Z'
|
57
|
+
expect(_).to eq(10)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'converts an end parameter into an absolute timeframe' do
|
61
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&timeframe=%7B%22end%22:%222014-07-06T12:00:00Z%22%7D"
|
62
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
63
|
+
_, options = start 'queries:run --collection minecraft-deaths --analysis-type count --end 2014-07-06T12:00:00Z'
|
64
|
+
expect(_).to eq(10)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'converts start and end parameters into an absolute timeframe' do
|
68
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&timeframe=%7B%22start%22:%222014-07-06T12:00:00Z%22,%22end%22:%222014-07-08T12:00:00Z%22%7D"
|
69
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
70
|
+
_, options = start 'queries:run --collection minecraft-deaths --analysis-type count --start 2014-07-06T12:00:00Z --end 2014-07-08T12:00:00Z'
|
71
|
+
expect(_).to eq(10)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'queries:url' do
|
77
|
+
|
78
|
+
it 'should return the url instead of running the query' do
|
79
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&api_key=#{Keen.read_key}"
|
80
|
+
_, options = start 'queries:url --analysis-type count --collection minecraft-deaths'
|
81
|
+
expect(_).to eq(url)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should not include the api key if excluded' do
|
85
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths"
|
86
|
+
_, options = start 'queries:url --analysis-type count --collection minecraft-deaths --exclude-api-key'
|
87
|
+
expect(_).to eq(url)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "queries:run aliases" do
|
93
|
+
KeenCli::CLI::ANALYSIS_TYPES.each do |analysis_type|
|
94
|
+
describe analysis_type do
|
95
|
+
it "aliases to queries run, passing along the #{analysis_type} analysis type" do
|
96
|
+
underscored_analysis_type = analysis_type.sub('-', '_')
|
97
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/#{underscored_analysis_type}?event_collection=minecraft-deaths"
|
98
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
99
|
+
_, options = start "#{analysis_type} --collection minecraft-deaths"
|
100
|
+
expect(_).to eq(10)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,4 +5,17 @@ require File.expand_path("../../lib/keen-cli", __FILE__)
|
|
5
5
|
|
6
6
|
RSpec.configure do |config|
|
7
7
|
|
8
|
+
config.before(:each) do
|
9
|
+
Keen.project_id = 'AAAAAAA'
|
10
|
+
Keen.read_key = 'DDDDDD'
|
11
|
+
Keen.write_key = 'BBBBBB'
|
12
|
+
Keen.master_key = 'CCCCCC'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def start(str=nil)
|
18
|
+
arry = str ? str.split(" ") : []
|
19
|
+
arry.push("--silent")
|
20
|
+
KeenCli::CLI.start(arry)
|
8
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keen-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
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: 2014-
|
12
|
+
date: 2014-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: keen
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.8.
|
21
|
+
version: 0.8.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.8.
|
29
|
+
version: 0.8.6
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: thor
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,12 +139,21 @@ files:
|
|
139
139
|
- bin/keen
|
140
140
|
- keen-cli.gemspec
|
141
141
|
- lib/keen-cli.rb
|
142
|
+
- lib/keen-cli/batch_processor.rb
|
142
143
|
- lib/keen-cli/cli.rb
|
144
|
+
- lib/keen-cli/events.rb
|
145
|
+
- lib/keen-cli/projects.rb
|
146
|
+
- lib/keen-cli/queries.rb
|
147
|
+
- lib/keen-cli/shared.rb
|
143
148
|
- lib/keen-cli/utils.rb
|
144
149
|
- lib/keen-cli/version.rb
|
145
150
|
- spec/fixtures/events.csv
|
146
151
|
- spec/fixtures/events.json
|
152
|
+
- spec/keen-cli/batch_processor_spec.rb
|
147
153
|
- spec/keen-cli/cli_spec.rb
|
154
|
+
- spec/keen-cli/events_spec.rb
|
155
|
+
- spec/keen-cli/projects_spec.rb
|
156
|
+
- spec/keen-cli/queries_spec.rb
|
148
157
|
- spec/spec_helper.rb
|
149
158
|
homepage: https://github.com/keenlabs/keen-cli
|
150
159
|
licenses:
|
@@ -174,6 +183,10 @@ summary: Command line interface to Keen IO
|
|
174
183
|
test_files:
|
175
184
|
- spec/fixtures/events.csv
|
176
185
|
- spec/fixtures/events.json
|
186
|
+
- spec/keen-cli/batch_processor_spec.rb
|
177
187
|
- spec/keen-cli/cli_spec.rb
|
188
|
+
- spec/keen-cli/events_spec.rb
|
189
|
+
- spec/keen-cli/projects_spec.rb
|
190
|
+
- spec/keen-cli/queries_spec.rb
|
178
191
|
- spec/spec_helper.rb
|
179
192
|
has_rdoc:
|