function tripal_get_remote_API_doc
3.x tripal_ws.api.inc | tripal_get_remote_API_doc($site_id) |
Retrieves the API documentation for a remote Tripal web service.
Parameters
$site_id: The numeric site ID for the remote Tripal site.
Return value
The vocabulary of a remote Tripal web service, or FALSE if an error occured.
Related topics
7 calls to tripal_get_remote_API_doc()
- tripal_get_remote_content_doc in tripal_ws/
api/ tripal_ws.api.inc - Retreive the content type information from a remote Tripal site.
- tripal_get_remote_field_doc in tripal_ws/
api/ tripal_ws.api.inc - Retrieves the field information for a content type from a remote Tripal site.
- tripal_get_remote_field_formatters in tripal_ws/
api/ tripal_ws.api.inc - Retrieves the list of download formatters for a remote field.
- tripal_get_remote_field_info in tripal_ws/
api/ tripal_ws.api.inc - Behaves similar to the field_info_field() function but for remote fields.
- tripal_get_remote_field_instance_info in tripal_ws/
api/ tripal_ws.api.inc - Behaves similar to the field_info_instance() function but for remote fields.
File
- tripal_ws/
api/ tripal_ws.api.inc, line 382 - This file provides the Tripal Web Services API: a set of functions for interacting with the Tripal Web Services.
Code
function tripal_get_remote_API_doc($site_id) {
$site_doc = '';
if (!$site_id) {
throw new Exception('Please provide a numeric site ID for the tripal_get_remote_API_doc function.');
}
$cache_name = 'trp_ws_doc_' . $site_id;
if ($cache = cache_get($cache_name)) {
return $cache->data;
}
// Get the site url from the tripal_sites table.
$remote_site = db_select('tripal_sites', 'ts')
->fields('ts')
->condition('ts.id', $site_id)
->execute()
->fetchObject();
if (!$remote_site) {
throw new Exception(t('Cannot find a remote site with id: "!id"', array('!id' => $site_id)));
}
// Build the URL to the remote web services.
$ws_version = $remote_site->version;
$ws_url = $remote_site->url;
$ws_url = trim($ws_url, '/');
$ws_url .= '/web-services/doc/' . $ws_version;
// Build and make the request.
$options =[];
$data = drupal_http_request($ws_url, $options);
if (!$data) {
tripal_report_error('tripal_ws', TRIPAL_ERROR,
t('Could not connect to the remote web service.'));
return FALSE;
}
// If the data object has an error then this is some sort of
// connection error (not a Tripal web servcies error).
if (property_exists($data, 'error')) {
tripal_report_error('tripal_ws', TRIPAL_ERROR,
'Remote web services document reports the following error: !error. Using URL: !url',
array('!error' => $error, '!url' => $ws_url));
return FALSE;
}
// We got a response, so convert it to a PHP array.
$site_doc = drupal_json_decode($data->data);
// Check if there was a Tripal Web Services error.
if (array_key_exists('error', $data)) {
$error = '</pre>' . print_r($data['error'], TRUE) . '</pre>';
tripal_report_error('tripal_ws', TRIPAL_ERROR,
'Tripal Remote web services document reports the following error: !error. Using URL: !url',
array('!error' => $error, '!url' => $ws_url));
return FALSE;
}
cache_set($cache_name, $site_doc);
return $site_doc;
}