Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit 39f73d2

Browse files
committed
Add track_self_describing_event() method (close snowplow#160)
1 parent 76e7538 commit 39f73d2

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

snowplow_tracker/_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
language governing permissions and limitations there under.
1616
1717
Authors: Anuj More, Alex Dean, Fred Blundun
18-
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
18+
Copyright: Copyright (c) 2013-2016 Snowplow Analytics Ltd
1919
License: Apache License Version 2.0
2020
"""
2121

2222

23-
__version_info__ = (0, 7, 2)
23+
__version_info__ = (0, 8, 0)
2424
__version__ = ".".join(str(x) for x in __version_info__)

snowplow_tracker/self_describing_json.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
License: Apache License Version 2.0
2020
"""
2121

22+
2223
class SelfDescribingJson(object):
2324

2425
def __init__(self, schema, data):

snowplow_tracker/test/unit/test_tracker.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
"""
2121

2222

23-
import unittest
2423
import re
24+
import unittest
25+
26+
from contracts.interface import ContractNotRespected
2527
from freezegun import freeze_time
28+
2629
from snowplow_tracker.tracker import Tracker
2730
from snowplow_tracker.emitters import Emitter
2831

@@ -61,3 +64,11 @@ def test_add_emitter(self):
6164
t = Tracker(e1, namespace="cloudfront", encode_base64= False, app_id="AF003")
6265
t.add_emitter(e2)
6366
self.assertEquals(t.emitters, [e1, e2])
67+
68+
def test_alias_contract(self):
69+
e1 = Emitter("d3rkrsqld9gmqf.cloudfront.net", method="get")
70+
t = Tracker(e1, namespace="cloudfront", encode_base64= False, app_id="AF003")
71+
try:
72+
t.track_self_describing_event("not-SelfDescribingJson")
73+
except Exception as e:
74+
self.assertIsInstance(e, ContractNotRespected)

snowplow_tracker/tracker.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(self, emitters, subject=None,
8181
self.emitters = emitters
8282
else:
8383
self.emitters = [emitters]
84-
84+
8585
self.subject = subject
8686
self.encode_base64 = encode_base64
8787

@@ -272,9 +272,9 @@ def track_ecommerce_transaction(self, order_id, total_value,
272272
item["order_id"] = order_id
273273
item["currency"] = currency
274274
self.track_ecommerce_transaction_item(**item)
275-
275+
276276
return self
277-
277+
278278
@contract
279279
def track_screen_view(self, name=None, id_=None, context=None, tstamp=None):
280280
"""
@@ -288,7 +288,7 @@ def track_screen_view(self, name=None, id_=None, context=None, tstamp=None):
288288
"""
289289
screen_view_properties = {}
290290
if name is not None:
291-
screen_view_properties["name"] = name
291+
screen_view_properties["name"] = name
292292
if id_ is not None:
293293
screen_view_properties["id"] = id_
294294

@@ -333,10 +333,11 @@ def track_unstruct_event(self, event_json, context=None, tstamp=None):
333333
:param event_json: The properties of the event. Has two field:
334334
A "data" field containing the event properties and
335335
A "schema" field identifying the schema against which the data is validated
336-
337336
:type event_json: self_describing_json
338337
:param context: Custom context for the event
339338
:type context: context_array | None
339+
:param tstamp: User-set timestamp
340+
:type tstamp: int | None
340341
:rtype: tracker
341342
"""
342343

@@ -349,6 +350,9 @@ def track_unstruct_event(self, event_json, context=None, tstamp=None):
349350

350351
return self.complete_payload(pb, context, tstamp)
351352

353+
# Alias
354+
track_self_describing_event = track_unstruct_event
355+
352356
@contract
353357
def flush(self, async=False):
354358
"""

0 commit comments

Comments
 (0)