Skip to content

Commit

Permalink
Feature/supported documents add backend token (#13)
Browse files Browse the repository at this point in the history
* Now supported_documents can be accessed with both USER_TOKEN and BACKEND_TOKEN
  • Loading branch information
acostapazo committed Nov 23, 2020
1 parent e0e648e commit fb96802
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion alice/onboarding/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,14 @@ def void_selfie(
)

def supported_documents(
self, user_id: str, verbose: bool = False
self, user_id: str = None, verbose: bool = False
) -> Result[Dict[str, str], OnboardingError]:
"""
This method is used to obtain a hierarchical-ordered dict with the information of the documents supported by the API.
This method can be called accessed with both USER_TOKEN and BACKEND_TOKEN.
If you provide a user_id this method call it using the USER_TOKEN, otherwise it will be called with the BACKEND_TOKEN
Parameters
----------
user_id
Expand Down
11 changes: 8 additions & 3 deletions alice/onboarding/onboarding_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,15 @@ def supported_documents(self, user_id: str, verbose: bool = False) -> Response:
A Response object [requests library]
"""
print_intro("supported_documents", verbose=verbose)
user_token = self.auth.create_user_token(user_id).unwrap()
print_token("user_token", user_token, verbose=verbose)

headers = self._auth_headers(user_token)
if user_id:
token = self.auth.create_user_token(user_id).unwrap()
print_token("user_token", token, verbose=verbose)
else:
token = self.auth.create_backend_token().unwrap()
print_token("backend_token", token, verbose=verbose)

headers = self._auth_headers(token)

response = requests.get(self.url + "/documents/supported", headers=headers)
print_response(response=response, verbose=verbose)
Expand Down
2 changes: 1 addition & 1 deletion examples/onboarding_with_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def configure_webhooks(api_key: str, verbose: bool = False):
webhooks_client.update_webhook(webhook_to_update, verbose)

# Send a ping using configured webhook
webhooks_client.ping_webhook(webhook_id, verbose)
result = webhooks_client.ping_webhook(webhook_id, verbose)

# Retrieve an existent Webhook
retrieved_webhook = webhooks_client.get_webhook(webhook_id, verbose).unwrap()
Expand Down

0 comments on commit fb96802

Please sign in to comment.