UPDATE Change base URL for the McCord Museum's CollectiveAccess instance and add a new function to test and display the API endpoint URL

This commit is contained in:
Antoine 2025-05-12 16:54:24 +02:00
parent 3596cb8466
commit 5d17a97892

View File

@ -20,8 +20,8 @@ if (!defined('ABSPATH')) {
*/
function carhop_ca_api_request($endpoint, $params = array(), $method = 'GET')
{
// Base URL of the McCord Museum's CollectiveAccess instance
$base_url = 'https://collections.musee-mccord.qc.ca';
// Base URL of the McCord Stewart Museum's CollectiveAccess instance
$base_url = 'https://collections.musee-mccord-stewart.ca';
// Build the full URL
$url = trailingslashit($base_url) . 'api/' . ltrim($endpoint, '/');
@ -128,3 +128,32 @@ function carhop_test_ca_api()
// Log the results
error_log('CollectiveAccess API Test Results: ' . print_r($objects, true));
}
/**
* Test and display the API endpoint URL
*/
function carhop_test_ca_endpoint()
{
$base_url = 'https://collections.musee-mccord.qc.ca';
$endpoint = 'objects';
$params = ['limit' => 1];
$url = trailingslashit($base_url) . 'api/' . ltrim($endpoint, '/');
if (!empty($params)) {
$url = add_query_arg($params, $url);
}
echo '<div class="notice notice-info">';
echo '<p>API Endpoint URL: <code>' . esc_url($url) . '</code></p>';
// Test the connection
$response = wp_remote_get($url);
if (is_wp_error($response)) {
echo '<p>Connection Error: ' . esc_html($response->get_error_message()) . '</p>';
} else {
$status = wp_remote_retrieve_response_code($response);
echo '<p>Response Status: ' . esc_html($status) . '</p>';
}
echo '</div>';
}