Wiki
Clone wikirestclient-php / Home
PHP library restclient-php
Features:
- Full-featured that means the client supports the whole functionality of the API.
- contains a model such that it is convenient for you to work with the data.
- supports Basic Auth as well as OAuth authentication methods.
- easy to integrate in your PHP App, since we have used composer, a powerful tool in order to integrate and autoload requirements of 3rd party software.
- outputs a fetched set of publications as a CSL-rendered publication list in your favorite citation style.
Basic Usage
Installation via Composer
Install composer to your project root folder:
$ curl -sS https://getcomposer.org/installer | php
Run composer and initialize your project.
$ php composer.phar init
Follow the prompt and define a package name, description, and author. When you'll be asked for dependencies type academicpuma/restclient-php
and choose the latest version. After finishing the initalization composer creates a composer.json
configuration file in the project root folder.
In order to fetch the dependencies and to get an autoload file run the following line in your terminal:
$ php composer.phar update
Composer creates a vendor
folder including the autoload.php
file and all the depended packages.
Now you can start developing!
Create an Accessor
The Accessor
object is required to authenticate your App on the REST API of PUMA/BibSonomy. You can choose between two authentication methods, Basic Auth or OAuth. For Basic Auth this would be:
<?php require 'path/to/vendor/autoload.php'; use AcademicPuma\RestClient\Accessor\BasicAuthAccessor; $accessor = new BasicAuthAccessor('http://www.bibsonomy.org', 'your-username', 'your-apikey'); ?>
Using an OAuth Accessor is more complicated. An detailed description you can find here.
Use the RESTClient
The next step is getting an instance of the REST Client:
<?php use AcademicPuma\RestClient\RESTClient; use AcademicPuma\RestClient\Config; $restClient = new RESTClient($accessor); ?>
<?php //choose Resource type and tags $restClient->getPosts(Config\Resourcetype::BIBTEX, Config\Grouping::USER, 'username', ['tag1', 'tag2']); ?>
<?php //output xml echo $restClient->xml(); //output CSL echo json_encode($restClient->csl()); //use the model $posts = $restClient->model(); foreach($posts as $post) { echo $post->getResource()->getTitle()."<br />\n"; } //print a bibliography in your preferred style and language echo $restClient->bibliography('apa', 'en-US'); ?>
If your request aims to fetch a document in order to provide it as a download you have to do the following steps:
<?php $restClient->getDocumentFile($userName, $resourceHash, $fileName, Config\DocumentType::FILE); header("Content-Disposition: attachment; filename=" . $fileName); print $restClient->file()->getContents(); ?>
Advanced Usage
- Web Tutorial
- Learn how to request GET, POST, PUT and DELETE queries
- How to use OAuth
- Advanced functionality (bibliography, calucualte hashes)
- Setup a Developer Workspace
Updated