function tripal_get_remote_content
3.x tripal_ws.api.inc | tripal_get_remote_content($site_id, $path = '', $query = '') |
Makes a request to the "content" service of a remote Tripal web site.
Parameters
$site_id: The numeric site ID for the remote Tripal site.
$path: The web service path for the content (excluding 'web-servcies/vX.x/content'). To retrieve the full content listing leave this paramter empty.
$query: An query string to appear after the ? in a URL.
Return value
The JSON response formatted in a PHP array or FALSE if a problem occured.
Related topics
3 calls to tripal_get_remote_content()
- remote__data::makeRemoteRequest in tripal_ws/
includes/ TripalFields/ remote__data/ remote__data.inc - Makes a request to a remote Tripal web services site.
- tripal_load_remote_entities in tripal_ws/
api/ tripal_ws.api.inc - Queries a remote site for an array of bulk entity ids.
- tripal_load_remote_entity in tripal_ws/
api/ tripal_ws.api.inc - Queries a remote site for an entity.
File
- tripal_ws/
api/ tripal_ws.api.inc, line 214 - This file provides the Tripal Web Services API: a set of functions for interacting with the Tripal Web Services.
Code
function tripal_get_remote_content($site_id, $path = '', $query = '') {
if (!$site_id) {
throw new Exception('Please provide a numeric site ID for the tripal_get_remote_content function.');
}
// Fetch the record for this site id.
$remote_site = db_select('tripal_sites', 'ts')
->fields('ts')
->condition('ts.id', $site_id)
->execute()
->fetchObject();
if (!$remote_site) {
tripal_report_error('tripal_ws', TRIPAL_ERROR,
t('Could not find a remote tripal site using the id provided: !id.',
array('!id' => $site_id)));
return FALSE;
}
// 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/content/' . $ws_version . '/' . $path;
// Build the Query and make and substitions needed.
if ($query) {
$ws_url = $ws_url . '?' . $query;
}
// TODO: something is wrong here, the query is not being recognized on
// the remote Tripal site. It's just returning the default.
$data = drupal_http_request($ws_url);
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 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.
$data = 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 reports the following error: !error. Using URL: !url',
array('!error' => $error, '!url' => $ws_url));
return FALSE;
}
return $data;
}