Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

idio/api-php

Repository files navigation

Idio API PHP Library

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

Build Status

Introduction

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.

Requirements

Suggestions

  • PHP HTTP extension – for link manipulation through Idio\Api\Link. If not available a compatible library is used.

Installation

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"
    }
}

Example Usage

<?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.";
}

Advanced Features

Concurrent (Batch) Requests

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();

Click Tracking Link Manipulation

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();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published