function getAccessToken() { $mendeley = new Mendeley(); if ($mendeley->getAccessToken()) { echo 'Success! You now have your access token. Please be sure that all tests are working: <a href="' . 'tests/all_tests.php">run tests</a>. (You need simpletest installed to run them)'; } }
function testArrayKeysRecursive() { $mendeley = new Mendeley(); $itemsPerPage = 2; $collection = $mendeley->getCollection('164791', array('items' => $itemsPerPage)); $this->assertEqual(count($collection->documents), $itemsPerPage); $info = MendeleyUtil::arrayKeysRecursive($collection->documents); $this->assertTrue(count($info) > 5); }
function testMendeleyWithCustomConstructorWorks() { $consumer = Configuration::getConsumer(); $mendeley = new Mendeley($consumer['key'], $consumer['secret']); $groupId = 164791; $url = 'groups/' . $groupId; $params = array('page' => 1, 'items' => 1); $result = $mendeley->get($url, $params); $this->assertEqual((int) $result->group_id, $groupId); }
function testUploadToMendeley() { $node = self::nodeFactory(); $biblioDoc = MendeleyBiblioDoc::constructWithNode($node); $mendeley = new Mendeley(); $response = $mendeley->post('documents', $biblioDoc->toParams()); $this->assertTrue(isset($response->document_id) && is_numeric($response->document_id)); $doc = $mendeley->get('documents/' . $response->document_id); $this->assertEqual($node->title, $doc->title); $this->assertEqual($node->biblio_type, MendeleyBiblioDoc::mendeleyToBiblioType($doc->type)); $this->assertEqual($node->taxonomy['taxonomy_term_1']['title'], $doc->tags[0]); $this->assertEqual($node->taxonomy['taxonomy_term_2']['title'], $doc->tags[1]); $this->assertEqual($node->biblio_contributors[MendeleyBiblioDoc::BIBLIO_AUTHOR][0]['name'], trim(implode(' ', array($doc->authors[0]->forename, $doc->authors[0]->surname)))); $this->assertEqual($node->biblio_contributors[MendeleyBiblioDoc::BIBLIO_AUTHOR][1]['name'], trim(implode(' ', array($doc->authors[1]->forename, $doc->authors[1]->surname)))); $this->assertEqual($node->biblio_abst_e, $doc->abstract); }
<?php ########################################################## # Testeley - Testing the Mendeley API # # Script: group.php # # Takes a group id and displays the contained documents. # # HS 2011-06-15 ########################################################## require_once 'config.inc.php'; require_once 'functions.inc.php'; require_once 'Mendeley.php'; $mendeley = new Mendeley(API_KEY); if (isset($_GET['gid']) && $_GET['gid'] != "") { $gid = $_GET['gid']; is_mendeley_group_id($gid) or die('invalid gid'); if (isset($_GET['format']) && $_GET['format'] == "raw") { $json = $mendeley->fetch_docs_in_group($gid); format_json($json); } else { $uuids = $mendeley->get_uuids_in_group($gid); if (count($uuids) == 0) { echo 'No documents found'; link_home(); } else { html_header(); link_home(); echo '<h3>Documents in group ' . $gid . '</h3>'; foreach ($uuids as $uuid) {
/** * Find for all papers in the local database the related papers and add them to the database. * Warning: This function does a lot of API calls. */ function expand() { $mendeley = new Mendeley(API_KEY); $docs_in_db = $this->get_all_papers(); foreach ($docs_in_db as $doc) { $uuid1 = $doc->uuid; $uuids = $mendeley->get_related_uuids($uuid1); foreach ($uuids as $uuid2) { if (!$this->in_db($uuid2)) { $paper2 = $mendeley->get_document($uuid2); $this->to_db($paper2); } if (!$this->sim_in_db($uuid1, $uuid2)) { $this->sim_to_db($uuid1, $uuid2); //echo '.'; //flush(); } } //echo '<br>'; //flush(); } }
<?php ########################################################## # Testeley - Testing the Mendeley API # # Script: author.php # # Takes a uuid and displays related documents. # # HS 2011-06-28 ########################################################## require_once 'config.inc.php'; require_once 'functions.inc.php'; require_once 'Mendeley.php'; $mendeley = new Mendeley(API_KEY); if (isset($_GET['author']) && $_GET['author'] != "") { $author = $_GET['author']; if (strlen($author) > 30 || strpos($author, "<") !== false || strpos($author, ">") !== false) { die('invalid author'); } if (isset($_GET['format']) && $_GET['format'] == "raw") { $json = $mendeley->fetch_docs_by_author($author); format_json($json); } else { $uuids = $mendeley->get_uuids_by_author($author); if (count($uuids) == 0) { echo 'No documents found'; link_home(); } else { html_header(); echo '<h3>Documents for author ' . $author . '</h3>';
<?php ########################################################## # Testeley - Testing the Mendeley API # # Script: details.php # # Takes a UUID and displays the document details. # # HS 2011-06-15 ########################################################## require_once 'config.inc.php'; require_once 'functions.inc.php'; require_once 'Mendeley.php'; require_once 'LitDb.php'; $mendeley = new Mendeley(API_KEY); if (isset($_GET['uuid']) && $_GET['uuid'] != "") { $uuid = $_GET['uuid']; is_uuid($uuid) or die('invalid uuid'); if (isset($_GET['format']) && $_GET['format'] == "raw") { $json = $mendeley->fetch_details($uuid); format_json($json); } else { html_header(); link_home(); $paper = $mendeley->get_document($uuid); $paper->format_html(); $db = new LitDb(DB_PATH); if ($db->in_db($paper->uuid)) { echo '</p>Paper already in DB</p>'; } else {
/** * Instantiates a Mendeley Document by its internal document id * * This almost an exact copy of @see MendeleyDoc::constructWithDocumentId because get_called_class is only available in PHP >= 5.3 * * @param string $documentId * sent by Mendeley in e.g. collections/*collectionId* */ public static function constructWithDocumentId($documentId) { $that = new MendeleyBiblioDoc(); $mendeley = new Mendeley(); if ($remote = $mendeley->get('documents/' . $documentId)) { $localParams = array_keys(get_object_vars($that)); $remoteParams = array_keys(get_object_vars($remote)); $match = array_intersect($localParams, $remoteParams); foreach ($match as $name) { if (!empty($remote->{$name})) { $that->{$name} = $remote->{$name}; } } $that->documentId = $documentId; } // authors are stored as objects in Mendeley and as strings in Biblio if (isset($that->authors)) { foreach ($that->authors as &$a) { $a = implode(' ', array($a->forename, $a->surname)); } } return $that; }
<?php ########################################################## # Testeley - Testing the Mendeley API # # Script: related.php # # Takes a uuid and displays related documents. # # HS 2011-06-15 ########################################################## require_once 'config.inc.php'; require_once 'functions.inc.php'; require_once 'Mendeley.php'; require_once 'LitDb.php'; $mendeley = new Mendeley(API_KEY); if (isset($_GET['uuid']) && $_GET['uuid'] != "") { $uuid = $_GET['uuid']; is_uuid($uuid) or die('invalid uuid'); if (isset($_GET['format']) && $_GET['format'] == "raw") { $json = $mendeley->fetch_related($uuid); format_json($json); } else { html_header(); $uuids = $mendeley->get_related_uuids($uuid); if (count($uuids) == 0) { echo 'No documents found'; link_home(); } else { $paper = $mendeley->get_document($uuid); $db = new LitDb(DB_PATH);
<?php require __DIR__ . '/classes/Mendeley.php'; $mendeley = new Mendeley(); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>DocNotes</title> <style> body { font-family: Helvetica, Arial, sans-serif; } th, td { text-align: left; vertical-align: top; padding: 2px 5px; } li { margin-bottom: 1em; } .citation { color: green; } </style> </head> <body> <? if ($collection = $_GET['collection']): ?> <? $docs = $mendeley->http('library/collections/' . urlencode($collection)); $items = array(); foreach ($docs['document_ids'] as $id){ $doc = $mendeley->http('library/documents/' . $id); if (!$doc['notes']) continue; $doc['id'] = $id; $items[] = $doc; }
/** * Instantiate a Mendeley Document by its internal document id * * @param string $documentId * sent by Mendeley in e.g. collections/*collectionId* */ public static function constructWithDocumentId($documentId) { $that = new MendeleyDoc(); $mendeley = new Mendeley(); if ($remote = $mendeley->get('documents/' . $documentId)) { $localParams = array_keys(get_object_vars($that)); $remoteParams = array_keys(get_object_vars($remote)); $match = array_intersect($localParams, $remoteParams); foreach ($match as $name) { if (!empty($remote->{$name})) { $that->{$name} = $remote->{$name}; } } $that->documentId = $documentId; } return $that; }