Skip to content

Instantly share code, notes, and snippets.

@hubgit
Created September 22, 2011 10:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hubgit/1234539 to your computer and use it in GitHub Desktop.
Save hubgit/1234539 to your computer and use it in GitHub Desktop.
Minimal PHP class for fetching data from the Mendeley API
<?php
// register at http://dev.mendeley.com/applications/
define('MENDELEY_CONSUMER_KEY', ''); // edit this
class Mendeley {
static function fetch($path, $params = array()) {
$default = array('consumer_key' => MENDELEY_CONSUMER_KEY);
$url = 'http://api.mendeley.com/oapi/' . $path . '?' . http_build_query($params + $default);
return json_decode(file_get_contents($url), true);
}
// http://apidocs.mendeley.com/home/public-resources/search-details
static function document($id, $type = null) {
if ($type == 'doi') $id = str_replace('/', '%2F', $id); // workaround
return self::fetch('documents/details/' . rawurlencode($id), array('type' => $type));
}
// http://apidocs.mendeley.com/home/public-resources/public-groups-details
static function group($id, $section = 'main') {
return self::fetch('documents/groups/' . rawurlencode($id));
}
}
$data = Mendeley::document('10.1038/nchem.1140', 'doi'); // an example DOI
print_r($data);
$data = Mendeley::group(630791); // an example group ID
print_r($data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment