Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "context" #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions posthog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def capture(
distinct_id, # type: str
event, # type: str
properties=None, # type: Optional[Dict]
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
groups=None, # type: Optional[Dict]
Expand Down Expand Up @@ -54,7 +53,6 @@ def capture(
distinct_id=distinct_id,
event=event,
properties=properties,
context=context,
timestamp=timestamp,
uuid=uuid,
groups=groups,
Expand All @@ -64,7 +62,6 @@ def capture(
def identify(
distinct_id, # type: str
properties=None, # type: Optional[Dict]
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
):
Expand All @@ -88,7 +85,6 @@ def identify(
"identify",
distinct_id=distinct_id,
properties=properties,
context=context,
timestamp=timestamp,
uuid=uuid,
)
Expand All @@ -97,7 +93,6 @@ def identify(
def set(
distinct_id, # type: str,
properties=None, # type: Optional[Dict]
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
):
Expand All @@ -121,7 +116,6 @@ def set(
"set",
distinct_id=distinct_id,
properties=properties,
context=context,
timestamp=timestamp,
uuid=uuid,
)
Expand All @@ -130,7 +124,6 @@ def set(
def set_once(
distinct_id, # type: str,
properties=None, # type: Optional[Dict]
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
):
Expand All @@ -154,7 +147,6 @@ def set_once(
"set_once",
distinct_id=distinct_id,
properties=properties,
context=context,
timestamp=timestamp,
uuid=uuid,
)
Expand All @@ -164,7 +156,6 @@ def group_identify(
group_type, # type: str
group_key, # type: str
properties=None, # type: Optional[Dict]
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
):
Expand All @@ -189,7 +180,6 @@ def group_identify(
group_type=group_type,
group_key=group_key,
properties=properties,
context=context,
timestamp=timestamp,
uuid=uuid,
)
Expand All @@ -198,7 +188,6 @@ def group_identify(
def alias(
previous_id, # type: str,
distinct_id, # type: str,
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
):
Expand All @@ -223,7 +212,6 @@ def alias(
"alias",
previous_id=previous_id,
distinct_id=distinct_id,
context=context,
timestamp=timestamp,
uuid=uuid,
)
Expand Down
32 changes: 7 additions & 25 deletions posthog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@ def __init__(
if send:
consumer.start()

def identify(self, distinct_id=None, properties=None, context=None, timestamp=None, uuid=None):
def identify(self, distinct_id=None, properties=None, timestamp=None, uuid=None):
properties = properties or {}
context = context or {}
require("distinct_id", distinct_id, ID_TYPES)
require("properties", properties, dict)

msg = {
"timestamp": timestamp,
"context": context,
"distinct_id": distinct_id,
"$set": properties,
"event": "$identify",
Expand All @@ -120,19 +118,15 @@ def identify(self, distinct_id=None, properties=None, context=None, timestamp=No

return self._enqueue(msg)

def capture(
self, distinct_id=None, event=None, properties=None, context=None, timestamp=None, uuid=None, groups=None
):
def capture(self, distinct_id=None, event=None, properties=None, timestamp=None, uuid=None, groups=None):
properties = properties or {}
context = context or {}
require("distinct_id", distinct_id, ID_TYPES)
require("properties", properties, dict)
require("event", event, string_types)

msg = {
"properties": properties,
"timestamp": timestamp,
"context": context,
"distinct_id": distinct_id,
"event": event,
"uuid": uuid,
Expand All @@ -144,15 +138,13 @@ def capture(

return self._enqueue(msg)

def set(self, distinct_id=None, properties=None, context=None, timestamp=None, uuid=None):
def set(self, distinct_id=None, properties=None, timestamp=None, uuid=None):
properties = properties or {}
context = context or {}
require("distinct_id", distinct_id, ID_TYPES)
require("properties", properties, dict)

msg = {
"timestamp": timestamp,
"context": context,
"distinct_id": distinct_id,
"$set": properties,
"event": "$set",
Expand All @@ -161,15 +153,13 @@ def set(self, distinct_id=None, properties=None, context=None, timestamp=None, u

return self._enqueue(msg)

def set_once(self, distinct_id=None, properties=None, context=None, timestamp=None, uuid=None):
def set_once(self, distinct_id=None, properties=None, timestamp=None, uuid=None):
properties = properties or {}
context = context or {}
require("distinct_id", distinct_id, ID_TYPES)
require("properties", properties, dict)

msg = {
"timestamp": timestamp,
"context": context,
"distinct_id": distinct_id,
"$set_once": properties,
"event": "$set_once",
Expand All @@ -178,9 +168,8 @@ def set_once(self, distinct_id=None, properties=None, context=None, timestamp=No

return self._enqueue(msg)

def group_identify(self, group_type=None, group_key=None, properties=None, context=None, timestamp=None, uuid=None):
def group_identify(self, group_type=None, group_key=None, properties=None, timestamp=None, uuid=None):
properties = properties or {}
context = context or {}
require("group_type", group_type, ID_TYPES)
require("group_key", group_key, ID_TYPES)
require("properties", properties, dict)
Expand All @@ -194,15 +183,12 @@ def group_identify(self, group_type=None, group_key=None, properties=None, conte
},
"distinct_id": "${}_{}".format(group_type, group_key),
"timestamp": timestamp,
"context": context,
"uuid": uuid,
}

return self._enqueue(msg)

def alias(self, previous_id=None, distinct_id=None, context=None, timestamp=None, uuid=None):
context = context or {}

def alias(self, previous_id=None, distinct_id=None, timestamp=None, uuid=None):
require("previous_id", previous_id, ID_TYPES)
require("distinct_id", distinct_id, ID_TYPES)

Expand All @@ -212,16 +198,14 @@ def alias(self, previous_id=None, distinct_id=None, context=None, timestamp=None
"alias": distinct_id,
},
"timestamp": timestamp,
"context": context,
"event": "$create_alias",
"distinct_id": previous_id,
}

return self._enqueue(msg)

def page(self, distinct_id=None, url=None, properties=None, context=None, timestamp=None, uuid=None):
def page(self, distinct_id=None, url=None, properties=None, timestamp=None, uuid=None):
properties = properties or {}
context = context or {}

require("distinct_id", distinct_id, ID_TYPES)
require("properties", properties, dict)
Expand All @@ -233,7 +217,6 @@ def page(self, distinct_id=None, url=None, properties=None, context=None, timest
"event": "$pageview",
"properties": properties,
"timestamp": timestamp,
"context": context,
"distinct_id": distinct_id,
"uuid": uuid,
}
Expand All @@ -247,7 +230,6 @@ def _enqueue(self, msg):
timestamp = datetime.utcnow().replace(tzinfo=tzutc())

require("timestamp", timestamp, datetime)
require("context", msg["context"], dict)

# add common
timestamp = guess_timezone(timestamp)
Expand Down
22 changes: 4 additions & 18 deletions posthog/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def test_advanced_capture(self):
"distinct_id",
"python test event",
{"property": "value"},
{"ip": "192.168.0.1"},
datetime(2014, 9, 3),
"new-uuid",
)
Expand All @@ -100,7 +99,6 @@ def test_advanced_capture(self):

self.assertEqual(msg["timestamp"], "2014-09-03T00:00:00+00:00")
self.assertEqual(msg["properties"]["property"], "value")
self.assertEqual(msg["context"]["ip"], "192.168.0.1")
self.assertEqual(msg["event"], "python test event")
self.assertEqual(msg["properties"]["$lib"], "posthog-python")
self.assertEqual(msg["properties"]["$lib_version"], VERSION)
Expand Down Expand Up @@ -132,14 +130,11 @@ def test_basic_identify(self):

def test_advanced_identify(self):
client = self.client
success, msg = client.identify(
"distinct_id", {"trait": "value"}, {"ip": "192.168.0.1"}, datetime(2014, 9, 3), "new-uuid"
)
success, msg = client.identify("distinct_id", {"trait": "value"}, datetime(2014, 9, 3), "new-uuid")

self.assertTrue(success)

self.assertEqual(msg["timestamp"], "2014-09-03T00:00:00+00:00")
self.assertEqual(msg["context"]["ip"], "192.168.0.1")
self.assertEqual(msg["$set"]["trait"], "value")
self.assertEqual(msg["properties"]["$lib"], "posthog-python")
self.assertEqual(msg["properties"]["$lib_version"], VERSION)
Expand All @@ -161,14 +156,11 @@ def test_basic_set(self):

def test_advanced_set(self):
client = self.client
success, msg = client.set(
"distinct_id", {"trait": "value"}, {"ip": "192.168.0.1"}, datetime(2014, 9, 3), "new-uuid"
)
success, msg = client.set("distinct_id", {"trait": "value"}, datetime(2014, 9, 3), "new-uuid")

self.assertTrue(success)

self.assertEqual(msg["timestamp"], "2014-09-03T00:00:00+00:00")
self.assertEqual(msg["context"]["ip"], "192.168.0.1")
self.assertEqual(msg["$set"]["trait"], "value")
self.assertEqual(msg["properties"]["$lib"], "posthog-python")
self.assertEqual(msg["properties"]["$lib_version"], VERSION)
Expand All @@ -190,14 +182,11 @@ def test_basic_set_once(self):

def test_advanced_set_once(self):
client = self.client
success, msg = client.set_once(
"distinct_id", {"trait": "value"}, {"ip": "192.168.0.1"}, datetime(2014, 9, 3), "new-uuid"
)
success, msg = client.set_once("distinct_id", {"trait": "value"}, datetime(2014, 9, 3), "new-uuid")

self.assertTrue(success)

self.assertEqual(msg["timestamp"], "2014-09-03T00:00:00+00:00")
self.assertEqual(msg["context"]["ip"], "192.168.0.1")
self.assertEqual(msg["$set_once"]["trait"], "value")
self.assertEqual(msg["properties"]["$lib"], "posthog-python")
self.assertEqual(msg["properties"]["$lib_version"], VERSION)
Expand Down Expand Up @@ -226,7 +215,7 @@ def test_basic_group_identify(self):

def test_advanced_group_identify(self):
success, msg = self.client.group_identify(
"organization", "id:5", {"trait": "value"}, {"ip": "192.168.0.1"}, datetime(2014, 9, 3), "new-uuid"
"organization", "id:5", {"trait": "value"}, datetime(2014, 9, 3), "new-uuid"
)

self.assertTrue(success)
Expand All @@ -243,7 +232,6 @@ def test_advanced_group_identify(self):
},
)
self.assertEqual(msg["timestamp"], "2014-09-03T00:00:00+00:00")
self.assertEqual(msg["context"]["ip"], "192.168.0.1")

def test_basic_alias(self):
client = self.client
Expand Down Expand Up @@ -279,15 +267,13 @@ def test_advanced_page(self):
"distinct_id",
"https://posthog.com/contact",
{"property": "value"},
{"ip": "192.168.0.1"},
datetime(2014, 9, 3),
"new-uuid",
)

self.assertTrue(success)

self.assertEqual(msg["timestamp"], "2014-09-03T00:00:00+00:00")
self.assertEqual(msg["context"]["ip"], "192.168.0.1")
self.assertEqual(msg["properties"]["$current_url"], "https://posthog.com/contact")
self.assertEqual(msg["properties"]["property"], "value")
self.assertEqual(msg["properties"]["$lib"], "posthog-python")
Expand Down
2 changes: 1 addition & 1 deletion posthog/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "1.4.6"
VERSION = "1.5.0"

if __name__ == "__main__":
print(VERSION, end="")