11import json
2+ from typing import Any
23
34import requests
45
6+ from shipday .exceptions import ShipdayRateLimitException
7+
58
69class ShipdayClient :
710 def __init__ (self , * args , api_key , ** kwargs , ):
@@ -21,25 +24,33 @@ def __get_api_key_(self):
2124 def __create_url_ (self , suffix : str ) -> str :
2225 return self ._base_url + suffix
2326
27+ def __check_status_ (self , response : Any ):
28+ if response .status_code == 429 :
29+ raise ShipdayRateLimitException (response .text )
30+
2431 def set_api_key (self , api_key : str ):
2532 self ._api_key = api_key
2633
2734 def get (self , suffix : str ):
2835 url = self .__create_url_ (suffix )
2936 response = requests .get (url , headers = self .__get_headers_ ())
37+ self .__check_status_ (response )
3038 return response .json ()
3139
3240 def post (self , suffix : str , data : dict ):
3341 url = self .__create_url_ (suffix )
3442 response = requests .post (url , json .dumps (data ), headers = self .__get_headers_ ())
43+ self .__check_status_ (response )
3544 return response .json ()
3645
3746 def put (self , suffix : str , data : dict ):
3847 url = self .__create_url_ (suffix )
3948 response = requests .put (url , json .dumps (data ), headers = self .__get_headers_ ())
49+ self .__check_status_ (response )
4050 return response .json ()
4151
4252 def delete (self , suffix : str ):
4353 url = self .__create_url_ (suffix )
4454 response = requests .delete (url , headers = self .__get_headers_ ())
55+ self .__check_status_ (response )
4556 return response
0 commit comments