Class: KeenCli::CLI
- Inherits:
-
Thor
- Object
- Thor
- KeenCli::CLI
- Defined in:
- lib/keen-cli/cli.rb
Class Method Summary collapse
- .collection_options ⇒ Object
- .data_options ⇒ Object
- .query_options ⇒ Object
- .shared_options ⇒ Object
Instance Method Summary collapse
- #events_add ⇒ Object
- #project_collections ⇒ Object
- #project_open ⇒ Object
- #project_show ⇒ Object
- #project_workbench ⇒ Object
- #queries_run ⇒ Object
- #version ⇒ Object
Class Method Details
.collection_options ⇒ Object
23 24 25 |
# File 'lib/keen-cli/cli.rb', line 23 def self. option :collection, :aliases => ['-c'] end |
.data_options ⇒ Object
19 20 21 |
# File 'lib/keen-cli/cli.rb', line 19 def self. option :data, :aliases => ['-d'] end |
.query_options ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/keen-cli/cli.rb', line 27 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 end |
.shared_options ⇒ Object
12 13 14 15 16 17 |
# File 'lib/keen-cli/cli.rb', line 12 def self. option :project, :aliases => ['-p'] option :"master-key", :aliases => ['-k'] option :"read-key", :aliases => ['-r'] option :"write-key", :aliases => ['-w'] end |
Instance Method Details
#events_add ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/keen-cli/cli.rb', line 127 def events_add events = [] if $stdin.tty? events.push([:data] || {}) else ARGV.clear ARGF.each_line do |line| events.push(line) end end events = events.map do |event| begin JSON.parse(event) rescue begin Utils.parse_data_as_querystring(event) rescue event end end end collection = Utils.get_collection_name() if events.length > 1 Keen.publish_batch(collection => events).tap do |result| puts JSON.pretty_generate(result) end else Keen.publish(collection, events.first).tap do |result| puts JSON.pretty_generate(result) end end end |
#project_collections ⇒ Object
62 63 64 65 66 67 |
# File 'lib/keen-cli/cli.rb', line 62 def project_collections Utils.() Keen.event_collections.tap do |collections| puts JSON.pretty_generate(collections) end end |
#project_open ⇒ Object
73 74 75 76 77 78 |
# File 'lib/keen-cli/cli.rb', line 73 def project_open Utils.() "https://keen.io/project/#{Keen.project_id}".tap do |project_url| `open #{project_url}` end end |
#project_show ⇒ Object
51 52 53 54 55 56 |
# File 'lib/keen-cli/cli.rb', line 51 def project_show Utils.() response = HTTP.get( "https://api.keen.io/3.0/projects/#{Keen.project_id}?api_key=#{Keen.master_key}") JSON.pretty_generate(JSON.parse(response.to_s)).tap do |s| puts s end end |
#project_workbench ⇒ Object
84 85 86 87 88 89 |
# File 'lib/keen-cli/cli.rb', line 84 def project_workbench Utils.() "https://keen.io/project/#{Keen.project_id}/workbench".tap do |project_url| `open #{project_url}` end end |
#queries_run ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/keen-cli/cli.rb', line 95 def queries_run Utils.() # convert dashes = .inject({}) do |memo, element| if ['analysis-type', 'group-by', 'target-property'].include?(element.first) memo[element.first.sub('-', '_')] = element.last else memo[element.first] = element.last end memo end collection = Utils.get_collection_name() Keen.send(["analysis_type"], collection, ).tap do |result| if result.is_a?(Hash) || result.is_a?(Array) puts JSON.pretty_generate(result) else puts result end end end |