Created
September 22, 2011 10:57
-
-
Save hubgit/1234539 to your computer and use it in GitHub Desktop.
Minimal PHP class for fetching data from the Mendeley API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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