Flesh out basic API client

This commit is contained in:
Nick Chambers 2022-08-19 05:59:41 -05:00
parent 482fb3ecfc
commit 4ce3b38ccf
1 changed files with 24 additions and 2 deletions

View File

@ -1,3 +1,25 @@
import requests
class Client:
def __init__(self, **kwargs):
print(kwargs)
DEFAULT_ENDPOINT = "https://api.vultr.com/v2"
def __init__(self, api_key=None, endpoint=None):
self.endpoint = endpoint
if self.endpoint is None:
self.endpoint = self.DEFAULT_ENDPOINT
self.hdrs = {
"User-Agent": "Vultron",
"Authorization": f"Bearer {api_key}"
}
def get(self, *resources):
url = f"{self.endpoint}/{'/'.join(resources)}"
res = requests.get(url, headers=self.hdrs)
if res.status_code == 200:
return res.json()
else:
pass
# FIXME: raise error w/ status code here