Skip to content

Commit

Permalink
Clean up user_track and user_delete
Browse files Browse the repository at this point in the history
  • Loading branch information
AA33 committed Feb 10, 2019
1 parent facd108 commit 2b51c11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions braze/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,45 +98,59 @@ def __init__(self, api_key, api_url=None):
self.api_url = api_url or DEFAULT_API_URL
self.request_url = ""

def user_track(self, attributes, events, purchases):
def user_track(self, attributes=None, events=None, purchases=None):
"""
Record custom events, user attributes, and purchases for users.
:param attributes: dict or list of user attributes dict (external_id, first_name, email)
:param events: dict or list of user events dict (external_id, app_id, name, time, properties)
:param purchases: dict or list of user purchases dict (external_id, app_id, product_id, currency, price)
:return: json dict response, for example: {"message": "success", "errors": [], "client_error": ""}
"""
if attributes is events is purchases is None:
raise ValueError(
"Bad arguments, at least one of attributes, events or purchases must be "
"non None"
)
self.request_url = self.api_url + USER_TRACK_ENDPOINT

payload = {}

if events:
payload["events"] = events
else:
payload["events"] = []

if attributes:
payload["attributes"] = attributes
else:
payload["attributes"] = []

if purchases:
payload["purchases"] = purchases
else:
payload["purchases"] = []

return self.__create_request(payload=payload)

def user_delete(self, external_ids, appboy_ids):
def user_delete(self, external_ids):
"""
Delete user from braze.
:param external_ids: dict or list of user external ids
:param appboy_ids: dict or list of user braze ids
:return: json dict response, for example: {"message": "success", "errors": [], "client_error": ""}
"""
if not external_ids:
raise ValueError("No external ids specified")

self.request_url = self.api_url + USER_DELETE_ENDPOINT

payload = {"external_ids": external_ids}

return self.__create_request(payload=payload)
payload = {}

if external_ids:
payload["external_ids"] = external_ids

if appboy_ids:
payload["appboy_ids"] = appboy_ids

return self.__create_request(payload=payload)

Expand Down
2 changes: 1 addition & 1 deletion examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
print(r["errors"])

# For delete users by external_id or appboy_id
r = client.user_delete(external_ids=["1"], appboy_ids=None)
r = client.user_delete(external_ids=["1"], braze_ids=None)
if r["success"]:
# do our magic here
print("Success!")
Expand Down

0 comments on commit 2b51c11

Please sign in to comment.