Skip to content

Commit 817d289

Browse files
author
Sam Gammon
committed
Merge branch 'master' of github.com:keenlabs/KeenClient-Python into hotfix-basestring
2 parents fc509c0 + 455cf45 commit 817d289

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

LICENSE.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2013 Keen Labs
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ Here are some examples of querying. Let's assume you've added some events to th
9595

9696
### Changelog
9797

98+
##### 0.2.2
99+
100+
+ Added interval to multi_analysis.
101+
102+
##### 0.2.1
103+
104+
+ Added stacktrace_id and unique_id to Keen API errors.
105+
98106
##### 0.2.0
99107

100108
+ Added add_events method to keen/__init__.py so it can be used at a module level.

keen/client.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def funnel(self, steps, timeframe=None, timezone=None):
353353
params = self.get_params(steps=steps, timeframe=timeframe, timezone=timezone)
354354
return self.api.query("funnel", params)
355355

356-
def multi_analysis(self, event_collection, analyses, timeframe=None, timezone=None, filters=None, group_by=None):
356+
def multi_analysis(self, event_collection, analyses, timeframe=None, interval=None, timezone=None, filters=None, group_by=None):
357357
""" Performs a multi-analysis query
358358
359359
Returns a dictionary of analysis results.
@@ -364,6 +364,8 @@ def multi_analysis(self, event_collection, analyses, timeframe=None, timezone=No
364364
"average price":{"analysis_type":"average","target_property":"purchase.price"}
365365
:param timeframe: string or dict, the timeframe in which the events
366366
happened example: "previous_7_days"
367+
:param interval: string, the time interval used for measuring data over
368+
time example: "daily"
367369
:param timezone: int, the timezone you'd like to use for the timeframe
368370
and interval in seconds
369371
:param filters: array of dict, contains the filters you'd like to apply to the data
@@ -372,8 +374,15 @@ def multi_analysis(self, event_collection, analyses, timeframe=None, timezone=No
372374
like to group you results by. example: "customer.id" or ["browser","operating_system"]
373375
374376
"""
375-
params = self.get_params(event_collection=event_collection, timeframe=timeframe, timezone=timezone,
376-
filters=filters, group_by=group_by, analyses=analyses)
377+
params = self.get_params(
378+
event_collection=event_collection,
379+
timeframe=timeframe,
380+
interval=interval,
381+
timezone=timezone,
382+
filters=filters,
383+
group_by=group_by,
384+
analyses=analyses)
385+
377386
return self.api.query("multi_analysis", params)
378387

379388
def get_params(self, event_collection=None, timeframe=None, timezone=None, interval=None, filters=None,
@@ -393,7 +402,7 @@ def get_params(self, event_collection=None, timeframe=None, timezone=None, inter
393402
if filters:
394403
params["filters"] = json.dumps(filters)
395404
if group_by:
396-
if type(group_by) is dict:
405+
if type(group_by) is list:
397406
params["group_by"] = json.dumps(group_by)
398407
else:
399408
params["group_by"] = group_by

keen/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def __init__(self, api_error):
3131
self.api_error = api_error
3232
self._message = "Error from Keen API. Details:\n Message: {0}\nCode: " \
3333
"{1}".format(api_error["message"], api_error["error_code"])
34+
if "stacktrace_id" in api_error:
35+
self._message = "{0}\nStacktrace ID: {1}".format(self._message, api_error["stacktrace_id"])
36+
if "unique_id" in api_error:
37+
self._message = "{0}\nUnique ID: {1}".format(self._message, api_error["unique_id"])
3438

3539

3640
class InvalidEnvironmentError(BaseKeenClientError):

keen/tests/client_tests.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ def setUp(self):
204204
api_key = "2e79c6ec1d0145be8891bf668599c79a"
205205
keen.write_key = scoped_keys.encrypt(api_key, {"allowed_operations": ["write"]})
206206
keen.read_key = scoped_keys.encrypt(api_key, {"allowed_operations": ["read"]})
207-
keen.add_event("query test", {"number": 5})
208-
keen.add_event("step2", {"number": 5})
207+
keen.add_event("query test", {"number": 5, "string": "foo"})
208+
keen.add_event("step2", {"number": 5, "string": "foo"})
209209

210210
def tearDown(self):
211211
keen.project_id = None
@@ -274,6 +274,11 @@ def test_group_by(self):
274274
resp = keen.count("query test", timeframe="today", group_by="number")
275275
assert type(resp) is list
276276

277+
def test_multi_group_by(self):
278+
resp = keen.count("query test", timeframe="today", group_by=["number", "string"])
279+
assert type(resp) is list
280+
assert len(resp) == 1
281+
277282
def test_interval(self):
278283
resp = keen.count("query test", timeframe="this_2_days", interval="daily")
279284
assert type(resp) is list

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from distutils.core import setup
44

55
setup(name="keen",
6-
version="0.2.0",
6+
version="0.2.2",
77
description="Python Client for Keen IO",
88
author="Keen IO",
99
author_email="[email protected]",

0 commit comments

Comments
 (0)