Created
February 12, 2024 23:33
-
-
Save carlosfernandezcabrero/bc9013c8e12d040a4e24330ae4ffc3cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
MIME_TYPES = { | |
"json": "application/json", | |
} | |
class NotOkStatusCodeException(Exception): | |
def __init__(self, message, status_code): | |
self.message = message | |
self.status_code = status_code | |
super(NotOkStatusCodeException, self).__init__(message) | |
class HttpFetcher: | |
def __init__(self, base_url, http_protocol="https", verify=False): | |
self.base_url = "{0}://{1}".format(http_protocol, base_url) | |
self.verify = verify | |
def get(self, endpoint, headers={}, params={}): | |
response = requests.get( | |
url="{0}{1}".format(self.base_url, endpoint), | |
verify=self.verify, | |
headers=headers, | |
params=params, | |
) | |
if response.status_code != 200: | |
raise NotOkStatusCodeException(response.text, response.status_code) | |
return response | |
def post(self, endpoint, data={}, headers={}): | |
response = requests.post( | |
url="{0}{1}".format(self.base_url, endpoint), | |
data=data, | |
verify=self.verify, | |
headers=headers, | |
) | |
if response.status_code != 200: | |
raise NotOkStatusCodeException(response.text, response.status_code) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment