From f1e92ac1cc19f168731c3a0f229e83dd222e52b7 Mon Sep 17 00:00:00 2001 From: Alexander Zhilyaev Date: Wed, 3 Aug 2016 09:56:07 +0200 Subject: [PATCH] New users delete endpoint --- appboy/client.py | 20 ++++++++++++++++++++ examples.py | 14 ++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/appboy/client.py b/appboy/client.py index b700133..b42f909 100644 --- a/appboy/client.py +++ b/appboy/client.py @@ -31,6 +31,7 @@ class AppboyClient(object): API_URL = 'https://api.appboy.com' USER_TRACK_ENDPOINT = '/users/track' + USER_DELETE_ENDPOINT = '/users/delete' REQUEST_POST = 'post' @@ -63,6 +64,25 @@ def user_track(self, attributes, events, purchases): return self.__create_request(payload=payload, request_type=self.REQUEST_POST) + def user_delete(self, external_ids, appboy_ids): + """ + Delete user from appboy. + :param external_ids: dict or list of user external ids + :param appboy_ids: dict or list of user appboy ids + :return: json dict response, for example: {"message": "success", "errors": [], "client_error": ""} + """ + self.request_url = self.API_URL + self.USER_DELETE_ENDPOINT + + payload = {} + + if external_ids: + payload['external_ids'] = external_ids + + if appboy_ids: + payload['appboy_ids'] = appboy_ids + + return self.__create_request(payload=payload, request_type=self.REQUEST_POST) + def __create_request(self, payload, request_type): self.headers = { 'Content-Type': 'application/json', diff --git a/examples.py b/examples.py index 47cc28a..9acfbdd 100644 --- a/examples.py +++ b/examples.py @@ -2,6 +2,7 @@ client = AppboyClient(app_group_id='YOUR_GROUP_ID') +# For create - update users r = client.user_track( attributes=[{ 'external_id': '1', @@ -21,3 +22,16 @@ else: print r['client_error'] print r['errors'] + +# For delete users by external_id or appboy_id +r = client.user_delete( + external_ids=['1'], + appboy_ids=None, +) +if r['success']: + # do our magic here + print 'Success!' + print r +else: + print r['client_error'] + print r['errors']