Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #92 from datasift/feature/analyze_limits
Added functionality for analyze limits
  • Loading branch information
andimiller committed Aug 3, 2016
2 parents 8ecc723 + 7bc2bef commit 85f703c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions datasift/limit.py
Expand Up @@ -36,35 +36,47 @@ 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=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`,
:class:`requests.exceptions.HTTPError`
"""

params = {'service': service, 'total_allowance': total_allowance}
params = {'service': service}

if total_allowance is not None:
params['total_allowance'] = total_allowance
if analyze_queries is not 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`,
:class:`requests.exceptions.HTTPError`
"""

params = {'service': service, 'total_allowance': total_allowance}
params = {'service': service}

if total_allowance != None:
params['total_allowance'] = total_allowance
if analyze_queries != None:
params['analyze_queries'] = analyze_queries

return self.request.put(str(identity_id) + '/limit/' + service, params)

Expand Down
2 changes: 1 addition & 1 deletion examples/identity_api.py
Expand Up @@ -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'))
Expand Down

0 comments on commit 85f703c

Please sign in to comment.