Skip to content

Commit

Permalink
Remove token parameter if the user is logged in and doesn't supply one
Browse files Browse the repository at this point in the history
  • Loading branch information
Elleo committed Dec 7, 2017
1 parent 1bae25c commit ef343d5
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions cape/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,6 @@ def answer(self, question, token=None, threshold=None, document_ids=None,
:param offset: The starting point in the list of answers, used in conjunction with number_of_items to retrieve multiple batches of answers.
:return: A list of answers
"""
if token is None:
if self.user_token is None:
if self.logged_in():
self.user_token = self.get_user_token()
else:
raise CapeException('A user token must be specified to retrieve an answer')
token = self.user_token

if document_ids is not None:
if not isinstance(document_ids, list):
raise TypeError(f'Expecting document ids to be of type list, instead got {type(document_ids)}')
Expand All @@ -162,6 +154,10 @@ def answer(self, question, token=None, threshold=None, document_ids=None,
'speedOrAccuracy': speed_or_accuracy,
'numberOfItems': str(number_of_items),
'offset': str(offset)}
if token is None:
params.pop('token')
if not self.logged_in():
raise CapeException("A user token must be supplied if the client isn't logged in.")
if len(document_ids) == 0:
params.pop('documentIds')
if threshold is None:
Expand Down

0 comments on commit ef343d5

Please sign in to comment.