keen 0.8.8 → 0.8.9
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 +24 -7
 - data/lib/keen/http.rb +1 -1
 - data/lib/keen/scoped_key.rb +1 -2
 - data/lib/keen/version.rb +1 -1
 - data/spec/keen/client/publishing_methods_spec.rb +16 -0
 - metadata +2 -2
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -113,6 +113,7 @@ Running queries requires that `KEEN_READ_KEY` is set. 
     | 
|
| 
       113 
113 
     | 
    
         
             
            Here are some examples of querying with keen-gem. Let's assume you've added some events to the "purchases" collection.
         
     | 
| 
       114 
114 
     | 
    
         | 
| 
       115 
115 
     | 
    
         
             
            ```ruby
         
     | 
| 
      
 116 
     | 
    
         
            +
            # Various analysis types
         
     | 
| 
       116 
117 
     | 
    
         
             
            Keen.count("purchases") # => 100
         
     | 
| 
       117 
118 
     | 
    
         
             
            Keen.sum("purchases", :target_property => "price")  # => 10000
         
     | 
| 
       118 
119 
     | 
    
         
             
            Keen.minimum("purchases", :target_property => "price")  # => 20
         
     | 
| 
         @@ -120,23 +121,35 @@ Keen.maximum("purchases", :target_property => "price")  # => 100 
     | 
|
| 
       120 
121 
     | 
    
         
             
            Keen.average("purchases", :target_property => "price")  # => 60
         
     | 
| 
       121 
122 
     | 
    
         
             
            Keen.median("purchases", :target_property => "price")  # => 60
         
     | 
| 
       122 
123 
     | 
    
         
             
            Keen.percentile("purchases", :target_property => "price", :percentile => 90)  # => 100
         
     | 
| 
      
 124 
     | 
    
         
            +
            Keen.count_unique("purchases", :target_property => "username")  # => 3
         
     | 
| 
      
 125 
     | 
    
         
            +
            Keen.select_unique("purchases", :target_property => "username")  # => ["Bob", "Linda", "Travis"]
         
     | 
| 
       123 
126 
     | 
    
         | 
| 
      
 127 
     | 
    
         
            +
            # Group by's and filters
         
     | 
| 
       124 
128 
     | 
    
         
             
            Keen.sum("purchases", :target_property => "price", :group_by => "item.id")  # => [{ "item.id": 123, "result": 240 }]
         
     | 
| 
       125 
129 
     | 
    
         
             
            Keen.count("purchases", :timeframe => "today", :filters => [{
         
     | 
| 
       126 
130 
     | 
    
         
             
                "property_name" => "referred_by",
         
     | 
| 
       127 
131 
     | 
    
         
             
                "operator" => "eq",
         
     | 
| 
       128 
132 
     | 
    
         
             
                "property_value" => "harry"
         
     | 
| 
       129 
133 
     | 
    
         
             
              }]) # => 2
         
     | 
| 
      
 134 
     | 
    
         
            +
              
         
     | 
| 
      
 135 
     | 
    
         
            +
            # Relative timeframes
         
     | 
| 
      
 136 
     | 
    
         
            +
            Keen.count("purchases", :timeframe => "today") # => 10
         
     | 
| 
       130 
137 
     | 
    
         | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
            Keen. 
     | 
| 
      
 138 
     | 
    
         
            +
            # Absolute timeframes
         
     | 
| 
      
 139 
     | 
    
         
            +
            Keen.count("purchases", :timeframe => { 
         
     | 
| 
      
 140 
     | 
    
         
            +
              :start => "2015-01-01T00:00:00Z", 
         
     | 
| 
      
 141 
     | 
    
         
            +
              :end => "2015-31-01T00:00:00Z" 
         
     | 
| 
      
 142 
     | 
    
         
            +
            }) # => 5
         
     | 
| 
       133 
143 
     | 
    
         | 
| 
      
 144 
     | 
    
         
            +
            # Extractions
         
     | 
| 
       134 
145 
     | 
    
         
             
            Keen.extraction("purchases")  # => [{ "keen" => { "timestamp" => "2014-01-01T00:00:00Z" }, "price" => 20 }]
         
     | 
| 
       135 
146 
     | 
    
         | 
| 
      
 147 
     | 
    
         
            +
            # Funnels
         
     | 
| 
       136 
148 
     | 
    
         
             
            Keen.funnel(:steps => [{ 
         
     | 
| 
       137 
149 
     | 
    
         
             
              :actor_property => "username", :event_collection => "purchases" }, {
         
     | 
| 
       138 
150 
     | 
    
         
             
              :actor_property => "username", :event_collection => "referrals" }]) # => [20, 15]
         
     | 
| 
       139 
151 
     | 
    
         | 
| 
      
 152 
     | 
    
         
            +
            # Multi-analysis
         
     | 
| 
       140 
153 
     | 
    
         
             
            Keen.multi_analysis("purchases", analyses: {
         
     | 
| 
       141 
154 
     | 
    
         
             
              :gross =>      { :analysis_type => "sum", :target_property => "price" },
         
     | 
| 
       142 
155 
     | 
    
         
             
              :customers =>  { :analysis_type => "count_unique", :target_property => "username" } },
         
     | 
| 
         @@ -270,7 +283,6 @@ Keen.project_id = 'xxxxxxxxxxxxxxx' 
     | 
|
| 
       270 
283 
     | 
    
         
             
            Keen.write_key = 'yyyyyyyyyyyyyyy'
         
     | 
| 
       271 
284 
     | 
    
         
             
            Keen.read_key = 'zzzzzzzzzzzzzzz'
         
     | 
| 
       272 
285 
     | 
    
         
             
            Keen.master_key = 'aaaaaaaaaaaaaaa'
         
     | 
| 
       273 
     | 
    
         
            -
            Keen.read_timeoout = 60
         
     | 
| 
       274 
286 
     | 
    
         
             
            ```
         
     | 
| 
       275 
287 
     | 
    
         | 
| 
       276 
288 
     | 
    
         
             
            You can also configure unique client instances as follows:
         
     | 
| 
         @@ -279,8 +291,7 @@ You can also configure unique client instances as follows: 
     | 
|
| 
       279 
291 
     | 
    
         
             
            keen = Keen::Client.new(:project_id => 'xxxxxxxxxxxxxxx',
         
     | 
| 
       280 
292 
     | 
    
         
             
                                    :write_key  => 'yyyyyyyyyyyyyyy',
         
     | 
| 
       281 
293 
     | 
    
         
             
                                    :read_key   => 'zzzzzzzzzzzzzzz',
         
     | 
| 
       282 
     | 
    
         
            -
                                    :master_key => 'aaaaaaaaaaaaaaa' 
     | 
| 
       283 
     | 
    
         
            -
                                    :read_timeout => 60)
         
     | 
| 
      
 294 
     | 
    
         
            +
                                    :master_key => 'aaaaaaaaaaaaaaa')
         
     | 
| 
       284 
295 
     | 
    
         
             
            ```
         
     | 
| 
       285 
296 
     | 
    
         | 
| 
       286 
297 
     | 
    
         
             
            #### em-synchrony
         
     | 
| 
         @@ -340,14 +351,17 @@ You can use the scoped key created in Ruby for API requests from any client. Sco 
     | 
|
| 
       340 
351 
     | 
    
         | 
| 
       341 
352 
     | 
    
         
             
            The default `Net:HTTP` timeout is 60 seconds. That's usually enough, but if you're querying over a large collection you may need to increase it. The timeout on the API side is 300 seconds, so that's as far as you'd want to go. You can configure a read timeout (in seconds) by setting a `KEEN_READ_TIMEOUT` environment variable, or by passing in a `read_timeout` option to the client constructor as follows:
         
     | 
| 
       342 
353 
     | 
    
         | 
| 
       343 
     | 
    
         
            -
            ```
         
     | 
| 
      
 354 
     | 
    
         
            +
            ``` ruby
         
     | 
| 
       344 
355 
     | 
    
         
             
            keen = Keen::Client.new(:read_timeout => 300)
         
     | 
| 
       345 
356 
     | 
    
         
             
            ```
         
     | 
| 
       346 
357 
     | 
    
         | 
| 
       347 
358 
     | 
    
         
             
            ##### HTTP Proxy
         
     | 
| 
       348 
359 
     | 
    
         | 
| 
       349 
     | 
    
         
            -
            You can set the `KEEN_PROXY_TYPE` and `KEEN_PROXY_URL` environment variables to enable HTTP proxying. `KEEN_PROXY_TYPE` should  
     | 
| 
      
 360 
     | 
    
         
            +
            You can set the `KEEN_PROXY_TYPE` and `KEEN_PROXY_URL` environment variables to enable HTTP proxying. `KEEN_PROXY_TYPE` should be set to `socks5`. You can also configure this on client instances by passing in `proxy_type` and `proxy_url` keys.
         
     | 
| 
       350 
361 
     | 
    
         | 
| 
      
 362 
     | 
    
         
            +
            ``` ruby
         
     | 
| 
      
 363 
     | 
    
         
            +
            keen = Keen::Client.new(:proxy_type => 'socks5', :proxy_url => 'http://localhost:8888')
         
     | 
| 
      
 364 
     | 
    
         
            +
            ```
         
     | 
| 
       351 
365 
     | 
    
         | 
| 
       352 
366 
     | 
    
         
             
            ### Troubleshooting
         
     | 
| 
       353 
367 
     | 
    
         | 
| 
         @@ -364,6 +378,9 @@ EventMachine itself won't do this because it runs in a different thread. Here's 
     | 
|
| 
       364 
378 
     | 
    
         | 
| 
       365 
379 
     | 
    
         
             
            ### Changelog
         
     | 
| 
       366 
380 
     | 
    
         | 
| 
      
 381 
     | 
    
         
            +
            ##### 0.8.9
         
     | 
| 
      
 382 
     | 
    
         
            +
            + Fix proxy support for sync client. Thanks [@nvieirafelipe](https://github.com/nvieirafelipe)!
         
     | 
| 
      
 383 
     | 
    
         
            +
             
     | 
| 
       367 
384 
     | 
    
         
             
            ##### 0.8.8
         
     | 
| 
       368 
385 
     | 
    
         
             
            + Add support for a configurable read timeout
         
     | 
| 
       369 
386 
     | 
    
         | 
    
        data/lib/keen/http.rb
    CHANGED
    
    
    
        data/lib/keen/scoped_key.rb
    CHANGED
    
    | 
         @@ -27,9 +27,8 @@ module Keen 
     | 
|
| 
       27 
27 
     | 
    
         
             
                def encrypt!
         
     | 
| 
       28 
28 
     | 
    
         
             
                  json_str = MultiJson.dump(self.data)
         
     | 
| 
       29 
29 
     | 
    
         
             
                  padded_api_key = pad(self.api_key)
         
     | 
| 
       30 
     | 
    
         
            -
                  padded_data = pad(json_str)
         
     | 
| 
       31 
30 
     | 
    
         
             
                  encrypted, iv = aes256_encrypt(padded_api_key, json_str)
         
     | 
| 
       32 
31 
     | 
    
         
             
                  hexlify(iv) + hexlify(encrypted)
         
     | 
| 
       33 
32 
     | 
    
         
             
                end
         
     | 
| 
       34 
33 
     | 
    
         
             
              end
         
     | 
| 
       35 
     | 
    
         
            -
            end
         
     | 
| 
      
 34 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/keen/version.rb
    CHANGED
    
    
| 
         @@ -71,6 +71,22 @@ describe Keen::Client::PublishingMethods do 
     | 
|
| 
       71 
71 
     | 
    
         
             
                    ).publish(collection, event_properties)
         
     | 
| 
       72 
72 
     | 
    
         
             
                  }.to raise_error(Keen::ConfigurationError, "Keen IO Exception: Write Key must be set for this operation")
         
     | 
| 
       73 
73 
     | 
    
         
             
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                context "when using proxy" do
         
     | 
| 
      
 76 
     | 
    
         
            +
                  let(:client) do
         
     | 
| 
      
 77 
     | 
    
         
            +
                    Keen::Client.new(:project_id => project_id,
         
     | 
| 
      
 78 
     | 
    
         
            +
                                     :write_key => write_key,
         
     | 
| 
      
 79 
     | 
    
         
            +
                                     :api_url => api_url,
         
     | 
| 
      
 80 
     | 
    
         
            +
                                     :proxy_url => "http://localhost:8888",
         
     | 
| 
      
 81 
     | 
    
         
            +
                                     :proxy_type => "socks5")
         
     | 
| 
      
 82 
     | 
    
         
            +
                  end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                  it "should return the proper response" do
         
     | 
| 
      
 85 
     | 
    
         
            +
                    api_response = { "created" => true }
         
     | 
| 
      
 86 
     | 
    
         
            +
                    stub_keen_post(api_event_collection_resource_url(api_url, collection), 201, api_response)
         
     | 
| 
      
 87 
     | 
    
         
            +
                    client.publish(collection, event_properties).should == api_response
         
     | 
| 
      
 88 
     | 
    
         
            +
                  end
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
       74 
90 
     | 
    
         
             
              end
         
     | 
| 
       75 
91 
     | 
    
         | 
| 
       76 
92 
     | 
    
         
             
              describe "publish_batch" 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: 0.8. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.8.9
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -11,7 +11,7 @@ authors: 
     | 
|
| 
       11 
11 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       12 
12 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       13 
13 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       14 
     | 
    
         
            -
            date:  
     | 
| 
      
 14 
     | 
    
         
            +
            date: 2015-02-27 00:00:00.000000000 Z
         
     | 
| 
       15 
15 
     | 
    
         
             
            dependencies:
         
     | 
| 
       16 
16 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       17 
17 
     | 
    
         
             
              name: multi_json
         
     |