ciyidogan commited on
Commit
ec380a0
·
verified ·
1 Parent(s): 5d1ab39

Update api_executor.py

Browse files
Files changed (1) hide show
  1. api_executor.py +46 -0
api_executor.py CHANGED
@@ -187,6 +187,7 @@ def call_api(api: APIConfig, session: Session) -> requests.Response:
187
  # Execute with retry
188
  retry_count = api.retry.retry_count if api.retry else 0
189
  last_error = None
 
190
 
191
  for attempt in range(retry_count + 1):
192
  try:
@@ -204,6 +205,51 @@ def call_api(api: APIConfig, session: Session) -> requests.Response:
204
 
205
  response.raise_for_status()
206
  log(f"✅ API call successful: {api.name} ({response.status_code})")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  return response
208
 
209
  except requests.exceptions.Timeout as e:
 
187
  # Execute with retry
188
  retry_count = api.retry.retry_count if api.retry else 0
189
  last_error = None
190
+ response = None
191
 
192
  for attempt in range(retry_count + 1):
193
  try:
 
205
 
206
  response.raise_for_status()
207
  log(f"✅ API call successful: {api.name} ({response.status_code})")
208
+
209
+ # Response mapping işlemi - başarılı her response için
210
+ if response.status_code in (200, 201, 202, 204) and hasattr(api, 'response_mappings') and api.response_mappings:
211
+ try:
212
+ # 204 No Content durumunda JSON parse etmeye çalışma
213
+ if response.status_code != 204 and response.content:
214
+ response_json = response.json()
215
+
216
+ for mapping in api.response_mappings:
217
+ var_name = mapping.get('variable_name')
218
+ var_type = mapping.get('type', 'str')
219
+ json_path = mapping.get('json_path')
220
+
221
+ if not all([var_name, json_path]):
222
+ continue
223
+
224
+ # JSON path'ten değeri al
225
+ value = response_json
226
+ for path_part in json_path.split('.'):
227
+ if isinstance(value, dict):
228
+ value = value.get(path_part)
229
+ if value is None:
230
+ break
231
+
232
+ if value is not None:
233
+ # Type conversion
234
+ if var_type == 'int':
235
+ value = int(value)
236
+ elif var_type == 'float':
237
+ value = float(value)
238
+ elif var_type == 'bool':
239
+ value = bool(value)
240
+ elif var_type == 'date':
241
+ # ISO format'ta sakla
242
+ value = str(value)
243
+ else: # str
244
+ value = str(value)
245
+
246
+ # Session'a kaydet
247
+ session.variables[var_name] = value
248
+ log(f"📝 Mapped response value: {var_name} = {value}")
249
+
250
+ except Exception as e:
251
+ log(f"⚠️ Response mapping error: {e}")
252
+
253
  return response
254
 
255
  except requests.exceptions.Timeout as e: