From 9c931d96799e8791ed1dd0a167b1e04e0689d3dd Mon Sep 17 00:00:00 2001 From: Paul Mozo Date: Wed, 3 Aug 2016 16:08:15 +0100 Subject: [PATCH 1/3] Added functionality for analyze limits Updated identity example to demonstrate usage --- datasift/limit.py | 16 +++++++++++++--- examples/identity_api.py | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/datasift/limit.py b/datasift/limit.py index 7213d4c..66f577e 100644 --- a/datasift/limit.py +++ b/datasift/limit.py @@ -36,7 +36,7 @@ def list(self, service, per_page=20, page=1): return self.request.get('limit/' + service, params) - def create(self, identity_id, service, total_allowance): + def create(self, identity_id, service, total_allowance=False, analyze_queries=False): """ Create the limit :param identity_id: The ID of the identity to retrieve @@ -48,7 +48,12 @@ def create(self, identity_id, service, total_allowance): :class:`requests.exceptions.HTTPError` """ - params = {'service': service, 'total_allowance': total_allowance} + params = {'service': service} + + if total_allowance: + params['total_allowance'] = total_allowance + if analyze_queries: + params['analyze_queries'] = analyze_queries return self.request.post(str(identity_id) + '/limit/', params) @@ -64,7 +69,12 @@ def update(self, identity_id, service, total_allowance): :class:`requests.exceptions.HTTPError` """ - params = {'service': service, 'total_allowance': total_allowance} + params = {'service': service} + + if total_allowance: + params['total_allowance'] = total_allowance + if analyze_queries: + params['analyze_queries'] = analyze_queries return self.request.put(str(identity_id) + '/limit/' + service, params) diff --git a/examples/identity_api.py b/examples/identity_api.py index ea9cb10..7ab2ec2 100644 --- a/examples/identity_api.py +++ b/examples/identity_api.py @@ -29,7 +29,7 @@ print(customer_client.pylon.list()) print("Create a limit for this identity and service") -datasift.account.identity.limit.create(identity['id'], 'facebook', 1000) +datasift.account.identity.limit.create(identity['id'], 'facebook', 1000, 2000) print("Get the newly created limit") print(datasift.account.identity.limit.get(identity['id'], 'facebook')) From ecec1f8f916a8d6d36e1a956346b822a5afc0a9d Mon Sep 17 00:00:00 2001 From: Paul Mozo Date: Wed, 3 Aug 2016 16:30:06 +0100 Subject: [PATCH 2/3] Added doc strings and changed parameter defaults to be None rather than False --- datasift/limit.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/datasift/limit.py b/datasift/limit.py index 66f577e..cf6c969 100644 --- a/datasift/limit.py +++ b/datasift/limit.py @@ -36,12 +36,13 @@ def list(self, service, per_page=20, page=1): return self.request.get('limit/' + service, params) - def create(self, identity_id, service, total_allowance=False, analyze_queries=False): + def create(self, identity_id, service, total_allowance=None, analyze_queries=None): """ Create the limit :param identity_id: The ID of the identity to retrieve :param service: The service that the token is linked to :param total_allowance: The total allowance for this token's limit + :param analyze_queries: The number of analyze calls :return: dict of REST API output with headers attached :rtype: :class:`~datasift.request.DictResponse` :raises: :class:`~datasift.exceptions.DataSiftApiException`, @@ -50,19 +51,20 @@ def create(self, identity_id, service, total_allowance=False, analyze_queries=Fa params = {'service': service} - if total_allowance: + if total_allowance != None: params['total_allowance'] = total_allowance - if analyze_queries: + if analyze_queries != None: params['analyze_queries'] = analyze_queries return self.request.post(str(identity_id) + '/limit/', params) - def update(self, identity_id, service, total_allowance): + def update(self, identity_id, service, total_allowance=None, analyze_queries=None): """ Update the limit :param identity_id: The ID of the identity to retrieve :param service: The service that the token is linked to :param total_allowance: The total allowance for this token's limit + :param analyze_queries: The number of analyze calls :return: dict of REST API output with headers attached :rtype: :class:`~datasift.request.DictResponse` :raises: :class:`~datasift.exceptions.DataSiftApiException`, @@ -71,9 +73,9 @@ def update(self, identity_id, service, total_allowance): params = {'service': service} - if total_allowance: + if total_allowance != None: params['total_allowance'] = total_allowance - if analyze_queries: + if analyze_queries != None: params['analyze_queries'] = analyze_queries return self.request.put(str(identity_id) + '/limit/' + service, params) From 7bc2befd9d55a0fb5567394419723e063d17867d Mon Sep 17 00:00:00 2001 From: Paul Mozo Date: Wed, 3 Aug 2016 16:34:10 +0100 Subject: [PATCH 3/3] Updated with pep8 standard --- datasift/limit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datasift/limit.py b/datasift/limit.py index cf6c969..20bf7e5 100644 --- a/datasift/limit.py +++ b/datasift/limit.py @@ -51,9 +51,9 @@ def create(self, identity_id, service, total_allowance=None, analyze_queries=Non params = {'service': service} - if total_allowance != None: + if total_allowance is not None: params['total_allowance'] = total_allowance - if analyze_queries != None: + if analyze_queries is not None: params['analyze_queries'] = analyze_queries return self.request.post(str(identity_id) + '/limit/', params)