2017 © Pedro Peláez
 

library infogram

PHP client for infogr.am REST API

image

infogram/infogram

PHP client for infogr.am REST API

  • Tuesday, April 25, 2017
  • by martinsb
  • Repository
  • 18 Watchers
  • 9 Stars
  • 1,066 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 4 Versions
  • 286 % Grown

The README.md

Infogram-PHP

This library provides an API to create and update infographics on Infogr.am, (*1)

Installation

The recommended way to install Infogram-PHP is via Composer. Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you., (*2)

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

Add the following dependency to the require section of your project's composer.json:, (*3)

"require": {
  "infogram/infogram": "1.0.*"
}

Execute command line composer update in your project's root, (*4)

API Keys

You're going to need API keys, the public key and the secret (or private) key, to be able to access infogr.am API service. To find your keys, log in to Infogr.am, find the account settings on the left panel and look for the API credentials. Keep your secret key secret, don't send it to anyone and do not pass it to any service directly., (*5)

The public key is used to indentify the API account the code is accessing with and the secret key is used to sign every request, i.e., add additional parameter to the request query string or body., (*6)

Usage

Making a Request

For making a request, two Infogram-PHP classes are essential: Infogram\RequestSigningSession and Infogram\InfogramRequest. The former is responsible for HTTP request signing using the provided API secret key and the latter performs HTTP requests to the Infogr.am API service., (*7)

TODO: add reference to HTTP API documentation, (*8)

use Infogram\InfogramRequest;
use Infogram\RequestSigningSession;
//...
$consumerKey = 'Your public key';
$consumerSecret = 'Your secret key';
$session = new RequestSigningSession($consumerKey, $consumerSecret);
$request = new InfogramRequest($session, 'GET', 'themes');
$response = $request->execute();

Using a Response

Method Infogram\InfogramRequest::execute returns an instance of class Infogram\InfogramResponse or null if Infogr.am API server cannot be accessed., (*9)

Infogram\InfogramResponse contains (1) HTTP status code from last API request, (2) HTTP response body, (3) HTTP response headers, (*10)

$content = array(
  array(
    'type' => 'h1',
    'text' => 'hello'
  )
);
$session = new RequestSigningSession($consumerKey, $consumerSecret);
$request = new InfogramRequest($session, 'POST', 'infographics', array('content' => $content));
$response = $request->execute();
if (! $response) {
   die("Could not contact Infogr.am API server\n");
}
if (! $response->isOK()) {
   die('Error executing API request: ' . $response->getBody() . "\n");
}
echo 'Created new infographic with ID: ' . $response->getHeader('X-Infogram-Id') . "\n";

On successful request ($response->isOK() == true), response's method getBody returns either a string or array (converted from a JSON string) if applicable. On error (! $response->isOK()), getBody returns string which contains the error message if there is any., (*11)

The Versions

25/04 2017

dev-master

9999999-dev https://github.com/infogram/infogram-php

PHP client for infogr.am REST API

  Sources   Download

The Requires

 

The Development Requires

by Mārtiņš Barinskis

infogram infogr.am

27/07 2015

1.0.1

1.0.1.0 https://github.com/infogram/infogram-php

PHP client for infogr.am REST API

  Sources   Download

The Requires

 

The Development Requires

by Mārtiņš Barinskis

infogram infogr.am

26/07 2015

dev-guzzle2request

dev-guzzle2request https://github.com/infogram/infogram-php

PHP client for infogr.am REST API

  Sources   Download

The Requires

 

The Development Requires

by Mārtiņš Barinskis

infogram infogr.am

12/12 2014

1.0.0

1.0.0.0 https://github.com/infogram/infogram-php

PHP client for infogr.am REST API

  Sources   Download

The Requires

 

The Development Requires

by Mārtiņš Barinskis

infogram infogr.am