A light, object orientated wrapper for the Idio API
- Written in PHP 5
- Follows PSR-0 conventions – auto-load friendly
- Follows the PSR-2 coding standard.
- Documented and tested
This library is not concerned with the individual API endpoints. Instead it acts as a simple wrapper for making requests against the API, whilst handling authentication and providing some convenient ways of, for example, making concurrent requests.
- PHP >= 5.3.2
- cURL extension
- Multibyte String extension
- PHPUnit – to run tests. (optional, installable via composer)
- PHP HTTP extension – for link manipulation through
Idio\Api\Link
. If not available a compatible library is used.
The easiest way of using the library is through composer. An example project's composer.json
might look like:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/idio/api-php"
}
],
"require": {
"idio/api-php" : "dev-master"
}
}
<?php
// This file is generated by Composer
require_once 'vendor/autoload.php';
$api = new Idio\Api\Client();
$api->setUrl(
'https://api.idio.co',
'1.0'
)->setAppCredentials(
'my_app_key',
'my_app_secret'
)->setDeliveryCredentials(
'my_delivery_key',
'my_delivery_secret'
);
// Returns an Idio\Api\Response object
$response = $api->request('GET', '/content')->send();
if ($response->getStatus() == 200) {
$result = $response->getBody();
echo "<p>{$result['total_hits']} Results</p>\n\n";
foreach ($result['content'] as $item) {
echo "<h2>{$item['title']}</h2>\n";
echo "<p>{$item['abstract']}</p>\n\n";
}
} else {
echo "Got {$response->getStatus()} from API.";
}
Send multiple API requests concurrently using curl_exec_multi
.
$responses = $api->batch(array(
$api->request('GET', '/users/1'),
$api->request('GET', '/users/2'),
$api->request('GET', '/users/3')
))->send();
Manipulate click tracking links to add, change or unset parameters. Useful for non-personalised content which can be cached, and then the links personalised by the client application.
$link = 'http://a.idio.co/r?c=idio&u=http%3A%2F%2Fwww.idioplatform.com';
$link = $api->link($link)->setParameters(array('x'=>array('idio'=>1)))->get();