Skip to content

Commit

Permalink
feat: Add extensive loggers (#29)
Browse files Browse the repository at this point in the history
* feat: Add extensive loggers

* comment resolved

* dump up version

* resolved comment
  • Loading branch information
Ashutosh619-sudo authored Oct 10, 2024
1 parent 8b0c63d commit 72a4c47
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion qbosdk/apis/api_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
API Base class with util functions
"""
import logging
import json
from typing import List, Dict, Generator

Expand All @@ -9,6 +10,7 @@
from ..exceptions import WrongParamsError, InvalidTokenError, QuickbooksOnlineSDKError, \
NoPrivilegeError, NotFoundItemError, ExpiredTokenError, InternalServerError

logger = logging.getLogger(__name__)

class ApiBase:
"""The base class for all API classes."""
Expand Down Expand Up @@ -54,6 +56,7 @@ def _query_get_all(self, object_type: str, url: str) -> List[Dict]:
response = requests.get(url=request_url.format(start_position), headers=api_headers)

if response.status_code == 200:
logger.debug('Response for get request for url: %s, %s', url, response.text)
data = json.loads(response.text)
query_response = data['QueryResponse']

Expand All @@ -66,6 +69,7 @@ def _query_get_all(self, object_type: str, url: str) -> List[Dict]:
query_response = data['QueryResponse']
return objects

logger.info('Response for get request for url: %s, %s', url, response.text)
if response.status_code == 400:
raise WrongParamsError('Some of the parameters are wrong', response.text)

Expand Down Expand Up @@ -113,11 +117,14 @@ def _query_get_all_generator(self, object_type: str, url: str) -> Generator[Dict
if not query_response or object_type not in query_response:
break

logger.debug('Response for get request for url: %s, %s', url, response.text)

yield query_response[object_type]

start_position += 1000

except requests.exceptions.HTTPError as err:
logger.info('Response for get request for url: %s, %s', url, err.response.text)
if err.response.status_code == 400:
raise WrongParamsError('Some of the parameters are wrong', err.response.text)

Expand Down Expand Up @@ -153,9 +160,11 @@ def _query(self, url: str) -> List[Dict]:
response = requests.get(url=request_url, headers=api_headers)

if response.status_code == 200:
logger.debug('Response for get request for url: %s, %s', url, response.text)
data = json.loads(response.text)
return data['QueryResponse']

logger.info('Response for get request for url: %s, %s', url, response.text)
if response.status_code == 400:
raise WrongParamsError('Some of the parameters are wrong', response.text)

Expand Down Expand Up @@ -197,9 +206,11 @@ def _get_request(self, object_type: str, api_url: str) -> List[Dict] or Dict:
)

if response.status_code == 200:
logger.debug('Response for get request for url: %s, %s', api_url, response.text)
result = json.loads(response.text)
return result[object_type]

logger.info('Response for get request for url: %s, %s', api_url, response.text)
if response.status_code == 400:
raise WrongParamsError('Some of the parameters are wrong', response.text)

Expand Down Expand Up @@ -244,8 +255,12 @@ def _post_request(self, data, api_url):
)

if response.status_code == 200:
logger.debug('Response for post request: %s', response.text)
result = json.loads(response.text)
return result

logger.debug('Payload for post request: %s', data)
logger.info('Response for post request: %s', response.text)

if response.status_code == 400:
raise WrongParamsError('Some of the parameters are wrong', response.text)
Expand Down Expand Up @@ -292,9 +307,14 @@ def _post_file(self, data, api_url):
)

if response.status_code == 200:
logger.debug('Response for post request: %s', response.text)
result = json.loads(response.text)
return result['AttachableResponse'][0]['Attachable']


logger.debug('Payload for post request: %s', data)
logger.info('Response for post request: %s', response.text)

if response.status_code == 400:
raise WrongParamsError('Some of the parameters are wrong', response.text)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='qbosdk',
version='0.18.0',
version='0.18.1',
author='Shwetabh Kumar',
author_email='[email protected]',
description='Python SDK for accessing Quickbooks Online APIs',
Expand Down

0 comments on commit 72a4c47

Please sign in to comment.