/publitio_php_sdk

Publitio PHP SDK

Primary LanguagePHP

Publitio PHP SDK

PHP SDK for Publitio API. This SDK works with PHP version 5.5 and up.

Deprecated version

Version 1 of this SDK has been deprecated and its use is discouraged. You can find the deprecated version on the deprecated branch.

Installation

This SDK is installed via Composer.

Install Composer if you haven't already:

curl -sS https://getcomposer.org/installer | php

Install the Publitio SDK:

php composer.phar require publitio/publitio

If you have already installed Composer globally, use:

composer require publitio/publitio

After installing, require the Composer autoloader:

require 'vendor/autoload.php';

Usage

The \Publitio\API class presents the main interface to the Publitio RESTful API. You can find more documentation about Publitio here.

To instantiate the API class, provide your API key and API secret (which you can find on your Publitio dashboard):

$publitio = new \Publitio\API('<API Key>', '<API Secret>');

To Make an API call, use the call method:

$response = $publitio->call($call_url, $method, $args);

For a list of available calls, see the docs.

  • $call_url is the API call URL, for example '/files/list'.

  • $method is the HTTP method, for example 'GET' or 'DELETE'. Which of these you need depends on what kind of call you are making. The method for each API URL is documented at the docs.

  • $args is an array of URL query parameters, such as array('public_id' => 'foo').

  • $response will be the response JSON parsed using json_decode. Note: this is a PHP object, not an array.

Use the call method when you aren't going to be uploading any files with the call. If you wish to upload a file, use the uploadFile or uploadRemoteFile methods:

$publitio->uploadFile(fopen('path/to/file.png', 'r'));

Documentation

For complete documentation of this SDK, see this page.

Example

For plenty more usage examples, see the examples directory.

$publitio = new \Publitio\API('<API Key>', '<API secret>');
$response = $publitio->call('/files/list', 'GET', array('offset' => '0', 'limit' => '10'));
var_dump($response);