diff --git a/README.md b/README.md index f5934f0..ab1bd4e 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,11 @@ properties["mrr"] = 399 properties["plan"] = "Pro" properties["registered_at"] = datetime.now() properties["this_property_will_be_deleted"] = "" -result = client.upsert_account(account, properties, ["memberId1", "memberId2"]) + +member1 = UserIdentified.by_user_id("memberId1") +member2 = UserIdentified.by_user_id("memberId2") + +result = client.upsert_account(account, properties, [member1, member2]) if isinstance(result, Success): print(result.request_id) # str print(result.calls_remaining) # int diff --git a/journyio/client.py b/journyio/client.py index 59464cb..210327d 100644 --- a/journyio/client.py +++ b/journyio/client.py @@ -12,6 +12,7 @@ from .user_identified import UserIdentified from .account_identified import AccountIdentified + class Properties(dict): def __init__(self): @@ -149,12 +150,13 @@ def upsert_user(self, user: UserIdentified, properties: Properties) -> Success[N except Exception: raise JournyException(f"An unknown error has occurred") - def upsert_account(self, account: AccountIdentified, properties: Properties, members: List[str]) -> Success[ - None] or Failure: + def upsert_account(self, account: AccountIdentified, properties: Properties, members: List[UserIdentified]) -> \ + Success[ + None] or Failure: assert_journy(isinstance(account, AccountIdentified), "Account is not an AccountIdentified object.") assert_journy(isinstance(properties, Properties), "Properties is not a Properties object.") for member in members: - assert_journy(isinstance(member, str), f"Member {member} is not a string.") + assert_journy(isinstance(member, UserIdentified), f"Member {member} is not a UserIdentified object.") try: request = HttpRequest(self.__create_url("/accounts/upsert"), Method.POST, @@ -162,7 +164,8 @@ def upsert_account(self, account: AccountIdentified, properties: Properties, mem json.dumps({ "identification": account.format_identification(), "properties": properties.properties, - "members": members + "members": [{"identification": member.format_identification()} for member in + members] })) response = self.httpclient.send(request) calls_remaining = Client.__parse_calls_remaining(response) diff --git a/tests/test_client.py b/tests/test_client.py index 500bb2d..4c5f47d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -154,7 +154,10 @@ def test_client_upsert_account(): properties["haveDog"] = False properties["name"] = "Journy" - response = client.upsert_account(account, properties, ["hansId", "manuId"]) + member1 = UserIdentified.by_user_id("hansId") + member2 = UserIdentified.by_user_id("manuId") + + response = client.upsert_account(account, properties, [member1, member2]) assert (isinstance(response, Success)) assert (response.__str__() == "Success(requestId, 4999, None)") @@ -163,7 +166,7 @@ def test_client_upsert_account(): assert (response.data is None) assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/accounts/upsert, Method.POST, {"content-type": "application/json", "x-api-key": "api-key"}, {"identification": {"domain": "www.journy.io", "accountId": "account_id"}, "properties": {"havedog": false, "name": "Journy"}, "members": ["hansId", "manuId"]})') + http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/accounts/upsert, Method.POST, {"content-type": "application/json", "x-api-key": "api-key"}, {"identification": {"domain": "www.journy.io", "accountId": "account_id"}, "properties": {"havedog": false, "name": "Journy"}, "members": [{"identification": {"userId": "hansId"}}, {"identification": {"userId": "manuId"}}]})') def test_client_link():