keen-cli 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # keen-cli
2
2
 
3
- [![Build Status](https://travis-ci.org/keenlabs/keen-cli.svg?branch=master)](https://travis-ci.org/keenlabs/keen-cli)
3
+ [![Build Status](https://travis-ci.org/keen/keen-cli.svg?branch=master)](https://travis-ci.org/keen/keen-cli)
4
4
 
5
5
  A command line interface for the Keen IO analytics API.
6
6
 
@@ -14,9 +14,10 @@ Install the gem:
14
14
  $ gem install keen-cli
15
15
  ```
16
16
 
17
- Verify the `keen` command is in your path by running it:
17
+ Verify the `keen` command is in your path by running it. You should see information about available commands.
18
18
 
19
- ``` shell
19
+ ```
20
+ $ keen
20
21
  Commands:
21
22
  keen average # Alias for queries:run -a average
22
23
  keen collections:delete # Delete events from a collection
@@ -41,13 +42,11 @@ Commands:
41
42
  keen version # Print the keen-cli version
42
43
  ```
43
44
 
44
- You should see information about available commands.
45
-
46
- If `keen` can't be found there might be an issue with your Ruby installation. If you're using [rbenv](https://github.com/sstephenson/rbenv) try running `rbenv rehash` after installation.
45
+ If `keen` can't be found there might be an issue with your Ruby installation. In that case check out [rbenv](https://github.com/sstephenson/rbenv). If you're already using `rbenv` and `keen` still can't be found try running `rbenv rehash` after installation.
47
46
 
48
47
  ### Environment configuration
49
48
 
50
- Most keen-cli commands require the presence of a project and one or more API keys to do meaningful actions. By default, keen-cli attempts to find these in the process environment or a `.env` file in the current directory. This is the same heuristic that [keen-gem](https://github.com/keenlabs/keen-gem) uses and is based on [dotenv](https://github.com/bkeepers/dotenv).
49
+ Most keen-cli commands require the presence of a project and one or more API keys to do meaningful actions. By default, keen-cli attempts to find these in the process environment or a `.env` file in the current directory. This is the same heuristic that [keen-gem](https://github.com/keen/keen-gem) uses and is based on [dotenv](https://github.com/bkeepers/dotenv).
51
50
 
52
51
  An example .env file looks like this:
53
52
 
@@ -190,54 +189,70 @@ Some examples:
190
189
  ``` shell
191
190
  # run a count
192
191
  $ keen queries:run --collection signups --analysis-type count
193
- 1000
192
+ {
193
+ "result": 1000
194
+ }
194
195
 
195
196
  # run a count with collection name from .env
196
197
  # KEEN_COLLECTION_NAME=signups
197
198
  $ keen queries:run --analysis-type count
198
- 1000
199
+ {
200
+ "result": 1000
201
+ }
199
202
 
200
203
  # run a count with a group by
201
204
  $ keen queries:run --collection signups --analysis-type count --group-by username
202
- [
203
- {
204
- "username": "dzello",
205
- "result": 1000
206
- }
207
- ]
205
+ {
206
+ "result": [
207
+ {
208
+ "username": "dzello",
209
+ "result": 1000
210
+ }
211
+ ]
212
+ }
208
213
 
209
214
  # run a query with a timeframe, target property, group by, and interval
210
215
  $ keen queries:run --collection signups --analysis-type count_unique --target-property age --group-by source --timeframe last_24_hours --interval hourly
211
-
212
216
  {
213
- "timeframe": {
214
- "start": "2014-06-27T01:00:00.000Z",
215
- "end": "2014-06-27T02:00:00.000Z"
216
- },
217
- "value": [
218
- ...
219
- ...
220
- ...
217
+ "result": [
218
+ {
219
+ "timeframe": {
220
+ "start": "2014-06-27T01:00:00.000Z",
221
+ "end": "2014-06-27T02:00:00.000Z"
222
+ },
223
+ "value": [
224
+ ...
225
+ ]
226
+ }
227
+ }
228
+ }
221
229
 
222
230
  # run a query with an absolute timeframe
223
231
  $ keen queries:run --analysis-type count --start 2014-07-01T00:00:00Z --end 2014-07-31T23:59:59Z
224
- 1000
232
+ {
233
+ "result": 1000
234
+ }
225
235
 
226
236
  # run an extraction with specific property names
227
237
  $ keen queries:run --collection minecraft-deaths --analysis-type extraction --property-names player,enemy
228
- [
229
- {
230
- "player": "dzello",
231
- "enemy": "creeper"
232
- },
233
- {
234
- "player": "dkador",
235
- "enemy": "creeper"
236
- }
237
- ]
238
+ {
239
+ "result": [
240
+ {
241
+ "player": "dzello",
242
+ "enemy": "creeper"
243
+ },
244
+ {
245
+ "player": "dkador",
246
+ "enemy": "creeper"
247
+ }
248
+ ]
249
+ }
238
250
 
239
251
  # run a query using JSON to specify parameters
240
252
  $ echo "{ \"event_collection\" : \"minecraft-deaths\", \"target_property\": \"level\" }" | keen queries:run -a average
253
+ {
254
+ "result": 2
255
+ }
241
256
  ```
242
257
 
243
258
  **Query URL Generation**
@@ -272,6 +287,7 @@ Parameters that apply to most commands include:
272
287
 
273
288
  ### Changelog
274
289
 
290
+ + 0.2.2 - Return full API JSON response for queries
275
291
  + 0.2.1 - Add `collections:delete` command
276
292
  + 0.2.0 - Add support for [spark](https://github.com/holman/spark) ▁▂▃▅▇
277
293
  + 0.1.9 - Supports JSON-encoded filters and comma-seperated multiple group by
@@ -289,7 +305,7 @@ Parameters that apply to most commands include:
289
305
 
290
306
  keen-cli is open source, and contributions are very welcome!
291
307
 
292
- Running the tests with:
308
+ Run the tests with:
293
309
 
294
310
  ```
295
311
  $ bundle exec rake spec
data/keen-cli.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.description = "Record events and run queries from the comfort of your command line"
13
13
  s.license = "MIT"
14
14
 
15
- s.add_dependency "keen", ">= 0.8.6"
15
+ s.add_dependency "keen", ">= 0.8.8"
16
16
  s.add_dependency "thor"
17
17
  s.add_dependency "dotenv"
18
18
 
@@ -40,11 +40,11 @@ module KeenCli
40
40
 
41
41
  query_options = to_query_options(options)
42
42
 
43
- result = Keen.query(analysis_type, collection, query_options)
43
+ result = Keen.query(analysis_type, collection, query_options, :response => :all_keys)
44
44
 
45
45
  if (options[:spark])
46
46
  raise 'Spark only applies to series queries!' unless options[:interval]
47
- numbers = result.map do |object|
47
+ numbers = result["result"].map do |object|
48
48
  object['value']
49
49
  end
50
50
  return numbers.join(' ').tap do |numbers_str|
@@ -1,3 +1,3 @@
1
1
  module KeenCli
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -7,33 +7,35 @@ describe KeenCli::CLI do
7
7
  let(:read_key) { Keen.read_key }
8
8
  let(:write_key) { Keen.write_key }
9
9
 
10
+ let(:expected_response) { { "result" => 10 } }
11
+
10
12
  describe 'queries:run' do
11
13
  it 'runs the query using certain params' do
12
14
  url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths"
13
15
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
14
16
  _, options = start 'queries:run --analysis-type count --collection minecraft-deaths'
15
- expect(_).to eq(10)
17
+ expect(_).to eq(expected_response)
16
18
  end
17
19
 
18
20
  it 'runs the query using aliased params' do
19
21
  url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths"
20
22
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
21
23
  _, options = start 'queries:run -a count -c minecraft-deaths'
22
- expect(_).to eq(10)
24
+ expect(_).to eq(expected_response)
23
25
  end
24
26
 
25
27
  it 'converts dashes to underscores for certain properties' do
26
28
  url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&group_by=%5B%22foo%22%5D&target_property=bar"
27
29
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
28
30
  _, options = start 'queries:run --analysis-type count --collection minecraft-deaths --group-by foo --target-property bar'
29
- expect(_).to eq(10)
31
+ expect(_).to eq(expected_response)
30
32
  end
31
33
 
32
34
  it 'allows comma-delimited group by fields' do
33
35
  url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&group_by=%5B%22%5C%22foo%22,%22bar%5C%22%22%5D&target_property=bar"
34
36
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
35
37
  _, options = start 'queries:run --analysis-type count --collection minecraft-deaths --group-by "foo,bar" --target-property bar'
36
- expect(_).to eq(10)
38
+ expect(_).to eq(expected_response)
37
39
  end
38
40
 
39
41
  it 'parses filters as JSON' do
@@ -41,49 +43,49 @@ describe KeenCli::CLI do
41
43
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
42
44
  filters = '[{"property_name":"enemy","operator":"eq","property_value":"creeper"}]'
43
45
  _, options = start "queries:run --analysis-type count --collection minecraft-deaths --filters #{filters}"
44
- expect(_).to eq(10)
46
+ expect(_).to eq(expected_response)
45
47
  end
46
48
 
47
49
  it 'accepts extraction-specific properties' do
48
50
  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"
49
51
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
50
52
  _, options = start 'queries:run --analysis-type extraction --collection minecraft-deaths --property-names foo,bar --latest 1 --email bob@bob.io'
51
- expect(_).to eq(10)
53
+ expect(_).to eq(expected_response)
52
54
  end
53
55
 
54
56
  it 'converts comma-delimited property names to an array' do
55
57
  url = "https://api.keen.io/3.0/projects/#{project_id}/queries/extraction?event_collection=minecraft-deaths&property_names=%5B%22foo%22,%22bar%22%5D"
56
58
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
57
59
  _, options = start 'queries:run --analysis-type extraction --collection minecraft-deaths --property-names foo,bar'
58
- expect(_).to eq(10)
60
+ expect(_).to eq(expected_response)
59
61
  end
60
62
 
61
63
  it 'uses a data option to take in query JSON' do
62
64
  url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths"
63
65
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
64
66
  _, options = start 'queries:run --analysis-type count --collection minecraft-deaths --data {"event_collection":"minecraft-deaths"}'
65
- expect(_).to eq(10)
67
+ expect(_).to eq(expected_response)
66
68
  end
67
69
 
68
70
  it 'converts a start parameter into an absolute timeframe' do
69
71
  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"
70
72
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
71
73
  _, options = start 'queries:run --collection minecraft-deaths --analysis-type count --start 2014-07-06T12:00:00Z'
72
- expect(_).to eq(10)
74
+ expect(_).to eq(expected_response)
73
75
  end
74
76
 
75
77
  it 'converts an end parameter into an absolute timeframe' do
76
78
  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"
77
79
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
78
80
  _, options = start 'queries:run --collection minecraft-deaths --analysis-type count --end 2014-07-06T12:00:00Z'
79
- expect(_).to eq(10)
81
+ expect(_).to eq(expected_response)
80
82
  end
81
83
 
82
84
  it 'converts start and end parameters into an absolute timeframe' do
83
85
  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"
84
86
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
85
87
  _, options = start 'queries:run --collection minecraft-deaths --analysis-type count --start 2014-07-06T12:00:00Z --end 2014-07-08T12:00:00Z'
86
- expect(_).to eq(10)
88
+ expect(_).to eq(expected_response)
87
89
  end
88
90
 
89
91
  end
@@ -131,7 +133,7 @@ describe KeenCli::CLI do
131
133
  url = "https://api.keen.io/3.0/projects/#{project_id}/queries/#{underscored_analysis_type}?event_collection=minecraft-deaths"
132
134
  stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
133
135
  _, options = start "#{analysis_type} --collection minecraft-deaths"
134
- expect(_).to eq(10)
136
+ expect(_).to eq(expected_response)
135
137
  end
136
138
  end
137
139
  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.2.1
4
+ version: 0.2.2
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-08-22 00:00:00.000000000 Z
12
+ date: 2014-12-20 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.6
21
+ version: 0.8.8
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.6
29
+ version: 0.8.8
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: thor
32
32
  requirement: !ruby/object:Gem::Requirement