Flesh out basic API client
This commit is contained in:
parent
482fb3ecfc
commit
4ce3b38ccf
|
@ -1,3 +1,25 @@
|
||||||
|
import requests
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
def __init__(self, **kwargs):
|
DEFAULT_ENDPOINT = "https://api.vultr.com/v2"
|
||||||
print(kwargs)
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue