Skip to content

Commit 8dd1dce

Browse files
committed
Imported public classes into __init__.py
Added _subject contract to Tracker.__init__ Changed "str" to "string" in contracts to support unicode
1 parent 352d412 commit 8dd1dce

4 files changed

Lines changed: 25 additions & 19 deletions

File tree

snowplow_tracker/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from snowplow_tracker._version import __version__
2+
from snowplow_tracker.subject import Subject
3+
from snowplow_tracker.consumer import Consumer, AsyncConsumer, CeleryConsumer, RedisConsumer
4+
from snowplow_tracker.tracker import Tracker

snowplow_tracker/payload.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def add_dict(self, dict_, base64=False):
5858
Add a dict of name value pairs to the Payload object
5959
6060
:param dict_: Dictionary to be added to the Payload
61-
:type dict_: dict(*:*)
61+
:type dict_: dict(string:*)
6262
"""
6363
for f in dict_:
6464
self.add(f, dict_[f])
@@ -69,13 +69,13 @@ def add_json(self, dict_, encode_base64, type_when_encoded, type_when_not_encode
6969
Add an encoded or unencoded JSON to the payload
7070
7171
:param dict_: Custom context for the event
72-
:type dict_: dict(str:*) | None
72+
:type dict_: dict(string:*) | None
7373
:param encode_base64: If the payload is base64 encoded
7474
:type encode_base64: bool
7575
:param type_when_encoded: Name of the field when encode_base64 is set
76-
:type type_when_encoded: str
76+
:type type_when_encoded: string
7777
:param type_when_not_encoded: Name of the field when encode_base64 is not set
78-
:type type_when_not_encoded: str
78+
:type type_when_not_encoded: string
7979
"""
8080

8181
if dict_ is not None and dict_ != {}:

snowplow_tracker/subject.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self):
4040
def set_platform(self, value):
4141
"""
4242
:param value: One of ["pc", "tv", "mob", "cnsl", "iot"]
43-
:type value: str
43+
:type value: string
4444
:rtype: subject
4545
"""
4646
if value in SUPPORTED_PLATFORMS:
@@ -53,7 +53,7 @@ def set_platform(self, value):
5353
def set_user_id(self, user_id):
5454
"""
5555
:param user_id: User ID
56-
:type user_id: non_empty_string
56+
:type user_id: string
5757
:rtype: subject
5858
"""
5959
self.standard_nv_pairs["uid"] = user_id
@@ -97,7 +97,7 @@ def set_color_depth(self, depth):
9797
def set_timezone(self, timezone):
9898
"""
9999
:param timezone: Timezone as a string
100-
:type timezone: non_empty_string
100+
:type timezone: string
101101
:rtype: subject
102102
"""
103103
self.standard_nv_pairs["tz"] = timezone
@@ -109,7 +109,7 @@ def set_lang(self, lang):
109109
Set language.
110110
111111
:param lang: Language the application is set to
112-
:type lang: non_empty_string
112+
:type lang: string
113113
:rtype: subject
114114
"""
115115
self.standard_nv_pairs["lang"] = lang

snowplow_tracker/tracker.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import time
2323
import random
2424
import logging
25-
from snowplow_tracker import payload, _version
25+
from snowplow_tracker import payload, _version, subject
2626
from contracts import contract, new_contract, disable_all
2727

2828

@@ -56,12 +56,14 @@ class Tracker:
5656
new_contract("consumer", lambda s: hasattr(s, "input"))
5757

5858
@contract
59-
def __init__(self, out_queue, subject=None,
59+
def __init__(self, out_queue, _subject=None,
6060
namespace=None, app_id=None, context_vendor=None, encode_base64=DEFAULT_ENCODE_BASE64,
6161
contracts=True, log=True):
6262
"""
6363
:param out_queue: Consumer to which events will be sent
6464
:type out_queue: consumer
65+
:param _subject: Subject to be tracked
66+
:type _subject: subject | None
6567
:param namespace: Identifier for the Tracker instance
6668
:type namespace: string_or_none
6769
:param app_id: Application ID
@@ -82,7 +84,7 @@ def __init__(self, out_queue, subject=None,
8284
logger.setLevel(logging.CRITICAL)
8385

8486
self.out_queue = out_queue
85-
self.subject=subject
87+
self.subject = _subject
8688
self.encode_base64 = encode_base64
8789
self.context_vendor = context_vendor
8890

@@ -166,7 +168,7 @@ def track_page_view(self, page_url, page_title=None, referrer=None, context=None
166168
:param referrer: Referrer of the page
167169
:type referrer: string_or_none
168170
:param context: Custom context for the event
169-
:type context: dict(str:*) | None
171+
:type context: dict(string:*) | None
170172
:rtype: tracker | int
171173
"""
172174
pb = payload.Payload()
@@ -208,7 +210,7 @@ def track_ecommerce_transaction_item(self, order_id, sku, price, quantity,
208210
:param currency: The currency the price is expressed in
209211
:type currency: string_or_none
210212
:param context: Custom context for the event
211-
:type context: dict(str:*) | None
213+
:type context: dict(string:*) | None
212214
:rtype: tracker | int
213215
"""
214216
pb = payload.Payload()
@@ -255,8 +257,8 @@ def track_ecommerce_transaction(self, order_id, total_value,
255257
:param items: The items in the transaction
256258
:type items: list(dict(str:*))
257259
:param context: Custom context for the event
258-
:type context: dict(str:*) | None
259-
:rtype: tracker | dict(str:*)
260+
:type context: dict(string:*) | None
261+
:rtype: tracker | dict(string:*)
260262
"""
261263
pb = payload.Payload()
262264
pb.add("e", "tr")
@@ -302,7 +304,7 @@ def track_screen_view(self, name, id_=None, context=None, tstamp=None):
302304
:param id_: Screen view ID
303305
:type id_: string_or_none
304306
:param context: Custom context for the event
305-
:type context: dict(str:*) | None
307+
:type context: dict(string:*) | None
306308
:rtype: tracker | int
307309
"""
308310
screen_view_properties = {"name": name}
@@ -328,7 +330,7 @@ def track_struct_event(self, category, action, label=None, property_=None, value
328330
:param value: A value associated with the user action
329331
:type value: int | float | None
330332
:param context: Custom context for the event
331-
:type context: dict(str:*) | None
333+
:type context: dict(string:*) | None
332334
:rtype: tracker | int
333335
"""
334336
pb = payload.Payload()
@@ -356,9 +358,9 @@ def track_unstruct_event(self, event_vendor, event_name, dict_, context=None, ts
356358
:param event_name: The name of the event
357359
:type event_name: non_empty_string
358360
:param dict_: The properties of the event
359-
:type dict_: dict(str:*)
361+
:type dict_: dict(string:*)
360362
:param context: Custom context for the event
361-
:type context: dict(str:*) | None
363+
:type context: dict(string:*) | None
362364
:rtype: tracker | int
363365
"""
364366
pb = payload.Payload()

0 commit comments

Comments
 (0)