|
|
@@ -0,0 +1,52 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
function get_access_token() { |
|
|
|
|
|
|
|
// OPS API credentials (details at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf) |
|
|
|
$ops_url = $_ENV["OPS_URL"] . '3.2/auth/accesstoken'; |
|
|
|
$auth = base64_encode($_ENV["CONSUMER_KEY"] . ":" . $_ENV["CONSUMER_SECRET"]); |
|
|
|
|
|
|
|
// Set up API call |
|
|
|
$ch = curl_init(); |
|
|
|
curl_setopt($ch, CURLOPT_URL, $ops_url); |
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic $auth","Content-Type: application/x-www-form-urlencoded")); |
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials'); |
|
|
|
curl_setopt($ch, CURLOPT_POST, true); |
|
|
|
|
|
|
|
// Give back curl result |
|
|
|
$response = curl_exec($ch); |
|
|
|
curl_close($ch); |
|
|
|
|
|
|
|
// Turn the API response into useful Json |
|
|
|
$json = json_decode($response); |
|
|
|
$access_token = $json->access_token; |
|
|
|
|
|
|
|
return $access_token; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function get_publication_details($document_reference) { |
|
|
|
|
|
|
|
$access_token = get_access_token(); |
|
|
|
|
|
|
|
// OPS API credentials (details at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf) |
|
|
|
$ops_url = $_ENV["OPS_URL"] . 'rest-services/published-data/publication/epodoc/' . $document_reference . '/biblio'; |
|
|
|
|
|
|
|
// Set up API call |
|
|
|
$ch = curl_init(); |
|
|
|
curl_setopt($ch, CURLOPT_URL, $ops_url); |
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token")); |
|
|
|
|
|
|
|
// Give back curl result |
|
|
|
$response = curl_exec($ch); |
|
|
|
curl_close($ch); |
|
|
|
|
|
|
|
if (strpos($response,"No results found") === false ) { |
|
|
|
print_r($response); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
?> |