@@ -163,52 +163,32 @@ def _format_request_data(
163
163
path : str ,
164
164
data : Optional [Dict [str , Any ]],
165
165
params : Optional [Dict [str , Any ]],
166
- http_method : str ,
167
166
) -> Tuple [str , str , Optional [Dict [str , Any ]]]:
168
167
if path .startswith (f"{ self .api_endpoint } /{ self .api_version } " ):
169
168
url = path
170
169
else :
171
170
url = f"{ self .api_endpoint } /{ self .api_version } /{ path } "
172
171
173
- params = params or {}
174
- data = data or {}
175
- params , data = self ._build_request_params_and_data (params , data , http_method )
176
-
177
- querystring = generate_querystring (params )
178
- if querystring :
179
- url += "?" + querystring
180
- params = None
181
-
182
172
payload = ""
183
173
if data is not None :
184
174
try :
185
175
payload = json .dumps (data )
186
176
except TypeError as err :
187
177
raise RequestSetupError (f"Error encoding data into JSON: { err } ." )
188
178
189
- return url , payload , params
179
+ if params is None :
180
+ params = {}
181
+ if self .testmode and "testmode" not in params :
182
+ if not (self .api_key .startswith ("access_" ) or hasattr (self , "_oauth_client" )):
183
+ raise RequestSetupError ("Configuring testmode only works with access_token or OAuth authorization" )
184
+ params ["testmode" ] = "true"
190
185
191
- def _is_valid_testmode (self ):
192
- """Check if the testmode can be configured."""
193
- if not self .api_key .startswith ("access_" ) and not hasattr (self , "_oauth_client" ):
194
- raise RequestSetupError ("Configuring testmode only works with access_token or OAuth authorization" )
195
-
196
- def _build_request_params_and_data (
197
- self , params : Dict [str , Any ], data : Dict [str , Any ], http_method : str
198
- ) -> Tuple [Dict [str , Any ], Dict [str , Any ]]:
199
- if http_method == "GET" :
200
- if self .testmode and "testmode" not in params :
201
- self ._is_valid_testmode ()
202
- params ["testmode" ] = "true"
203
- else :
204
- if self .testmode and "testmode" not in data :
205
- self ._is_valid_testmode ()
206
- data ["testmode" ] = "true"
207
- if "testmode" in params :
208
- self ._is_valid_testmode ()
209
- testmode = params .pop ("testmode" )
210
- data ["testmode" ] = testmode
211
- return params , data
186
+ querystring = generate_querystring (params )
187
+ if querystring :
188
+ url += "?" + querystring
189
+ params = None
190
+
191
+ return url , payload , params
212
192
213
193
def _perform_http_call_apikey (
214
194
self ,
@@ -226,7 +206,7 @@ def _perform_http_call_apikey(
226
206
self ._client .verify = True
227
207
self ._setup_retry ()
228
208
229
- url , payload , params = self ._format_request_data (path , data , params , http_method )
209
+ url , payload , params = self ._format_request_data (path , data , params )
230
210
try :
231
211
headers = {
232
212
"Accept" : "application/json" ,
@@ -260,7 +240,7 @@ def _perform_http_call_oauth(
260
240
params : Optional [Dict [str , Any ]] = None ,
261
241
idempotency_key : str = "" ,
262
242
) -> requests .Response :
263
- url , payload , params = self ._format_request_data (path , data , params , http_method )
243
+ url , payload , params = self ._format_request_data (path , data , params )
264
244
try :
265
245
headers = {
266
246
"Accept" : "application/json" ,
0 commit comments