Superdesk Content API PHP SDK
, (*1)
This is an SDK written in PHP for the Superdesk Content API., (*2)
For more information about the Superdesk Content API please read the documentation., (*3)
Installation
Requirements
When using the CurlApiClient and CurlClient classes make sure you've installed
the following PHP extensions:
* cURL
* Multibyte String, (*4)
Composer
- Require the SDK as a composer dependency
$ php composer.phar require superdesk/contentapi-sdk-php
Manual
- Download a copy of the SDK
- Add the classes to your autoloader
Customization
You can use your own client classes instead of
CurlClient and
CurlApiClient files.
This is for example useful if your framework or project already has it's own
http client, you can easily incorporate that without having multiple
depencencies.
All you need to do is to implement the
ClientInterface and
ClientApiInterface.
For the ClientApi class there also a useful abstract class
AbstractApiClient
which contains some sane defaults., (*5)
Examples
This example uses the CurlClient
and CurlApiClient files., (*6)
You can run the example.php via the cli
with the command:, (*7)
$ php sample/default-client/example.php
Make sure you have the extenions cURL and Multibyte String enabled and
you've installed the vendors., (*8)
$ php composer.phar install --no-dev
Samples
Authentication
OAuth username and password authentication. The
CurlApiClient
will automatically try to retrieve new access token if the previous token has
been invalited., (*9)
setClientId(API_CLIENT_ID)
->setUsername(API_USERNAME)
->setPassword(API_PASSWORD);
$apiClient = new CurlApiClient($genericClient, $authentication);
$contentApi = new ContentApiSdk($apiClient, API_HOST, API_PORT, API_PROTOCOL);
?>
Pagination and traversing through results
We use Pagerfanta as a pagination
library. All results returned from the methods getItems(...) and
getPackages(...) are actually Pagerfanta instances. That should make it easy
enough to traverse through your API results and also built in your own pagination., (*10)
getItems(array(), $startPage, $maxPerPage);
$items->getNbResults(); // Total items
$items->getMaxPerPage(); // Max results per age == $maxPerPage
$items->getNbPages(); // Total pages
?>