keen 1.1.0 → 1.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 065f80ef6be231a709d26afe30ae76a8a1138812
4
- data.tar.gz: d6a07538cff945becfa38fc12015f1e0244d9032
3
+ metadata.gz: c47eef1b0e54dae99c1ea8b602cf656cd42802db
4
+ data.tar.gz: 34f117595df684a9634475892330fff3d22ac7e8
5
5
  SHA512:
6
- metadata.gz: 40e792c1cd92e85b901b365ad3f27a146e964094cb25475a252b36f903760eb319055d620eb2ceee371ccb7fbb3bc7bfddb306c0b871b07b50d96e741f2f4a5e
7
- data.tar.gz: 5b65635514c0be2d55107f3d1aa3a532a2d502f3b9599817daa691e9adcfb6f1e3ff8505e9ad74b6ee2d296fef8f099e4a67080e7717a0a0dbb577c602d44201
6
+ metadata.gz: 161ab7ad63b06647a52afe0714564cd53cc03ee720f28e3916cca4b7703b2c39ef1b48fc87ba596655795f93c6beb72e89ba0239f9045757727c9f388b59be86
7
+ data.tar.gz: 5d7bc3a97aedc1b508bda127b133e191088f5cc1b369fe21f0310da92fae78164410396621626abbf66bd356a9e7cd14eb89dc6f07ea1b2ac09c2c668cfaa2a6
data/README.md CHANGED
@@ -175,6 +175,16 @@ Each query method or alias takes an optional hash of options as an additional pa
175
175
  `:response` – Set to `:all_keys` to return the full API response (usually only the value of the `"result"` key is returned).
176
176
  `:method` - Set to `:post` to enable post body based query (https://keen.io/docs/data-analysis/post-queries/).
177
177
 
178
+ ##### Query Logging
179
+
180
+ You can log all GET and POST queries automatically by setting the `log_queries` option.
181
+
182
+ ``` ruby
183
+ Keen.log_queries = true
184
+ Keen.count('purchases')
185
+ # I, [2016-10-30T11:45:24.678745 #9978] INFO -- : [KEEN] Send GET query to https://api.keen.io/3.0/projects/<YOUR_PROJECT_ID>/queries/count?event_collection=purchases with options {}
186
+ ```
187
+
178
188
  ### Saved Queries
179
189
 
180
190
  You can manage your saved queries from the Keen ruby client.
@@ -447,6 +457,10 @@ If you want some bot protection, check out the [Voight-Kampff](https://github.co
447
457
 
448
458
  ### Changelog
449
459
 
460
+ ##### 1.1.1
461
+ + Added an option to log queries
462
+ + Added a cli option that includes the Keen code
463
+
450
464
  ##### 1.1.0
451
465
  + Add support for access keys
452
466
  + Move saved queries into the Keen namespace
@@ -602,10 +616,21 @@ Similarly, you can use guard to listen for changes to files and run specs.
602
616
 
603
617
  `bundle exec guard -g synchrony`
604
618
 
619
+ #### Running a Local Console
620
+
621
+ You can spawn an `irb` session with the local files already loaded for debugging
622
+ or experimentation.
623
+
624
+ ```
625
+ $ bundle exec rake console
626
+ 2.2.6 :001 > Keen
627
+ => Keen
628
+ ```
605
629
  ### Community Contributors
606
630
  + [alexkwolfe](https://github.com/alexkwolfe)
607
631
  + [peteygao](https://github.com/peteygao)
608
632
  + [obieq](https://github.com/obieq)
609
633
  + [cbartlett](https://github.com/cbartlett)
634
+ + [myrridin](https://github.com/myrridin)
610
635
 
611
636
  Thanks everyone, you rock!
data/Rakefile CHANGED
@@ -21,5 +21,10 @@ RSpec::Core::RakeTask.new(:pattern) do |t|
21
21
  t.pattern = "spec/#{ENV['PATTERN']}/**/*_spec.rb"
22
22
  end
23
23
 
24
+ desc "Start a development console with local code loaded"
25
+ task :console do
26
+ exec "irb -r keen -I ./lib"
27
+ end
28
+
24
29
  task :default => :spec
25
30
  task :test => [:spec]
@@ -33,7 +33,8 @@ module Keen
33
33
  :write_key, :write_key=,
34
34
  :read_key, :read_key=,
35
35
  :master_key, :master_key=,
36
- :api_url, :api_url=
36
+ :api_url, :api_url=,
37
+ :log_queries, :log_queries=
37
38
 
38
39
  def_delegators :default_client,
39
40
  :proxy_url, :proxy_url=,
@@ -16,7 +16,7 @@ module Keen
16
16
  include Keen::Client::QueryingMethods
17
17
  include Keen::Client::MaintenanceMethods
18
18
 
19
- attr_accessor :project_id, :write_key, :read_key, :master_key, :api_url, :proxy_url, :proxy_type, :read_timeout, :open_timeout
19
+ attr_accessor :project_id, :write_key, :read_key, :master_key, :api_url, :proxy_url, :proxy_type, :read_timeout, :log_queries, :open_timeout
20
20
 
21
21
  CONFIG = {
22
22
  :api_url => "https://api.keen.io",
@@ -240,6 +240,8 @@ module Keen
240
240
  ensure_project_id!
241
241
  ensure_read_key!
242
242
 
243
+ log_query("#{self.api_url}#{api_query_resource_path(analysis_type)}", 'POST', params) if log_queries
244
+
243
245
  query_params = params.dup
244
246
  query_params[:event_collection] = event_collection.to_s if event_collection
245
247
  Keen::HTTP::Sync.new(self.api_url, self.proxy_url, self.read_timeout, self.open_timeout).post(
@@ -261,6 +263,7 @@ module Keen
261
263
  end
262
264
 
263
265
  def get_response(url, options={})
266
+ log_query(url) if log_queries
264
267
  uri = URI.parse(url)
265
268
  Keen::HTTP::Sync.new(self.api_url, self.proxy_url, self.read_timeout, self.open_timeout).get(
266
269
  :path => "#{uri.path}?#{uri.query}",
@@ -274,6 +277,10 @@ module Keen
274
277
  "/#{self.api_version}/projects/#{self.project_id}/queries/#{analysis_type}"
275
278
  end
276
279
 
280
+ def log_query(url, method='GET', options={})
281
+ Keen.logger.info { "[KEEN] Send #{method} query to #{url} with options #{options}" }
282
+ end
283
+
277
284
  def request_headers(options={})
278
285
  base_headers = api_headers(self.read_key, "sync")
279
286
  options.has_key?(:headers) ? base_headers.merge(options[:headers]) : base_headers
@@ -1,3 +1,3 @@
1
1
  module Keen
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -148,17 +148,45 @@ describe Keen::Client do
148
148
  expect(api_response).to eq({ "result" => [1] })
149
149
  end
150
150
 
151
- it "should call API with post body if method opton is set to post " do
152
- steps = [{
153
- :event_collection => "sign ups",
154
- :actor_property => "user.id"
155
- }]
156
- expected_url = query_url("funnel")
157
- stub_keen_post(expected_url, 200, :result => 1)
158
- response = query.call("funnel", nil, { :steps => steps }, { :method => :post })
151
+ context "if log_queries is true" do
152
+ before(:each) { client.log_queries = true }
159
153
 
160
- expect_keen_post(expected_url, { :steps => steps }, "sync", read_key)
161
- expect(response).to eq(api_response["result"])
154
+ it "logs the query" do
155
+ expect(client).to receive(:log_query).with(query_url("count", "?event_collection=users"))
156
+ test_query
157
+ end
158
+
159
+ after(:each) { client.log_queries = false }
160
+ end
161
+
162
+ context "if method option is set to post" do
163
+ let(:steps) do
164
+ [{
165
+ :event_collection => "sign ups",
166
+ :actor_property => "user.id"
167
+ }]
168
+ end
169
+ let(:expected_url) { query_url("funnel") }
170
+ before(:each) { stub_keen_post(expected_url, 200, :result => 1) }
171
+
172
+ it "should call API with post body" do
173
+ response = query.call("funnel", nil, { :steps => steps }, { :method => :post })
174
+
175
+ expect_keen_post(expected_url, { :steps => steps }, "sync", read_key)
176
+ expect(response).to eq(api_response["result"])
177
+ end
178
+
179
+ context "if log_queries is true" do
180
+ before(:each) { client.log_queries = true }
181
+
182
+ it "logs the query" do
183
+ expected_params = {:steps=>[{:event_collection=>"sign ups", :actor_property=>"user.id"}]}
184
+ expect(client).to receive(:log_query).with(expected_url, 'POST', expected_params)
185
+ query.call("funnel", nil, { :steps => steps }, { :method => :post })
186
+ end
187
+
188
+ after(:each) { client.log_queries = false }
189
+ end
162
190
  end
163
191
 
164
192
  it "should add extra headers if you supply them as an option" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Kleissner
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-15 00:00:00.000000000 Z
12
+ date: 2017-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json