Skip to content

Instantly share code, notes, and snippets.

@SimonXIX
Created July 26, 2019 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonXIX/c03b438b15270a4bf3e874df320ae17c to your computer and use it in GitHub Desktop.
Save SimonXIX/c03b438b15270a4bf3e874df320ae17c to your computer and use it in GitHub Desktop.
Testing the EPrints RESTful API for Users
<?php
# @name: eprints_rest.php
# @version: 0.1
# @creation_date: 2019-07-22
# @license: The MIT License <https://opensource.org/licenses/MIT>
# @author: Simon Bowie <sb174@soas.ac.uk>
# @purpose: Testing the EPrints RESTful API
?>
<?php
$baseurl = 'xxxxxxxx';
$service = 'user';
$user_id = 'xxxxxxxx';
$function = 'ref_category.xml';
$username = 'xxxxxxxx';
$password = 'xxxxxxxx';
$fullurl = 'http://' . $baseurl . '/' . $service . '/' . $user_id . '.xml';
#GET using cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fullurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERPWD, urlencode($username) . ':' . urlencode($password));
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$response = curl_exec($ch);
if (!curl_exec($ch)) {
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
curl_close($ch);
$result = new SimpleXMLElement($response);
print_r($response);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment