various improvements to make release 1 complete
This commit is contained in:
@@ -9,6 +9,7 @@ class Swi_Foot_API
|
||||
private $verein_id;
|
||||
private $season_id;
|
||||
private $cache_duration;
|
||||
private $language;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -18,6 +19,7 @@ class Swi_Foot_API
|
||||
$this->verein_id = get_option('swi_foot_verein_id');
|
||||
$this->season_id = get_option('swi_foot_season_id', date('Y'));
|
||||
$this->cache_duration = get_option('swi_foot_match_cache_duration', 30);
|
||||
$this->language = get_option('swi_foot_api_language', '1');
|
||||
|
||||
// AJAX actions were migrated to REST endpoints (see includes/class-swi-foot-rest.php)
|
||||
|
||||
@@ -176,6 +178,7 @@ class Swi_Foot_API
|
||||
$response = wp_remote_get($url, array(
|
||||
'headers' => array(
|
||||
'X-User-Token' => $token,
|
||||
'X-User-Language' => $this->language,
|
||||
'Content-Type' => 'application/json'
|
||||
),
|
||||
'timeout' => 30
|
||||
@@ -204,7 +207,13 @@ class Swi_Foot_API
|
||||
if ($response_code !== 200) {
|
||||
$body_debug = wp_remote_retrieve_body($response);
|
||||
error_log('Swiss Football API: Request to ' . $url . ' returned ' . $response_code . ' - body: ' . substr($body_debug, 0, 1000));
|
||||
return new WP_Error('api_error', 'API request failed with code ' . $response_code);
|
||||
|
||||
// Handle 406 Not Acceptable - data not yet available
|
||||
if ($response_code === 406) {
|
||||
return new WP_Error('data_not_available', 'Data not yet available', array('status_code' => 406));
|
||||
}
|
||||
|
||||
return new WP_Error('api_error', 'API request failed with code ' . $response_code, array('status_code' => $response_code));
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body($response);
|
||||
@@ -348,6 +357,11 @@ class Swi_Foot_API
|
||||
return $this->api_request('/api/match/' . $match_id . '/events');
|
||||
}
|
||||
|
||||
public function get_match_referees($match_id)
|
||||
{
|
||||
return $this->api_request('/api/match/' . $match_id . '/referees');
|
||||
}
|
||||
|
||||
public function get_team_picture($team_id)
|
||||
{
|
||||
// Special handling for team picture endpoint which returns 200 with data or 204 No Content
|
||||
@@ -364,6 +378,7 @@ class Swi_Foot_API
|
||||
$response = wp_remote_get($url, array(
|
||||
'headers' => array(
|
||||
'X-User-Token' => $token,
|
||||
'X-User-Language' => $this->language,
|
||||
'Content-Type' => 'application/json'
|
||||
),
|
||||
'timeout' => 30
|
||||
@@ -410,9 +425,9 @@ class Swi_Foot_API
|
||||
return $body;
|
||||
}
|
||||
|
||||
public function get_commons_ids()
|
||||
public function get_common_ids($params = array())
|
||||
{
|
||||
return $this->api_request('/api/commons/ids');
|
||||
return $this->api_request('/api/common/ids', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,17 +456,54 @@ class Swi_Foot_API
|
||||
*/
|
||||
public function test_connection()
|
||||
{
|
||||
// Actually test the connection by making an API request
|
||||
$result = $this->api_request('/api/teams', array('vereinId' => $this->verein_id));
|
||||
|
||||
// Check if the request was successful (not an error)
|
||||
if (is_wp_error($result)) {
|
||||
error_log('Swiss Football API: Connection test failed - ' . $result->get_error_message());
|
||||
return false;
|
||||
// First, check if credentials are configured
|
||||
if (empty($this->username) || empty($this->password)) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'API credentials not configured',
|
||||
'details' => 'Please configure API Username and Password in Settings → Swiss Football'
|
||||
);
|
||||
}
|
||||
|
||||
// Check if Verein ID is configured
|
||||
if (empty($this->verein_id)) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'Verein ID (Club ID) not configured',
|
||||
'details' => 'Please configure Verein ID in Settings → Swiss Football'
|
||||
);
|
||||
}
|
||||
|
||||
// Verify we got a response (array means success)
|
||||
return is_array($result);
|
||||
// Test connection using the /api/common/ids endpoint with required parameters
|
||||
$result = $this->get_common_ids(array(
|
||||
'ClubId' => $this->verein_id,
|
||||
'Language' => 1 // 1 = German
|
||||
));
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
$error_msg = $result->get_error_message();
|
||||
error_log('Swiss Football API: Connection test failed - ' . $error_msg);
|
||||
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'API connection failed',
|
||||
'details' => $error_msg
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_array($result)) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'Invalid API response',
|
||||
'details' => 'The API returned unexpected data format'
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => true,
|
||||
'error' => null,
|
||||
'details' => 'Connection successful!'
|
||||
);
|
||||
}
|
||||
|
||||
public function get_current_match($team_id)
|
||||
|
||||
Reference in New Issue
Block a user