Skip to content

Commit

Permalink
Merge commit '600869d73aa0c87c409083037a7c00372aeaecc3' into sync-all…
Browse files Browse the repository at this point in the history
…-travelperk-accounts
  • Loading branch information
JustARatherRidiculouslyLongUsername committed Oct 28, 2024
2 parents ba9d32c + 600869d commit 6f66765
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions connectors/travelperk/apis/api_base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging
from typing import List, Dict
import requests
import json

from connectors.travelperk.exceptions import *

logger = logging.getLogger(__name__)

class ApiBase:
"""The base class for all API classes."""
Expand All @@ -28,7 +30,7 @@ def set_server_url(self, server_url):
"""
self.__server_url = server_url

def _get_error(self, status_code: int, response_text: str):
def _get_error(self, status_code: int, response_text: str) -> TravelperkError:
"""Get the error object from the response.
Parameters:
Expand Down Expand Up @@ -116,18 +118,25 @@ def _post_request(self, api_url: str, data: Dict) -> Dict:
'Api-Version': '1'
}

endpoint = '{0}{1}'.format(self.__server_url, api_url)
logger.debug(f"POST {endpoint}")
logger.debug(f"Payload for POST request: {data}")
response = requests.post(
'{0}{1}'.format(self.__server_url, api_url),
endpoint,
headers=api_headers,
json=data
)

if response.status_code == 200:
result = json.loads(response.text)
logger.debug(f"POST response: {result}")
return result

else:
raise self._get_error(response.status_code, response.text)
error = self._get_error(response.status_code, response.text)
logger.info(f"POST request failed: {response.status_code} | {error.message}")
logger.info(f"POST response: {error.response}")
raise error

def _delete_request(self, api_url: str) -> Dict:
"""Create a HTTP DELETE request.
Expand Down

0 comments on commit 6f66765

Please sign in to comment.