@@ -9,12 +9,24 @@ class Vultr(object):
99
1010 def __init__ (self , api_key : Optional [str ] = None ):
1111 """
12- :param str api_key: Vultr API Key or VULTR_API_KEY environment variable
12+ :param str api_key: Vultr API Key or VULTR_API_KEY Environment Variable
1313 """
1414 self .api_key = api_key or os .getenv ("VULTR_API_KEY" )
15- self .s = requests .session ()
15+ self ._session = requests .session ()
1616 if self .api_key :
17- self .s .headers .update ({"Authorization" : f"Bearer { self .api_key } " })
17+ self ._session .headers .update ({"Authorization" : f"Bearer { self .api_key } " })
18+
19+ def get (self , url : str ):
20+ return self ._get (f"{ self .url } /{ url .lstrip ('/' )} " )
21+
22+ def post (self , url : str , ** kwargs ):
23+ return self ._post (f"{ self .url } /{ url .lstrip ('/' )} " , kwargs )
24+
25+ def patch (self , url : str , ** kwargs ):
26+ return self ._patch (f"{ self .url } /{ url .lstrip ('/' )} " , kwargs )
27+
28+ def delete (self , url : str ):
29+ return self ._delete (f"{ self .url } /{ url .lstrip ('/' )} " )
1830
1931 def list_os (self ):
2032 url = f"{ self .url } /os"
@@ -144,25 +156,25 @@ def filter_regions(regions: list, locations: list) -> list:
144156 return [d for d in regions if d ["id" ] in locations ]
145157
146158 def _get (self , url ):
147- r = self .s .get (url , timeout = 10 )
159+ r = self ._session .get (url , timeout = 10 )
148160 if not r .ok :
149161 r .raise_for_status ()
150162 return r .json ()
151163
152164 def _post (self , url , data ):
153- r = self .s .post (url , json = data , timeout = 10 )
165+ r = self ._session .post (url , json = data , timeout = 10 )
154166 if not r .ok :
155167 r .raise_for_status ()
156168 return r .json ()
157169
158170 def _patch (self , url , data ):
159- r = self .s .patch (url , json = data , timeout = 10 )
171+ r = self ._session .patch (url , json = data , timeout = 10 )
160172 if not r .ok :
161173 r .raise_for_status ()
162174 return r .json ()
163175
164176 def _delete (self , url ):
165- r = self .s .delete (url , timeout = 10 )
177+ r = self ._session .delete (url , timeout = 10 )
166178 if not r .ok :
167179 r .raise_for_status ()
168180 return None
0 commit comments