Cleeng PHP SDK

Cleeng PHP SDK is a wrapper library that allows accessing Cleeng API in convenient, object oriented way. In next steps you can read how to download, install and use Cleeng PHP SDK.

Requirements

Cleeng PHP SDK required PHP version 5.2 (or above) and CURL extension.

Download

Cleeng PHP SDK is hosted on GitHub.

Installation

If you don't use autoloader, please include cleend_api.php file. That file will load full PHP SDK library, and prepare you to use Cleeng API. Check Tutorial 1 - protect your content. You can find there bunch of examples how to include cleeng_api.

Usage

To start, you have to create Cleeng_Api object.

$cleengApi = new Cleeng_Api();

By default SDK doesn't require any configuration. You may want to switch it to sandbox mode during tests:

$cleengApi->enableSandbox();

When Cleeng_Api class is instantiated, you can start using the API! As an example, we'll list single offers from theteam@cleeng.com first:

$offerList = $cleengApi->listSingleOffers(array('publisherEmail' => 'theteam@cleeng.com'), 0, 20);
foreach ($offerList as $offer) {
    echo $offer->title, "<br />\n";
}

Authentication

Most of Cleeng API functions require either customerToken or publisherToken parameter to be specified. PHP SDK will try to read customer token from cookie (it is created on your domain by Javascript API after customer purchases or logs in).

Publisher token must be set explicitly:

$cleengApi->setPublisherToken('0KRQzKhjcerYyVq-MtBVDb56W7SYJH0LaA48kXfwCM0HC9x7');

Batch mode

You can bundle max 50 API calls into 1 http-request.

$cleengApi->setBatchMode(true);  // enable batch mode
$offer = $cleengApi->getSingleOffer('A123123123');        // stack some API calls...
$status1 = $cleengApi->getAccessStatus('A123123123');
$status2 = $cleengApi->getAccessStatus('S789789789');
$cleengApi->commit(); // make actual request

// now properties are available:
if ($status1->accessGranted || $status2->accessGranted) {
     // ...
}

Troubleshooting

In case of any troubles related to connection or environment settings, what you should now is:

  • Cleeng PHP SDK uses Curl extension to connect with Cleeng API,
  • connection timeout is set 10s.

If needed, you can set your own Curl settings using:

$cleengApi->getTransport()->setCurlOptions($optionsArray);

For instance, to increase default timeout, you can use:

$options = array(
    CURLOPT_CONNECTTIMEOUT => 15
);
$cleengApi->getTransport()->setCurlOptions($options);