Wiki

Clone wiki

restclient-php / Basic Requests

Requests and Models

The most API requests need a couple of parameters that specify what exactly the API should do.

GET Requests

An example: If you like to get posts you have to determine which kind of resources you want to get: Bookmarks (URLs) or Bibtex (publications). Also, you have to deliver the owner (e. g. user or group) from whose collection you want to get that posts.

<?php

use AcademicPuma\RestClient\Config;

$posts = $restClient->getPosts(Config\Resourcetype::BOOKMARK, Config\Grouping::USER, "some_username")->model();

// Get the title of the first received bookmark:
$bookmarkTitle = $posts[0]->getResource()->getTitle();

?>

PUT Requests

In order to update a concept transmit a model object to the method and the name of the user who is holding the concept. The model object needs the name of the concept you want to update.

<?php

use AcademicPuma\RestClient\Model;

// Create a concept Model-Object:
$subTag = new Model\Tag();
$subTag->setName('SubTag');

$tag = new Model\Tag();
$tag->setName("NewConceptName");
$tag->addSubTag($subTag);

$restClient->updateConcept($tag, "UserName");

?>

POST Requests

In most cases you're going to create posts directly. Posts already containing users, visibility groups and tags, so you don't need to create those separatly.

Have a look at the following example:

<?php

use AcademicPuma\RestClient\Model;
$userName = '' // define Post owner's userName

// initialize user
$user = new Model\User();
$user->setName($userName); 

// initialize tag
$tag = new Model\Tag();
$tag->setName($this->tagName);

// initialize visibility group.
$group = new Model\Group();
$group->setName('public');

// initialize bookmark.
$bookmark = new Model\Bookmark();
$bookmark->setTitle('REST Client Repository');
$bookmark->setUrl('https://bitbucket.org/bibsonomy/restclient-php');

// initialize post
$post = new Model\Post();
$post->setUser($user);
$post->addTag($tag);
$post->setDescription('Sources of the restclient-php library');
$post->setResource($bookmark);
$post->setGroup($group);

// submit the request
$restClient->createPosts($post, $userName);
?>
Similarly, you can create Concepts, UserRelationships and Documents.

If you want to attach a Document to an existing Publication Post, try the following:

<?php
$filePath = '/full/path/to/File.pdf';
$restClient->createDocument($filePath, $post->getResource()->getIntraHash(), $post->getUser()->getName());
?>

DELETE Request

You want to delete something? No problem:

<?php

$fileName = $somePost->getDocuments()[0]->getFilename();
$resourceHash = $somePost->getResource()->getIntrahash();

$restClient->deleteDocument("MyUserName", $resourceHash, $fileName);

?>

Updated