@@ -33,7 +33,7 @@ def __init__(self, auth_service, base_url: str) -> None:
3333 self ._auth_service .authenticate ()
3434
3535 def post (self , url : str , json : dict = None , ** kwargs ) -> requests .Response :
36- """Sends a POST request.
36+ """Sends a POST request.
3737
3838 A wrapper for the requests.post method.
3939
@@ -59,16 +59,43 @@ def post(self, url: str, json: dict = None, **kwargs) -> requests.Response:
5959
6060 return response
6161
62+ def put (self , url : str , json : dict = None , ** kwargs ) -> requests .Response :
63+ """Sends a PUT request.
64+
65+ A wrapper for the requests.put method.
66+
67+ Builds the url, uses custom headers, refresh tokens if needed.
68+
69+ :param url: relative url of the API endpoint
70+ :type url: str
71+ :param json: A JSON serializable Python object to send in the body of the Request, defaults to None
72+ :type json: dict, optional
73+
74+ :raises APIException: an api exception with message and error type code
75+
76+ :return: Response object
77+ :rtype: requests.Response
78+ """
79+ url = self ._add_base_url (url )
80+ headers = self ._generate_headers ()
81+
82+ self ._refresh_token_if_expired ()
83+
84+ response = requests .put (url , json = json , headers = headers , ** kwargs )
85+ handle_error (response )
86+
87+ return response
88+
6289 def get (self , url : str , params : dict = None , ** kwargs ) -> requests .Response :
63- """Sends a GET request.
90+ """Sends a GET request.
6491
6592 A wrapper for the requests.get method.
6693
6794 Builds the url, uses custom headers, refresh tokens if needed.
6895
6996 :param url: relative url of the API endpoint
7097 :type url: str
71- :param params: Dictionary, list of tuples or bytes to send in the query string for the Request., defaults to None
98+ :param params: Dictionary, list of tuples or bytes to send in the query string for the Request. defaults to None
7299 :type params: dict, optional
73100
74101 :raises APIException: an api exception with message and error type code
@@ -87,7 +114,7 @@ def get(self, url: str, params: dict = None, **kwargs) -> requests.Response:
87114 return response
88115
89116 def delete (self , url : str , json : dict = None , ** kwargs ) -> requests .Response :
90- """Sends a DELETE request.
117+ """Sends a DELETE request.
91118
92119 A wrapper for the requests.delete method.
93120
@@ -124,7 +151,7 @@ def _refresh_token_if_expired(self) -> None:
124151 # to to refresh. if refresh token has expired, reauthenticate
125152 try :
126153 self ._auth_service .refresh ()
127- except :
154+ except Exception :
128155 self ._auth_service .authenticate ()
129156
130157 def _generate_headers (self ) -> dict :
@@ -141,7 +168,7 @@ def _generate_headers(self) -> dict:
141168 return headers
142169
143170 def _generate_bearer_header (self ) -> str :
144- """generate the authorization header Bearer string
171+ """generate the authorization header Bearer string
145172
146173 :return: Authorization header Bearer string
147174 :rtype: str
@@ -162,7 +189,7 @@ def _generate_user_agent(self) -> str:
162189 def _add_base_url (self , url : str ) -> str :
163190 """Adds the base url to the relative url
164191
165- example:
192+ example:
166193 if the relative url is '/balance'
167194 and the base url is 'https://api.datacrunch.io/v1'
168195 then this method will return 'https://api.datacrunch.io/v1/balance'
0 commit comments