Class: KeenCli::CLI
- Inherits:
-
Thor
- Object
- Thor
- KeenCli::CLI
- Defined in:
- lib/keen-cli/cli.rb,
lib/keen-cli/events.rb,
lib/keen-cli/shared.rb,
lib/keen-cli/queries.rb,
lib/keen-cli/projects.rb,
lib/keen-cli/collections.rb
Constant Summary collapse
- ANALYSIS_TYPES =
%w(average count count-unique extraction median minimum maximum sum percentile select-unique)
Class Method Summary collapse
- .collection_options ⇒ Object
- .data_options ⇒ Object
- .delete_options ⇒ Object
- .events_options ⇒ Object
- .file_options ⇒ Object
- .query_options ⇒ Object
- .shared_options ⇒ Object
- .viz_options ⇒ Object
Instance Method Summary collapse
- #collections_delete ⇒ Object
- #docs ⇒ Object
- #events_add ⇒ Object
- #projects_collections ⇒ Object
- #projects_describe ⇒ Object
- #projects_open ⇒ Object
- #projects_workbench ⇒ Object
- #queries_run(analysis_type = nil) ⇒ Object
- #queries_url ⇒ Object
- #version ⇒ Object
Class Method Details
.collection_options ⇒ Object
14 15 16 |
# File 'lib/keen-cli/shared.rb', line 14 def self. option :collection, :aliases => ['-c'] end |
.data_options ⇒ Object
18 19 20 |
# File 'lib/keen-cli/shared.rb', line 18 def self. option :data, :aliases => ['-d'] end |
.delete_options ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/keen-cli/collections.rb', line 5 def self. self. option :timeframe, :aliases => ['-t'] option :filters, :aliases => ['-f'] option :start, :aliases => ['s'] option :end, :aliases => ['e'] option :force, :type => :boolean, :default => false end |
.events_options ⇒ Object
7 8 9 10 11 |
# File 'lib/keen-cli/events.rb', line 7 def self. option :csv option :params option :'batch-size', type: :numeric end |
.file_options ⇒ Object
22 23 24 |
# File 'lib/keen-cli/shared.rb', line 22 def self. option :file, :aliases => ['-f'] end |
.query_options ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/keen-cli/queries.rb', line 5 def self. self. option :"analysis-type", :aliases => ['-a'] option :"group-by", :aliases => ['-g'] option :"target-property", :aliases => ['-y'] option :interval, :aliases => ['-i'] option :timeframe, :aliases => ['-t'] option :filters, :aliases => ['-f'] option :percentile option :"property-names" option :latest option :email option :start, :aliases => ['s'] option :end, :aliases => ['e'] end |
.shared_options ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/keen-cli/shared.rb', line 5 def self. option :project, :aliases => ['-p'] option :"master-key", :aliases => ['-k'] option :"read-key", :aliases => ['-r'] option :"write-key", :aliases => ['-w'] option :pretty, :type => :boolean, :default => true option :silent, :type => :boolean, :default => false end |
.viz_options ⇒ Object
21 22 23 |
# File 'lib/keen-cli/queries.rb', line 21 def self. option :"spark", :type => :boolean end |
Instance Method Details
#collections_delete ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/keen-cli/collections.rb', line 20 def collections_delete Utils.() collection = Utils.get_collection_name() unless [:force] puts "WARNING! This is a delete request. Please re-enter the collection name to confirm." confirmation = $stdin.gets.chomp! unless confirmation == collection Utils.out "Confirmation failed!", return false end end = {} [:timeframe] = [:timeframe] if start_time = [:start] [:timeframe] = { :start => start_time } end if filters = [:filters] [:filters] = JSON.parse(filters) end if end_time = [:end] [:timeframe] = [:timeframe] || {} [:timeframe][:end] = end_time end .delete_if { |k, v| v.nil? } Keen.delete(collection, ).tap do |result| Utils.out(result, ) end end |
#docs ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/keen-cli/cli.rb', line 36 def docs docs_url = [:reference] ? 'https://keen.io/docs/api/reference/' : 'https://keen.io/docs' docs_url.tap do |url| `open #{url}` end end |
#events_add ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/keen-cli/events.rb', line 22 def events_add Utils.() collection = Utils.get_collection_name() batch_processor = BatchProcessor.new(collection, :csv => [:csv], :params => [:params], :pretty => [:pretty], :silent => [:silent], :'batch-size' => [:'batch-size']) if data = [:data] batch_processor.add(data) end if file = [:file] File.readlines(file).each do |line| batch_processor.add(line) end end if !$stdin.tty? ARGV.clear ARGF.each_line do |line| batch_processor.add(line) end end if $stdin.tty? && data.nil? && file.nil? batch_processor.add("{}") end batch_processor.flush batch_processor.total_size end |
#projects_collections ⇒ Object
20 21 22 23 24 25 |
# File 'lib/keen-cli/projects.rb', line 20 def projects_collections Utils.() Keen.event_collections.tap do |collections| Utils.out_json(collections, ) end end |
#projects_describe ⇒ Object
9 10 11 12 13 14 |
# File 'lib/keen-cli/projects.rb', line 9 def projects_describe Utils.() Keen.project_info.tap do |info| Utils.out_json(info, ) end end |
#projects_open ⇒ Object
31 32 33 34 35 36 |
# File 'lib/keen-cli/projects.rb', line 31 def projects_open Utils.() "https://keen.io/project/#{Keen.project_id}".tap do |projects_url| `open #{projects_url}` end end |
#projects_workbench ⇒ Object
42 43 44 45 46 47 |
# File 'lib/keen-cli/projects.rb', line 42 def projects_workbench Utils.() "https://keen.io/project/#{Keen.project_id}/workbench".tap do |project_url| `open #{project_url}` end end |
#queries_run(analysis_type = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/keen-cli/queries.rb', line 31 def queries_run(analysis_type=nil) Utils.() collection = Utils.get_collection_name() raise "No collection given!" unless collection analysis_type = analysis_type || [:"analysis-type"] raise "No analysis type given!" unless analysis_type = () result = Keen.query(analysis_type, collection, , :response => :all_keys) if ([:spark]) raise 'Spark only applies to series queries!' unless [:interval] numbers = result["result"].map do |object| object['value'] end return numbers.join(' ').tap do |numbers_str| Utils.out(numbers_str, ) end end if result.is_a?(Hash) || result.is_a?(Array) Utils.out_json(result, ) else Utils.out(result, ) end result end |
#queries_url ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/keen-cli/queries.rb', line 71 def queries_url Utils.() collection = Utils.get_collection_name() raise "No collection given!" unless collection analysis_type = [:"analysis-type"] raise "No analysis type given!" unless analysis_type = () Keen.query_url(analysis_type, collection, , { :exclude_api_key => [:'exclude-api-key']}).tap do |url| Utils.out(url, ) end end |