@@ -78,7 +78,7 @@ def __init__(self, host=None, **kwargs):
7878 if kwargs .get ('connect' , True ):
7979 self .connect ()
8080
81- def setHostName (self , host ):
81+ def setHostName (self , host : str ):
8282 """Validate that the provided base URL is valid"""
8383
8484 if host is None :
@@ -136,7 +136,7 @@ def connect(self):
136136 if not self .token :
137137 self .requestToken ()
138138
139- def constructApiUrl (self , endpoint_url ) :
139+ def constructApiUrl (self , endpoint_url : str ) -> str :
140140 """Construct an API endpoint URL based on the provided API URL.
141141
142142 Arguments:
@@ -145,17 +145,7 @@ def constructApiUrl(self, endpoint_url):
145145 Returns: A fully qualified URL for the subsequent request
146146 """
147147
148- # Strip leading / character if provided
149- if endpoint_url .startswith ("/" ):
150- endpoint_url = endpoint_url [1 :]
151-
152- url = urljoin (self .api_url , endpoint_url )
153-
154- # Ensure the API URL ends with a trailing slash
155- if not url .endswith ('/' ):
156- url += '/'
157-
158- return url
148+ return urljoin (self .api_url , endpoint_url )
159149
160150 def testAuth (self ):
161151 """
@@ -169,7 +159,7 @@ def testAuth(self):
169159 return False
170160
171161 try :
172- response = self .get ('/ user/me/' )
162+ response = self .get ('user/me/' )
173163 except requests .exceptions .HTTPError as e :
174164 logger .fatal (f"Authentication error: { str (type (e ))} " )
175165 return False
@@ -254,7 +244,7 @@ def requestToken(self):
254244 # Request an auth token from the server
255245 try :
256246 response = self .get (
257- '/ user/token/' ,
247+ 'user/token/' ,
258248 params = {
259249 'name' : self .token_name ,
260250 }
@@ -273,14 +263,14 @@ def requestToken(self):
273263
274264 return self .token
275265
276- def request (self , api_url , ** kwargs ):
266+ def request (self , url : str , ** kwargs ):
277267 """ Perform a URL request to the Inventree API """
278268
279269 if not self .connected :
280270 # If we have not established a connection to the server yet, attempt now
281271 self .connect ()
282272
283- api_url = self .constructApiUrl (api_url )
273+ api_url = self .constructApiUrl (url )
284274
285275 data = kwargs .get ('data' , kwargs .get ('json' , {}))
286276 files = kwargs .get ('files' , {})
@@ -401,7 +391,7 @@ def request(self, api_url, **kwargs):
401391
402392 return response
403393
404- def delete (self , url , ** kwargs ):
394+ def delete (self , url : str , ** kwargs ):
405395 """ Perform a DELETE request. Used to remove a record in the database.
406396
407397 """
@@ -420,7 +410,7 @@ def delete(self, url, **kwargs):
420410
421411 return response
422412
423- def post (self , url , data , ** kwargs ):
413+ def post (self , url : str , data : dict , ** kwargs ):
424414 """ Perform a POST request. Used to create a new record in the database.
425415
426416 Args:
@@ -457,7 +447,7 @@ def post(self, url, data, **kwargs):
457447
458448 return data
459449
460- def patch (self , url , data , ** kwargs ):
450+ def patch (self , url : str , data : dict , ** kwargs ):
461451 """
462452 Perform a PATCH request.
463453
@@ -495,7 +485,7 @@ def patch(self, url, data, **kwargs):
495485
496486 return data
497487
498- def put (self , url , data , ** kwargs ):
488+ def put (self , url : str , data : dict , ** kwargs ):
499489 """
500490 Perform a PUT request. Used to update existing records in the database.
501491
@@ -531,7 +521,7 @@ def put(self, url, data, **kwargs):
531521
532522 return data
533523
534- def get (self , url , ** kwargs ):
524+ def get (self , url : str , ** kwargs ):
535525 """ Perform a GET request.
536526
537527 For argument information, refer to the 'request' method
@@ -633,7 +623,7 @@ def scanBarcode(self, barcode_data):
633623 barcode_data = json .dumps (barcode_data )
634624
635625 response = self .post (
636- '/ barcode/' ,
626+ 'barcode/' ,
637627 {
638628 'barcode' : str (barcode_data ),
639629 }
0 commit comments