zulip_bots: Check API key on initialization for Baremetrics bot.
This commit is contained in:
parent
f719964487
commit
8e800d545b
|
@ -2,6 +2,7 @@
|
|||
|
||||
from typing import Any
|
||||
import requests
|
||||
import logging
|
||||
|
||||
class BaremetricsHandler(object):
|
||||
def initialize(self, bot_handler: Any) -> None:
|
||||
|
@ -20,6 +21,19 @@ class BaremetricsHandler(object):
|
|||
'List the sources', 'List the plans for the source', 'List the customers in the source',
|
||||
'List the subscriptions in the source']
|
||||
|
||||
self.check_api_key()
|
||||
|
||||
def check_api_key(self) -> None:
|
||||
url = "https://api.baremetrics.com/v1/account"
|
||||
test_query_response = requests.get(url, headers=self.auth_header)
|
||||
test_query_data = test_query_response.json()
|
||||
|
||||
try:
|
||||
if test_query_data['error'] == "Unauthorized. Token not found":
|
||||
logging.error('API Key not valid. Please see doc.md to find out how to get it.')
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
def usage(self) -> str:
|
||||
return '''
|
||||
This bot gives updates about customer behavior, financial performance, and analytics
|
||||
|
|
Loading…
Reference in a new issue