keen-cli 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,6 +19,7 @@ Verify the `keen` command is in your path by running it:
19
19
  ``` shell
20
20
  Commands:
21
21
  keen average # Alias for queries:run -a average
22
+ keen collections:delete # Delete events from a collection
22
23
  keen count # Alias for queries:run -a count
23
24
  keen count-unique # Alias for queries:run -a count_unique
24
25
  keen docs # Open the full Keen IO documentation in a browser
@@ -93,6 +94,10 @@ keen-cli has a variety of commands, and most are namespaced for clarity.
93
94
  * `projects:describe` - Get data about the project. Uses the [project row resource](https://keen.io/docs/api/reference/#project-row-resource).
94
95
  * `projects:collections` - Get schema information about the project's collections. Uses the [event resource](https://keen.io/docs/api/reference/#event-resource).
95
96
 
97
+ ##### Collections
98
+
99
+ * `collections:delete` - Delete a collection. Takes filters and timeframe as options. Requires confirmation. Pass `--force` to skip, but BE CAREFUL :)
100
+
96
101
  ##### Events
97
102
 
98
103
  `events:add` - Add an event.
@@ -173,7 +178,7 @@ Parameters:
173
178
  + `--property-names`: A comma-separated list of property names. Extractions only.
174
179
  + `--latest`: Number of latest events to retrieve. Extractions only.
175
180
  + `--email`: Send extraction results via email, asynchronously. Extractions only.
176
- + `--spark`: Format output for [spark](https://github.com/holman/spark) ▁▂▃▅▇ Interval and timeframe fields required.
181
+ + `--spark`: Format output for [spark](https://github.com/holman/spark) ▁▂▃▅▇. Interval and timeframe fields required. Set this flag and pipe output to `spark` to visualize output.
177
182
 
178
183
  Input source parameters:
179
184
  + `--data`, `-d`: Specify query parameters as JSON instead of query params.
@@ -267,6 +272,7 @@ Parameters that apply to most commands include:
267
272
 
268
273
  ### Changelog
269
274
 
275
+ + 0.2.1 - Add `collections:delete` command
270
276
  + 0.2.0 - Add support for [spark](https://github.com/holman/spark) ▁▂▃▅▇
271
277
  + 0.1.9 - Supports JSON-encoded filters and comma-seperated multiple group by
272
278
  + 0.1.8 - Inputted lines can also be arrays of JSON objects. `--batch-size` param is now properly recognized.
data/lib/keen-cli/cli.rb CHANGED
@@ -8,6 +8,7 @@ require 'keen-cli/utils'
8
8
  require 'keen-cli/shared'
9
9
 
10
10
  require 'keen-cli/projects'
11
+ require 'keen-cli/collections'
11
12
  require 'keen-cli/events'
12
13
  require 'keen-cli/queries'
13
14
 
@@ -0,0 +1,61 @@
1
+ module KeenCli
2
+
3
+ class CLI < Thor
4
+
5
+ def self.delete_options
6
+ self.collection_options
7
+ option :timeframe, :aliases => ['-t']
8
+ option :filters, :aliases => ['-f']
9
+ option :start, :aliases => ['s']
10
+ option :end, :aliases => ['e']
11
+ option :force, :type => :boolean, :default => false
12
+ end
13
+
14
+ desc 'collections:delete', 'Delete events from a collection'
15
+ map 'collections:delete' => :collections_delete
16
+
17
+ shared_options
18
+ delete_options
19
+
20
+ def collections_delete
21
+
22
+ Utils.process_options!(options)
23
+
24
+ collection = Utils.get_collection_name(options)
25
+
26
+ unless options[:force]
27
+ puts "WARNING! This is a delete request. Please re-enter the collection name to confirm."
28
+ confirmation = $stdin.gets.chomp!
29
+ unless confirmation == collection
30
+ Utils.out "Confirmation failed!", options
31
+ return false
32
+ end
33
+ end
34
+
35
+ q_options = {}
36
+ q_options[:timeframe] = options[:timeframe]
37
+
38
+ if start_time = options[:start]
39
+ q_options[:timeframe] = { :start => start_time }
40
+ end
41
+
42
+ if filters = options[:filters]
43
+ q_options[:filters] = JSON.parse(filters)
44
+ end
45
+
46
+ if end_time = options[:end]
47
+ q_options[:timeframe] = q_options[:timeframe] || {}
48
+ q_options[:timeframe][:end] = end_time
49
+ end
50
+
51
+ q_options.delete_if { |k, v| v.nil? }
52
+
53
+ Keen.delete(collection, q_options).tap do |result|
54
+ Utils.out(result, options)
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -1,3 +1,3 @@
1
1
  module KeenCli
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe KeenCli::CLI do
4
+
5
+ describe 'collections:delete' do
6
+
7
+ it 'deletes the collection' do
8
+ stub_request(:delete, "https://api.keen.io/3.0/projects/#{Keen.project_id}/events/minecraft-deaths").
9
+ to_return(:status => 204, :body => "")
10
+ _, options = start 'collections:delete --collection minecraft-deaths --force'
11
+ expect(_).to eq(true)
12
+ end
13
+
14
+ it 'deletes the collection with filters' do
15
+ filters = '[{"property_name":"enemy","operator":"eq","property_value":"creeper"}]'
16
+ stub_request(:delete, "https://api.keen.io/3.0/projects/#{Keen.project_id}/events/minecraft-deaths?filters=%5B%7B%22property_name%22%3A%22enemy%22%2C%22operator%22%3A%22eq%22%2C%22property_value%22%3A%22creeper%22%7D%5D").
17
+ to_return(:status => 204, :body => "")
18
+ _, options = start "collections:delete --collection minecraft-deaths --filters #{filters} --force"
19
+ expect(_).to eq(true)
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -106,13 +106,21 @@ describe KeenCli::CLI do
106
106
 
107
107
  describe 'spark format' do
108
108
 
109
- it 'should emit interval results as numbers' do
109
+ it 'emits interval results as numbers' do
110
110
  url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&timeframe=last_2_minutes&interval=minutely"
111
111
  stub_request(:get, url).to_return(:body => { :result => [{ value: 10 }, { value: 20 }] }.to_json)
112
112
  _ = start 'queries:run --collection minecraft-deaths --analysis-type count --timeframe last_2_minutes --interval minutely --spark'
113
113
  expect(_).to eq("10 20")
114
114
  end
115
115
 
116
+ it 'raises an exception if the query does not have an interval' do
117
+ url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&timeframe=last_2_minutes"
118
+ stub_request(:get, url).to_return(:body => { :result => [{ value: 10 }, { value: 20 }] }.to_json)
119
+ expect {
120
+ _ = start 'queries:run --collection minecraft-deaths --analysis-type count --timeframe last_2_minutes --spark'
121
+ }.to raise_error /Spark only applies to series/
122
+ end
123
+
116
124
  end
117
125
 
118
126
  describe "queries:run aliases" do
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.0
4
+ version: 0.2.1
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-19 00:00:00.000000000 Z
12
+ date: 2014-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: keen
@@ -141,6 +141,7 @@ files:
141
141
  - lib/keen-cli.rb
142
142
  - lib/keen-cli/batch_processor.rb
143
143
  - lib/keen-cli/cli.rb
144
+ - lib/keen-cli/collections.rb
144
145
  - lib/keen-cli/events.rb
145
146
  - lib/keen-cli/projects.rb
146
147
  - lib/keen-cli/queries.rb
@@ -152,6 +153,7 @@ files:
152
153
  - spec/fixtures/events.json
153
154
  - spec/keen-cli/batch_processor_spec.rb
154
155
  - spec/keen-cli/cli_spec.rb
156
+ - spec/keen-cli/collections_spec.rb
155
157
  - spec/keen-cli/events_spec.rb
156
158
  - spec/keen-cli/projects_spec.rb
157
159
  - spec/keen-cli/queries_spec.rb
@@ -187,6 +189,7 @@ test_files:
187
189
  - spec/fixtures/events.json
188
190
  - spec/keen-cli/batch_processor_spec.rb
189
191
  - spec/keen-cli/cli_spec.rb
192
+ - spec/keen-cli/collections_spec.rb
190
193
  - spec/keen-cli/events_spec.rb
191
194
  - spec/keen-cli/projects_spec.rb
192
195
  - spec/keen-cli/queries_spec.rb