diff --git a/qbosdk/apis/api_base.py b/qbosdk/apis/api_base.py index f843603..790e1e9 100644 --- a/qbosdk/apis/api_base.py +++ b/qbosdk/apis/api_base.py @@ -1,6 +1,7 @@ """ API Base class with util functions """ +import logging import json from typing import List, Dict, Generator @@ -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.""" @@ -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'] @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/setup.py b/setup.py index b3beec5..ca13f6c 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name='qbosdk', - version='0.18.0', + version='0.18.1', author='Shwetabh Kumar', author_email='shwetabh.kumar@fyle.in', description='Python SDK for accessing Quickbooks Online APIs',