zulip_bots: Check API key on initialization for Baremetrics bot.

This commit is contained in:
Viraat Chandra 2017-12-29 18:20:35 +05:30 committed by Robert Hönig
parent f719964487
commit 8e800d545b

View file

@ -2,6 +2,7 @@
from typing import Any from typing import Any
import requests import requests
import logging
class BaremetricsHandler(object): class BaremetricsHandler(object):
def initialize(self, bot_handler: Any) -> None: 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 sources', 'List the plans for the source', 'List the customers in the source',
'List the subscriptions 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: def usage(self) -> str:
return ''' return '''
This bot gives updates about customer behavior, financial performance, and analytics This bot gives updates about customer behavior, financial performance, and analytics