@@ -6,14 +6,24 @@ class Client:
66 def __init__ (self , configuration ):
77 self .configuration = configuration
88
9- def get (self , path , params = {}):
10- r = requests .get (self .url (path ), params = params , headers = self .headers ())
9+ def get (self , path , params = {}, timeout = None ):
10+ r = requests .get (self .url (path ), params = params , headers = self .headers (), timeout = timeout )
1111 return self .handle_response (r )
1212
13- def post (self , path , payload ):
14- r = requests .post (self .url (path ), json = payload , headers = self .headers ())
13+ def post (self , path , payload , timeout = None ):
14+ r = requests .post (self .url (path ), data = payload , headers = self .headers (), timeout = timeout )
1515 return self .handle_response (r )
1616
17+ def download (self , url , path ):
18+ r = requests .get (url , stream = True , timeout = self .configuration .download_timeout )
19+
20+ with open (path , 'wb' ) as f :
21+ for chunk in r .iter_content (chunk_size = 1024 ):
22+ if chunk :
23+ f .write (chunk )
24+
25+ return path
26+
1727 def handle_response (self , r ):
1828 json = r .json ()
1929
@@ -25,7 +35,7 @@ def handle_response(self, r):
2535 return json
2636
2737 def url (self , path ):
28- return "%s/ %s?Secret=%s" % (self .configuration .base_uri , path , self .configuration .api_secret )
38+ return "%s%s?Secret=%s" % (self .configuration .base_uri , path , self .configuration .api_secret )
2939
3040 def headers (self ):
3141 return {
0 commit comments