keen-cli 0.1.4 → 0.1.5
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 +25 -16
- data/lib/keen-cli/cli.rb +38 -14
- data/lib/keen-cli/version.rb +1 -1
- data/spec/fixtures/events.csv +4 -0
- data/spec/fixtures/events.json +3 -0
- data/spec/keen-cli/cli_spec.rb +29 -0
- metadata +6 -2
data/README.md
CHANGED
@@ -96,8 +96,10 @@ keen-cli has a variety of commands, and most are namespaced for clarity.
|
|
96
96
|
|
97
97
|
Parameters:
|
98
98
|
|
99
|
-
+ `--collection
|
100
|
-
+ `--data
|
99
|
+
+ `--collection`, `-c`: The collection to add the event to. Alternately you can set `KEEN_COLLECTION_NAME` on the environment if you're working with the same collection frequently.
|
100
|
+
+ `--data`, `-d`: The properties of the event. The value can be JSON or `key=value` pairs delimited by `&` (just like a query string). Data can also be piped in via STDIN.
|
101
|
+
+ `--file`, `-f`: The name of a file that contains newline delimited JSON
|
102
|
+
+ `--csv`: Specify that the file is in CSV format
|
101
103
|
|
102
104
|
Various examples:
|
103
105
|
|
@@ -124,6 +126,12 @@ $ echo "{ \"username\" : \"dzello\", \"zsh\": 1 }" | keen events:add -c cli-test
|
|
124
126
|
# pipe in events in querystring format
|
125
127
|
$ echo "username=dzello&zsh=1" | keen events:add -c cli-test
|
126
128
|
|
129
|
+
# specify a file that contains newline delimited json
|
130
|
+
$ keen events:add --file events.json
|
131
|
+
|
132
|
+
# specify a file in CSV format
|
133
|
+
$ keen events:add --csv --file events.csv
|
134
|
+
|
127
135
|
# pipe in events from a file of newline delimited json
|
128
136
|
# { "username" : "dzello", "zsh" : 1 }
|
129
137
|
# { "username" : "dkador", "zsh" : 1 }
|
@@ -137,20 +145,20 @@ $ cat events.json | keen events:add -c cli-test
|
|
137
145
|
|
138
146
|
Parameters:
|
139
147
|
|
140
|
-
+ `--collection
|
141
|
-
+ `--analysis-type
|
142
|
-
+ `--group-by
|
143
|
-
+ `--target-property
|
144
|
-
+ `--timeframe
|
145
|
-
+ `--start
|
146
|
-
+ `--end
|
147
|
-
+ `--interval
|
148
|
-
+ `--filters
|
149
|
-
+ `--percentile
|
150
|
-
+ `--property-names
|
151
|
-
+ `--latest
|
152
|
-
+ `--email
|
153
|
-
+ `--data
|
148
|
+
+ `--collection`, `-c`: – The collection to query against. Can also be set on the environment via `KEEN_COLLECTION_NAME`.
|
149
|
+
+ `--analysis-type`, `-a`: The analysis type for the query. Only needed when not using a query command alias.
|
150
|
+
+ `--group-by`, `-g`: A group by for the query.
|
151
|
+
+ `--target-property`, `-y`: A target property for the query.
|
152
|
+
+ `--timeframe`, `-t`: A relative timeframe, e.g. `last_60_minutes`.
|
153
|
+
+ `--start`, `-s`: The start time of an absolute timeframe.
|
154
|
+
+ `--end`, `-e`: The end time of an absolute timeframe.
|
155
|
+
+ `--interval`, `-i`: The interval for a series query.
|
156
|
+
+ `--filters`, `-f`: A set of filters for the query, passed as JSON.
|
157
|
+
+ `--percentile`: The percentile value (e.g. 99) for a percentile query.
|
158
|
+
+ `--property-names`: A comma-separated list of property names. Extractions only.
|
159
|
+
+ `--latest`: Number of latest events to retrieve. Extractions only.
|
160
|
+
+ `--email`: Send extraction results via email, asynchronously. Extractions only.
|
161
|
+
+ `--data`, `-d`: Specify query parameters as JSON instead of query params. Data can also be piped in via STDIN.
|
154
162
|
|
155
163
|
Some examples:
|
156
164
|
|
@@ -224,6 +232,7 @@ Run `keen` with no arguments to see the full list of aliases.
|
|
224
232
|
|
225
233
|
### Changelog
|
226
234
|
|
235
|
+
+ 0.1.5 – Support adding events from files with `--file`. Optionally add from CSV with `--csv`.
|
227
236
|
+ 0.1.4 – Support absolute timeframes via `--start` and `--end` flags
|
228
237
|
+ 0.1.3 – Add querying via JSON. Add query aliases. Add support for extraction fields.
|
229
238
|
+ 0.1.2 – Change `project:show` to `project:describe`
|
data/lib/keen-cli/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'keen'
|
3
3
|
require 'json'
|
4
|
+
require 'csv'
|
4
5
|
|
5
6
|
require 'keen-cli/utils'
|
6
7
|
|
@@ -19,6 +20,11 @@ module KeenCli
|
|
19
20
|
option :data, :aliases => ['-d']
|
20
21
|
end
|
21
22
|
|
23
|
+
def self.file_options
|
24
|
+
option :file, :aliases => ['-f']
|
25
|
+
option :csv
|
26
|
+
end
|
27
|
+
|
22
28
|
def self.collection_options
|
23
29
|
option :collection, :aliases => ['-c']
|
24
30
|
end
|
@@ -182,34 +188,52 @@ module KeenCli
|
|
182
188
|
|
183
189
|
shared_options
|
184
190
|
data_options
|
191
|
+
file_options
|
185
192
|
collection_options
|
186
193
|
|
187
194
|
def events_add
|
188
195
|
|
189
196
|
events = []
|
197
|
+
collection = Utils.get_collection_name(options)
|
198
|
+
|
199
|
+
if options[:csv]
|
200
|
+
|
201
|
+
data = File.read(options[:file])
|
202
|
+
csv = CSV.new(data, :headers => true, :header_converters => :symbol, :converters => :all)
|
203
|
+
events = csv.to_a.map {|row| row.to_hash }
|
190
204
|
|
191
|
-
if $stdin.tty?
|
192
|
-
events.push(options[:data] || {})
|
193
205
|
else
|
194
|
-
|
195
|
-
|
196
|
-
|
206
|
+
|
207
|
+
if $stdin.tty?
|
208
|
+
if data = options[:data]
|
209
|
+
events.push(data)
|
210
|
+
elsif file = options[:file]
|
211
|
+
File.readlines(file).each do |line|
|
212
|
+
events.push(line)
|
213
|
+
end
|
214
|
+
else
|
215
|
+
events.push({})
|
216
|
+
end
|
217
|
+
else
|
218
|
+
ARGV.clear
|
219
|
+
ARGF.each_line do |line|
|
220
|
+
events.push(line)
|
221
|
+
end
|
197
222
|
end
|
198
|
-
end
|
199
223
|
|
200
|
-
|
201
|
-
begin
|
202
|
-
JSON.parse(event)
|
203
|
-
rescue
|
224
|
+
events = events.map do |event|
|
204
225
|
begin
|
205
|
-
|
226
|
+
JSON.parse(event)
|
206
227
|
rescue
|
207
|
-
|
228
|
+
begin
|
229
|
+
Utils.parse_data_as_querystring(event)
|
230
|
+
rescue
|
231
|
+
event
|
232
|
+
end
|
208
233
|
end
|
209
234
|
end
|
210
|
-
end
|
211
235
|
|
212
|
-
|
236
|
+
end
|
213
237
|
|
214
238
|
if events.length > 1
|
215
239
|
|
data/lib/keen-cli/version.rb
CHANGED
data/spec/keen-cli/cli_spec.rb
CHANGED
@@ -140,4 +140,33 @@ describe KeenCli::CLI do
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
end
|
143
|
+
|
144
|
+
describe 'events:add' do
|
145
|
+
it 'should accept JSON events from a data param' do
|
146
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/events/minecraft-deaths"
|
147
|
+
stub_request(:post, url).
|
148
|
+
with(:body => { "foo" => 1 }).
|
149
|
+
to_return(:body => { :created => true }.to_json)
|
150
|
+
_, options = start 'events:add --collection minecraft-deaths --data {"foo":1}'
|
151
|
+
expect(_).to eq("created" => true)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should accept JSON events from a file param' do
|
155
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/events/minecraft-deaths"
|
156
|
+
stub_request(:post, "https://api.keen.io/3.0/projects/AAAAAAA/events").
|
157
|
+
with(:body => "{\"minecraft-deaths\":[{\"foo\":1},{\"foo\":2},{\"foo\":3}]}").
|
158
|
+
to_return(:body => { :created => true }.to_json)
|
159
|
+
_, options = start "events:add --collection minecraft-deaths --file #{File.expand_path('../../fixtures/events.json', __FILE__)}"
|
160
|
+
expect(_).to eq("created" => true)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should accept JSON events from a file param in CSV format' do
|
164
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/events/minecraft-deaths"
|
165
|
+
stub_request(:post, "https://api.keen.io/3.0/projects/AAAAAAA/events").
|
166
|
+
with(:body => "{\"minecraft-deaths\":[{\"foo\":1},{\"foo\":2},{\"foo\":3}]}").
|
167
|
+
to_return(:body => { :created => true }.to_json)
|
168
|
+
_, options = start "events:add --collection minecraft-deaths --csv --file #{File.expand_path('../../fixtures/events.csv', __FILE__)}"
|
169
|
+
expect(_).to eq("created" => true)
|
170
|
+
end
|
171
|
+
end
|
143
172
|
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.5
|
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-07-
|
12
|
+
date: 2014-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: keen
|
@@ -142,6 +142,8 @@ files:
|
|
142
142
|
- lib/keen-cli/cli.rb
|
143
143
|
- lib/keen-cli/utils.rb
|
144
144
|
- lib/keen-cli/version.rb
|
145
|
+
- spec/fixtures/events.csv
|
146
|
+
- spec/fixtures/events.json
|
145
147
|
- spec/keen-cli/cli_spec.rb
|
146
148
|
- spec/spec_helper.rb
|
147
149
|
homepage: https://github.com/keenlabs/keen-cli
|
@@ -170,6 +172,8 @@ signing_key:
|
|
170
172
|
specification_version: 3
|
171
173
|
summary: Command line interface to Keen IO
|
172
174
|
test_files:
|
175
|
+
- spec/fixtures/events.csv
|
176
|
+
- spec/fixtures/events.json
|
173
177
|
- spec/keen-cli/cli_spec.rb
|
174
178
|
- spec/spec_helper.rb
|
175
179
|
has_rdoc:
|