44from typing import Literal , Optional , Union
55
66from pydantic import BaseModel , Field , ValidationError , validate_call
7- from requests import Response , delete
7+ from requests import Response
88from requests .adapters import HTTPAdapter
99from requests .sessions import Session
1010from typing_extensions import Annotated
@@ -107,30 +107,34 @@ def post(
107107 request_path : str = '' ,
108108 params : dict = None ,
109109 auth_type : Literal ['jwt' , 'basic' , 'signature' ] = 'jwt' ,
110- body_type : Literal ['json' , 'data' ] = 'json' ,
110+ sent_data_type : Literal ['json' , 'data' ] = 'json' ,
111111 ) -> Union [dict , None ]:
112- return self .make_request ('POST' , host , request_path , params , auth_type , body_type )
112+ return self .make_request (
113+ 'POST' , host , request_path , params , auth_type , sent_data_type
114+ )
113115
114116 def get (
115117 self ,
116118 host : str ,
117119 request_path : str = '' ,
118120 params : dict = None ,
119121 auth_type : Literal ['jwt' , 'basic' , 'signature' ] = 'jwt' ,
120- body_type : Literal ['json' , 'data ' ] = 'json' ,
122+ sent_data_type : Literal ['json' , 'form' , 'query_params ' ] = 'json' ,
121123 ) -> Union [dict , None ]:
122- return self .make_request ('GET' , host , request_path , params , auth_type , body_type )
124+ return self .make_request (
125+ 'GET' , host , request_path , params , auth_type , sent_data_type
126+ )
123127
124128 def patch (
125129 self ,
126130 host : str ,
127131 request_path : str = '' ,
128132 params : dict = None ,
129133 auth_type : Literal ['jwt' , 'basic' , 'signature' ] = 'jwt' ,
130- body_type : Literal ['json' , 'data ' ] = 'json' ,
134+ sent_data_type : Literal ['json' , 'form' , 'query_params ' ] = 'json' ,
131135 ) -> Union [dict , None ]:
132136 return self .make_request (
133- 'PATCH' , host , request_path , params , auth_type , body_type
137+ 'PATCH' , host , request_path , params , auth_type , sent_data_type
134138 )
135139
136140 def delete (
@@ -139,10 +143,10 @@ def delete(
139143 request_path : str = '' ,
140144 params : dict = None ,
141145 auth_type : Literal ['jwt' , 'basic' , 'signature' ] = 'jwt' ,
142- body_type : Literal ['json' , 'data ' ] = 'json' ,
146+ sent_data_type : Literal ['json' , 'form' , 'query_params ' ] = 'json' ,
143147 ) -> Union [dict , None ]:
144148 return self .make_request (
145- 'DELETE' , host , request_path , params , auth_type , body_type
149+ 'DELETE' , host , request_path , params , auth_type , sent_data_type
146150 )
147151
148152 @validate_call
@@ -153,7 +157,7 @@ def make_request(
153157 request_path : str = '' ,
154158 params : Optional [dict ] = None ,
155159 auth_type : Literal ['jwt' , 'basic' , 'signature' ] = 'jwt' ,
156- body_type : Literal ['json' , 'data ' ] = 'json' ,
160+ sent_data_type : Literal ['json' , 'form' , 'query_params ' ] = 'json' ,
157161 ):
158162 url = f'https://{ host } { request_path } '
159163 logger .debug (
@@ -174,10 +178,12 @@ def make_request(
174178 'timeout' : self ._timeout ,
175179 }
176180
177- if body_type == 'json' :
181+ if sent_data_type == 'json' :
178182 self ._headers ['Content-Type' ] = 'application/json'
179183 request_params ['json' ] = params
180- else :
184+ elif sent_data_type == 'query_params' :
185+ request_params ['params' ] = params
186+ elif sent_data_type == 'form' :
181187 request_params ['data' ] = params
182188
183189 with self ._session .request (** request_params ) as response :
0 commit comments