Divided util into it's own module. Struggling with class variables and using them across many functions...

This commit is contained in:
Norm Rasmussen
2024-09-01 08:16:39 -04:00
parent e49d3d0a01
commit 10cb3e54d0
7 changed files with 95 additions and 35 deletions

View File

View File

@ -0,0 +1 @@
SANDBOX = "SlpQlju219WnWogn94dQUT6Yt"

View File

@ -0,0 +1,48 @@
import requests
import Apikeys
import pprint
PP = pprint.PrettyPrinter(indent=4)
APIKEY = Apikeys.SANDBOX
HEADERS = {"content-type": "application/json", "X-Api-Key": APIKEY}
BASEURL = "https://api.northpass.com/v2"
def get(url):
try:
get_response = requests.get(url, headers=HEADERS)
# print(f"Executed Get Request. Status code is {get_response.status_code}")
except HTTPError as h:
print(
f"Error occurred. Here's the info: {h} and status code: {get_response.status_code}"
)
finally:
json_get = get_response.json()
# PP.pprint(json_get)
return json_get
def post(url, payload):
try:
post_response = requests.post(url, headers=HEADERS, json=payload)
print(f"Executed Post Request. Status code is {get_response.status_code}")
except HTTPError as h:
print(
f"Error occurred. Here's the info: {h} and status code: {get_response.status_code}"
)
finally:
json_post = get_response.json()
# PP.pprint(json_post)
def delete(url):
try:
get_response = requests.delete(url, headers=HEADERS)
# print(f"Executed Get Request. Status code is {get_response.status_code}")
except HTTPError as h:
print(
f"Error occurred. Here's the info: {h} and status code: {get_response.status_code}"
)
finally:
return get_response