345
This commit is contained in:
@@ -316,8 +316,21 @@ class Igny8API {
|
||||
* @return array Response data
|
||||
*/
|
||||
public function post($endpoint, $data, $max_retries = 3) {
|
||||
if (!$this->is_authenticated()) {
|
||||
return array('success' => false, 'error' => 'Not authenticated', 'http_status' => 401);
|
||||
// Special case: test-connection endpoint allows API key in request body
|
||||
// So we don't require pre-authentication for this endpoint
|
||||
$is_test_connection = (strpos($endpoint, 'test-connection') !== false);
|
||||
$has_api_key_in_data = !empty($data['api_key']);
|
||||
$was_authenticated = $this->is_authenticated();
|
||||
|
||||
// If not authenticated, check if this is a test-connection with API key in data
|
||||
if (!$was_authenticated) {
|
||||
if ($is_test_connection && $has_api_key_in_data) {
|
||||
// Temporarily set the API key for this request
|
||||
$temp_api_key = $this->access_token;
|
||||
$this->access_token = $data['api_key'];
|
||||
} else {
|
||||
return array('success' => false, 'error' => 'Not authenticated', 'http_status' => 401);
|
||||
}
|
||||
}
|
||||
// Ensure endpoint starts with /v1
|
||||
if (strpos($endpoint, '/v1/') === false) {
|
||||
@@ -366,10 +379,18 @@ class Igny8API {
|
||||
}
|
||||
|
||||
// Not throttled or max retries reached, return response
|
||||
// Restore original access token if we temporarily set it
|
||||
if ($is_test_connection && $has_api_key_in_data && !$was_authenticated) {
|
||||
$this->access_token = isset($temp_api_key) ? $temp_api_key : null;
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
||||
// Should never reach here, but return last response if we do
|
||||
// Restore original access token if we temporarily set it
|
||||
if ($is_test_connection && $has_api_key_in_data && !$was_authenticated) {
|
||||
$this->access_token = isset($temp_api_key) ? $temp_api_key : null;
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user