From dc8b5e7e01fd58493c49d579f5ac2b15c283d620 Mon Sep 17 00:00:00 2001 From: Manu De Buck Date: Tue, 15 Jun 2021 23:45:29 +0200 Subject: [PATCH 1/4] Add support for null values and arrays in properties --- journyio/client.py | 12 +++++++++--- tests/test_client.py | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/journyio/client.py b/journyio/client.py index 59464cb..d56b07c 100644 --- a/journyio/client.py +++ b/journyio/client.py @@ -22,12 +22,18 @@ def __getitem__(self, key: str): assert_journy(isinstance(key, str), "The key is not a string.") return self.properties.get(key.lower().strip()) - def __setitem__(self, key: str, value: str or list): + def a(self, a: str): + pass + + def __setitem__(self, key: str, value: str or List[str] or bool or int or datetime or None): assert_journy(isinstance(key, str), "The key is not a string.") - if isinstance(value, str) or isinstance(value, int) or isinstance(value, bool) or isinstance(value, datetime): + if isinstance(value, str) or isinstance(value, int) or isinstance(value, bool) or isinstance(value, datetime) \ + or value is None or (isinstance(value, list) and all([isinstance(el, str) for el in value])): + if isinstance(value, datetime): + value = str(value.isoformat()) self.properties.__setitem__(key.lower().strip(), value) else: - raise JournyException("Value is not a string, number, boolean or datetime.") + raise JournyException("Value is not a string, number, boolean, datetime or None.") def union(self, other): self.properties.update(other.properties) diff --git a/tests/test_client.py b/tests/test_client.py index 500bb2d..ef6fb60 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -33,6 +33,8 @@ def test_properties(): properties["doesexisttoo"] = 2 assert (properties["doesexisttoo"] == 2) properties["thistoo"] = True + properties["will_be_deleted"] = None + properties["array_of_values"] = ["first_value", "second_value"] assert (properties["thistoo"]) with pytest.raises(JournyException): properties[2] = "hallo" From 3971c38b7260cedbe26b85d63b2d94d0dcc23cd9 Mon Sep 17 00:00:00 2001 From: Manu De Buck Date: Tue, 15 Jun 2021 23:48:13 +0200 Subject: [PATCH 2/4] Add REAMDE examples --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f5934f0..bcda567 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,9 @@ properties["is_paying_account"] = True properties["mrr"] = 399 properties["plan"] = "Pro" properties["registered_at"] = datetime.now() -properties["this_property_will_be_deleted"] = "" +properties["empty_property"] = "" +properties["previous_plans"] = ["Free", "Business"] +properties["this_property_will_be_deleted"] = None result = client.upsert_account(account, properties, ["memberId1", "memberId2"]) if isinstance(result, Success): print(result.request_id) # str From 76bea90f8163b38291232656f11fb77dcb5dafd9 Mon Sep 17 00:00:00 2001 From: Manu De Buck Date: Tue, 29 Jun 2021 11:24:12 +0200 Subject: [PATCH 3/4] Remove debug statement --- journyio/client.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/journyio/client.py b/journyio/client.py index d56b07c..fbf480c 100644 --- a/journyio/client.py +++ b/journyio/client.py @@ -22,9 +22,6 @@ def __getitem__(self, key: str): assert_journy(isinstance(key, str), "The key is not a string.") return self.properties.get(key.lower().strip()) - def a(self, a: str): - pass - def __setitem__(self, key: str, value: str or List[str] or bool or int or datetime or None): assert_journy(isinstance(key, str), "The key is not a string.") if isinstance(value, str) or isinstance(value, int) or isinstance(value, bool) or isinstance(value, datetime) \ From 366af8b442fde7e69e269ebca57a365b39b14f3d Mon Sep 17 00:00:00 2001 From: Manu De Buck Date: Tue, 29 Jun 2021 11:30:50 +0200 Subject: [PATCH 4/4] Update properties in README according to API Docs --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bcda567..543210b 100644 --- a/README.md +++ b/README.md @@ -97,13 +97,15 @@ account = AccountIdentified.by_account_id("accountId") account = AccountIdentified.by_domain("www.domain.tld") properties = Properties() -properties["name"] = "ACME, Inc" -properties["is_paying_account"] = True -properties["mrr"] = 399 -properties["plan"] = "Pro" +properties["full_name"] = "John Doe" +properties["first_name"] = "John" +properties["last_name"] = "Doe" +properties["phone"] = "123" +properties["is_admin"] = True properties["registered_at"] = datetime.now() -properties["empty_property"] = "" -properties["previous_plans"] = ["Free", "Business"] +properties["age"] = 26 +properties["array_of_values"] = ["value1", "value2"] +properties["key_with_empty_value"] = "" properties["this_property_will_be_deleted"] = None result = client.upsert_account(account, properties, ["memberId1", "memberId2"]) if isinstance(result, Success):