26 lines
586 B
Python
26 lines
586 B
Python
import requests
|
|
|
|
class Client:
|
|
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
|