1+ import json
2+
13import requests
24
35from staxapp .config import Config
79class Api :
810 _requests_auth = None
911
12+ @classmethod
13+ def _headers (cls , custom_headers ) -> dict :
14+ headers = {
15+ ** custom_headers ,
16+ "User-Agent" : json .dumps (
17+ {
18+ "platform" : Config .platform ,
19+ "python_version" : Config .python_version ,
20+ "sdk_version" : Config .sdk_version ,
21+ }
22+ ),
23+ }
24+ return headers
25+
1026 @classmethod
1127 def _auth (cls , ** kwargs ):
1228 if not cls ._requests_auth :
@@ -27,7 +43,13 @@ def get(cls, url_frag, params={}, **kwargs):
2743 url_frag = url_frag .replace (f"/{ Config .API_VERSION } " , "" )
2844 url = f"{ Config .api_base_url ()} /{ url_frag .lstrip ('/' )} "
2945
30- response = requests .get (url , auth = cls ._auth (), params = params , ** kwargs )
46+ response = requests .get (
47+ url ,
48+ auth = cls ._auth (),
49+ params = params ,
50+ headers = cls ._headers (kwargs .get ("headers" , {})),
51+ ** kwargs ,
52+ )
3153 cls .handle_api_response (response )
3254 return response .json ()
3355
@@ -36,7 +58,13 @@ def post(cls, url_frag, payload={}, **kwargs):
3658 url_frag = url_frag .replace (f"/{ Config .API_VERSION } " , "" )
3759 url = f"{ Config .api_base_url ()} /{ url_frag .lstrip ('/' )} "
3860
39- response = requests .post (url , json = payload , auth = cls ._auth (), ** kwargs )
61+ response = requests .post (
62+ url ,
63+ json = payload ,
64+ auth = cls ._auth (),
65+ headers = cls ._headers (kwargs .get ("headers" , {})),
66+ ** kwargs ,
67+ )
4068 cls .handle_api_response (response )
4169 return response .json ()
4270
@@ -45,7 +73,13 @@ def put(cls, url_frag, payload={}, **kwargs):
4573 url_frag = url_frag .replace (f"/{ Config .API_VERSION } " , "" )
4674 url = f"{ Config .api_base_url ()} /{ url_frag .lstrip ('/' )} "
4775
48- response = requests .put (url , json = payload , auth = cls ._auth (), ** kwargs )
76+ response = requests .put (
77+ url ,
78+ json = payload ,
79+ auth = cls ._auth (),
80+ headers = cls ._headers (kwargs .get ("headers" , {})),
81+ ** kwargs ,
82+ )
4983 cls .handle_api_response (response )
5084 return response .json ()
5185
@@ -54,6 +88,12 @@ def delete(cls, url_frag, params={}, **kwargs):
5488 url_frag = url_frag .replace (f"/{ Config .API_VERSION } " , "" )
5589 url = f"{ Config .api_base_url ()} /{ url_frag .lstrip ('/' )} "
5690
57- response = requests .delete (url , auth = cls ._auth (), params = params , ** kwargs )
91+ response = requests .delete (
92+ url ,
93+ auth = cls ._auth (),
94+ params = params ,
95+ headers = cls ._headers (kwargs .get ("headers" , {})),
96+ ** kwargs ,
97+ )
5898 cls .handle_api_response (response )
5999 return response .json ()
0 commit comments