GithubHelp home page GithubHelp logo

contentapi-sdk-php's Introduction

Superdesk Content API PHP SDK

Build Status Scrutinizer Code Quality Code Climate SensioLabsInsight

This is an SDK written in PHP for the Superdesk Content API.

For more information about the Superdesk Content API please read the documentation.

Installation

Requirements

  • PHP >= 5.3

When using the CurlApiClient and CurlClient classes make sure you've installed the following PHP extensions:

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.

Examples

This example uses the CurlClient and CurlApiClient files.

You can run the example.php via the cli with the command:

$ php sample/default-client/example.php

Make sure you have the extenions cURL and Multibyte String enabled and you've installed the vendors.

$ 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.

<?php

use Superdesk\ContentApiSdk\ContentApiSdk;
use Superdesk\ContentApiSdk\Client\CurlClient;
use Superdesk\ContentApiSdk\Client\CurlApiClient;
use Superdesk\ContentApiSdk\Api\Authentication\OAuthPasswordAuthentication;

$genericClient = new CurlClient();
$authentication = new OAuthPasswordAuthentication($genericClient);
$authentication
    ->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.

<?php

use Superdesk\ContentApiSdk\ContentApiSdk;

$contentApi = new ContentApiSdk(...);

$maxPerPage = 1;
$startPage = 1;

$items = $contentApi->getItems(array(), $startPage, $maxPerPage);

$items->getNbResults(); // Total items
$items->getMaxPerPage(); // Max results per age == $maxPerPage
$items->getNbPages(); // Total pages

?>

contentapi-sdk-php's People

Contributors

m038 avatar scrutinizer-auto-fixer avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

contentapi-sdk-php's Issues

[Insight] Object parameters should be type hinted - in src/…/ContentApiSdk/ContentApiSdk.php, line 172

in src/Superdesk/ContentApiSdk/ContentApiSdk.php, line 172

The parameter package, which is an object, should be typehinted.

     *
     * @param Package $package A package
     *
     * @return stdClass List of associations
     */
    private function getAssociationsFromPackage($package)
    {
        $associations = new stdClass();

        if (isset($package->associations)) {
            foreach ($package->associations as $associatedName => $associatedItem) {

Posted from SensioLabsInsight

[Insight] Missing use statement should be avoided - in src/…/Client/FileGetContentsClient.php, line 124

in src/Superdesk/ContentApiSdk/Client/FileGetContentsClient.php, line 124

The ContentApiSdk class resolves to the following class: Superdesk\ContentApiSdk\ContentApiSdk.
Did you forget to add a corresponding use statement?

    {
        if (!is_array($params)) {
            return $params;
        }

        $validParameters = ContentApiSdk::getValidParameters();
        foreach ($params as $key => $value) {
            if (!in_array($key, $validParameters)) {
                unset($params[$key]);
            }
        }

Posted from SensioLabsInsight

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.