Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
src
tests
.editorconfig
.env.dist
.gitattributes
.gitignore
.travis.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE Rename license text file Sep 4, 2017
README.md
composer.json
phpdox.xml Auto-generate code documentation with phpdox Feb 15, 2018

README.md

i-doit API client library

Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API

Latest Stable Version Minimum PHP Version Build Status

About

i-doit is a software application for IT documentation and a CMDB (Configuration Management Database). This application is very useful to collect all your knowledge about the IT infrastructure you are dealing with. i-doit is a Web application and has an exhausting API which is very useful to automate your infrastructure.

This API client library provides a simple, but powerful abstraction layer to send requests to i-doit's API. It is written in pure PHP.

Features

Why should you use this API client library? There are some good reasons:

  • Easy to use
  • There is a PHP function for each API method
  • Supports batch requests (much faster)
  • Sends user-defined requests
  • Uploads files and images
  • Supports login and logout methods to save sessions
  • Follows redirects (HTTP 301/302) automatically
  • Uses optional HTTP or SOCKS5 proxy
  • Verifies TLS certificate chains
  • Throws exception on error
  • Many examples
  • Well-documented
  • Easy to install via Composer
  • Well-tested with dozens of unit tests

What's new? Take a look at the changelog.

Requirements

Meet these simple requirements before using the client:

  • A running instance of i-doit, version 1.10.2 or higher
  • i-doit API add-on, version 1.9.1 or higher
  • PHP, version 5.6 or higher (7.2 is recommended)
  • PHP modules curl, date, json, openssl and zlib

Installation

It is recommended to install this client via Composer. Change to your project's root directory and fetch the latest stable version:

composer require "bheisig/idoitapi=>=0.6"

This installs version 0.6 or higher if available. Instead of sticking to a specific/minimum version you may switch to the current development branch by using @DEV:

composer require "bheisig/idoitapi=@DEV"

Updates

Composer has the great advantage (besides many others) that you can simply update the API client library by running:

composer update

Usage

If you use Composer you should use its own autoloader, too:

require_once 'vendor/autoload.php';

This is it. All other files will be auto-loaded on-the-fly if needed.

Configuration

The API client library class requires a configuration:

use bheisig\idoitapi\API;

$api = new API([
    'url' => 'https://demo.i-doit.com/src/jsonrpc.php',
    'port' => 443,
    'key' => 'c1ia5q',
    'username' => 'admin',
    'password' => 'admin',
    'language' => 'en',
    'proxy' => [
        'active' => false,
        'type' => 'HTTP', // 'HTTP' or 'SOCKS5'
        'host' => 'proxy.example.net',
        'port' => 8080,
        'username' => '',
        'password' => ''
    ]
]);
  • url: URL to i-doit's API, probably the base URL appended by src/jsonrpc.php
  • port: optional port on which the Web server listens; if not set port 80 will be used for HTTP and 443 for HTTPS
  • key: API key
  • username and password: optional credentials if needed, otherwise System API user will be used
  • language: requests to and responses from i-doit will be translated to this language (de and en supported); this is optional; defaults to user's prefered language
  • proxy: use a proxy between client and server
    • active: if true proxy settings will be used
    • type: use a HTTP or a SOCKS5 proxy
    • host: FQDN or IP address to proxy
    • port: port on which the proxy server listens
    • username and password: optional credentials used to authenticate against the proxy

Examples

A basic "Hello, World!" example is to fetch some basic information about your i-doit instance:

use bheisig\idoitapi\API;
use bheisig\idoitapi\Idoit;

require_once 'vendor/autoload.php';

$api = new API([
    'url' => 'https://demo.i-doit.com/src/jsonrpc.php',
    'key' => 'c1ia5q',
    'username' => 'admin',
    'password' => 'admin'
]);

$request = new Idoit($api);
$info = $request->readVersion();

var_dump($info);

It is simple like that. For more examples take a look at the next sub sections.

Login and logout

One sweet thing about i-doit's API you can (and should) use one user session for your stuff. This saves resources on the server side and allows you to perform a lot more calls in a short time.

The session handling is done by the API client library. You just need to login. And if you are nice you want to logout after your work is done.

use bheisig\idoitapi\API;

$api = new API([/* … */]);

$api->login();
// Do your stuff…
$api->logout();

If you are unsure in which condition your session is try isLoggedIn():

$api->isLoggedIn(); // Returns true or false

Pre-defined methods

For almost every case there is a remote procedure you may call to read from or manipulate i-doit's database through its API. Each remote procedure is assigned to a namespace to keep the API clean and smoothly. Furtunately, you do not need to call these remote procedures on your own. The API client library provides for each namespace a class and for each remote procedure a method. Here is a quick overview:

Namespace Remote Procedure Call (RPC) Class in API Client Library Method
idoit idoit.version Idoit readVersion()
idoit.search search()
idoit.constants readConstants()
idoit.login API login()
idoit.logout logout()
cmdb.object cmdb.object.create CMDBObject create()
cmdb.object.read read()
cmdb.object.update udpate()
cmdb.object.delete archive(), delete(), purge()
cmdb.objects cmdb.objects.read CMDBObjects read()
cmdb.category cmdb.category.create CMDBCategory create()
cmdb.category.read read(), readOneByID(), readFirst()
cmdb.category.update update()
cmdb.category.delete archive(), delete(), purge()
cmdb.category_info cmdb.category_info.read CMDBCategoryInfo read()
cmdb.dialog cmdb.dialog.create CMDBDialog create()
cmdb.dialog.read read()
cmdb.impact cmdb.impact.read CMDBImpact readByID(), readByConst()
cmdb.location_tree cmdb.location_tree.read CMDBLocationTree read(), readRecursively()
cmdb.logbook cmdb.logbook.create CMDBLogbook create()
cmdb.logbook.read read()
cmdb.objects_by_relation cmdb.objects_by_relation.read CMDBObjectsByRelation readByID(), readByConst()
cmdb.object_type_categories cmdb.object_type_categories.read CMDBObjectTypeCategories readByID(), readByConst()
cmdb.object_type_groups cmdb.object_type_groups.read CMDBObjectTypeGroups read()
cmdb.object_types cmdb.object_types.read CMDBObjectTypes read(), readOne(), readByTitle()
cmdb.reports cmdb.reports.read CMDBReports read(), listReports()
cmdb.workstation_components cmdb.workstation_components.read CMDBWorkstationComponents read(), readByEMail(), readByEMails()
checkmk.statictag checkmk.statictag.create CheckMKStaticTag create()
checkmk.statictag.read read(), readByID(), readByIDs(), readByTag()
checkmk.statictag.update update()
checkmk.statictag.delete delete()
checkmk.tags checkmk.tags.read CheckMKTags read()
monitoring.livestatus monitoring.livestatus.create MonitoringLivestatus createTCPConnection, createUNIXSocketConnection
monitoring.livestatus.read read(), readByID(), readByIDs(), readByTitle()
monitoring.livestatus.update update()
monitoring.livestatus.delete deleteByID(), deleteByTitle()

Additionally, this API client library is shipped with methods as workarounds for remote procedure calls you probably miss. The RPC cmdb.objects.create does not exist but you may use CMDBObjects::create(). It simulates the missing RPC and gives you an easier and faster way to manipulate your CMDB.

If it makes sense there are methods to perform batch requests for most RPCs. For example, CMDBCategory::batchRead() fetches multiple category entries at once.

Examples

Search in i-doit's database

use bheisig\idoitapi\API;
use bheisig\idoitapi\Idoit;

$api = new API([/* … */]);

$idoit = new Idoit($api);
$result = $idoit->search('Server XY');

var_dump($result);

Perform more than one search at once:

use bheisig\idoitapi\API;
use bheisig\idoitapi\Idoit;

$api = new API([/* … */]);

$idoit = new Idoit($api);
$result = $idoit->batchSearch([
    'Server XY',
    'Client A',
    'John Doe'
]);

var_dump($result);

Create a new object

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObject;

$api = new API([/* … */]);

$object = new CMDBObject($api);
$objectID = $object->create(
    'C__OBJTYPE__SERVER',
    'Server XY'
);

var_dump($objectID);

Read common information about an object

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObject;

$api = new API([/* … */]);

$object = new CMDBObject($api);
$objectInfo = $object->read(42);

var_dump($objectInfo);

Load all data of an object

This will fetch everything about an object: common data, assigned categories and category entries as well.

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObject;

$api = new API([/* … */]);

$object = new CMDBObject($api);
$objectInfo = $object->load(42);

var_dump($objectInfo);

The method load() triggers round about 4 API calls. So be aware if it is heavily used.

Update an existing object

Currently, you are able to update an object's title:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObject;

$api = new API([/* … */]);

$object = new CMDBObject($api);
$object->update(
    42,
    [
        'title' => 'A shiny new object title'
    ]
);

Create or update an object ("upsert")

You you like to get an identifier of an object but you are unsure whether or not it exists, try an upsert. This is an "update" and an "insert" at the same time. This means, if the object exists you will get its identifier directly. If not the object will be created and then you will get its identifier. Objects must match against type and title. Additional attributes will be stored.

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObject;

$api = new API([/* … */]);

$object = new CMDBObject($api);
$object->upsert(
    'C__OBJTYPE__SERVER',
    'My little server',
    [
        'purpose' => 'Private stuff'
    ]
);

Fetch an object identifier

Fetch an object identifier by object title and (optional) type:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObjects;

$api = new API([/* … */]);

$object = new CMDBObjects($api);
$objectID = $object->getID('My little server');
$objectID = $object->getID('My little server', 'C__OBJTYPE__SERVER');

An exception error will be thrown if there is either no object or more than one.

Change documentation status of an object

i-doit has the concept of archiving your IT documentation. Each object has an status (normal, archived, marked as deleted). And last but not least, an object may be purged from the database.

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObject;

$api = new API([/* … */]);

$object = new CMDBObject($api);
$objectID = 42;
// Archive:
$object->archive($objectID);
// Mark as deleted:
$object->delete($objectID);
// Purge from database:
$object->purge($objectID);

Create multiple objects

Create multiple objects at once:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObjects;

$api = new API([/* … */]);

$cmdbObjects = new CMDBObjects($api);

$objectIDs = $cmdbObjects->create(
    [
        ['type' => 'C__OBJTYPE__SERVER', 'title' => 'Server No. One'],
        ['type' => 'C__OBJTYPE__SERVER', 'title' => 'Server No. Two'],
        ['type' => 'C__OBJTYPE__SERVER', 'title' => 'Server No. Three']
    ]
);

var_dump($objectIDs);

Read multiple objects

Reading multiple objects at once is provided by several methods. Let's see:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObjects;

$api = new API([/* … */]);

$cmdbObjects = new CMDBObjects($api);

// Fetch every object:
$objects = $cmdbObjects->read();
var_dump($objects);

// Fetch max. 10 servers and sort them descending by title:
$objects = $cmdbObjects->read(['type' => 'C__OBJTYPE__SERVER'], 10, 0, 'title', CMDBObjects::SORT_DESCENDING);
var_dump($objects);

// Get them by their identifiers:
$objects = $cmdbObjects->readByIDs([1, 2, 3]);
var_dump($objects);

// Get all servers:
$objects = $cmdbObjects->readByType('C__OBJTYPE__SERVER');
var_dump($objects);

// Get archived clients:
$objects = $cmdbObjects->readArchived('C__OBJTYPE__CLIENT');
var_dump($objects);

// Get clients marked as deleted:
$objects = $cmdbObjects->readDeleted('C__OBJTYPE__CLIENT');
var_dump($objects);

Update multiple objects

Update multiple objects at once:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObjects;

$api = new API([/* … */]);

$cmdbObjects = new CMDBObjects($api);

// Rename objects 1, 2, 3:
$cmdbObjects->update([
  ['id' => 1, 'title' => 'New name'],
  ['id' => 2, 'title' => 'Another name'],
  ['id' => 3, 'title' => 'Just a name'],
]);

Archive/delete/purge multiple objects

Archive objects, mark them as deleted or even purge them from database:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObjects;

$api = new API([/* … */]);

$cmdbObjects = new CMDBObjects($api);

$cmdbObjects
    ->archive([1, 2, 3])
    ->delete([1, 2, 3])
    ->purge([1, 2, 3]);

Create category entries with attributes

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBCategory;

$api = new API([/* … */]);

$category = new CMDBCategory($api);
$entryID = $this->category->create(
    42,
    'C__CATG__IP',
    [
        'net' => 123,
        'active' => false,
        'primary' => false,
        'net_type' => 1,
        'ipv4_assignment' => 2,
        "ipv4_address" =>  '10.20.10.100',
        'description' => 'API TEST'
    ]
);

var_dump($entryID);

Alternatively, use method CMDBCategory::batchCreate() for batch requests.

Read categories and attributes

Read one or more category entries for one specific object:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBCategory;

$api = new API([/* … */]);

$category = new CMDBCategory($api);
$result = $category->read(42, 'C__CATG__IP');

var_dump($result);

Read one specific categoy entry for one specific object:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBCategory;

$api = new API([/* … */]);

$category = new CMDBCategory($api);
$result = $category->readOneByID(42, 'C__CATG__IP', 23);

var_dump($result);

Read just one category entry (easier than read() when using single-valued categories):

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBCategory;

$api = new API([/* … */]);

$category = new CMDBCategory($api);
$result = $category->readFirst(42, 'C__CATG__IP');

var_dump($result);

Read data for multiple objects and categories at once:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBCategory;

$api = new API([/* … */]);

$category = new CMDBCategory($api);
$result = $category->batchRead(
    [23, 42],
    ['C__CATG__IP', 'C__CATG__MODEL']
);

var_dump($result);

Update categories and attributes

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBCategory;

$api = new API([/* … */]);

$category = new CMDBCategory($api);
$category->update(
    42,
    'C__CATG__GLOBAL',
    [
        'cmdb_status' => 10
    ]
);

Alternatively, use method CMDBCategory::batchUpdate() for batch requests.

Change documentation status of a category and its attributes

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBCategory;

$api = new API([/* … */]);

$category = new CMDBCategory($api);
// Archive:
$category->archive(42, 'C__CATG__CPU', 1);
// Mark as deleted:
$category->delete(42, 'C__CATG__CPU', 2);
// Purge from database:
$category->purge(42, 'C__CATG__CPU', 3);

Create values in drop-down menus

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBDialog;

$api = new API([/* … */]);

$dialog = new CMDBDialog($api);

$entryID = $dialog->create('C__CATG__MODEL', 'title', 'My model');
var_dump($entryID);

$entryIDs = $dialog->batchCreate([
    'C__CATG__MODEL' => [
        'manufacturer' => 'My manufacturer',
        'title' => 'My model'
    ],
    'C__CATG__GLOBAL' => [
        'category' => [
            'cat 1',
            'cat 2',
            'cat 3'
        ],
        'purpose' => 'API TEST'
    ]
]);
var_dump($entryIDs);

Fetch values from drop-down menus

Drop-down menus in i-doit are called "dialog" (read-only) or "dialog+" (editable).

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBDialog;

$api = new API([/* … */]);

$dialog = new CMDBDialog($api);

$models = $dialog->read('C__CATG__MODEL', 'title');
var_dump($models);

$modelsAndManufacturers = $dialog->batchRead([
    'C__CATG__MODEL' => [
        'manufacturer',
        'title'
    ]
]);
var_dump($modelsAndManufacturers);

Build a location tree

Read objects located directly under an object:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBLocationTree;

$api = new API([/* … */]);

$locationTree = new CMDBLocationTree($api);
$result = $locationTree->read(1);

var_dump($result);

Read recursively objects located under an object:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBLocationTree;

$api = new API([/* … */]);

$locationTree = new CMDBLocationTree($api);
$result = $locationTree->readRecursively(1);

var_dump($result);

Fetch relations between objects

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObjectsByRelation;

$api = new API([/* … */]);
$relation = new CMDBObjectsByRelation($api);

$result = $relation->read(
    10,
    'C__RELATION_TYPE__PERSON_ASSIGNED_GROUPS'
);

var_dump($result);

Fetch workplace components for a person

A Person may be assigned to a workplace with several components like a PC, a monitor and a telephone. These components can be fetched by the person. You either need the object ID or the email address. Even more than one workplaces are supported.

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBWorkstationComponents;

$api = new API([/* … */]);
$components = new CMDBWorkstationComponents($api);

$result = $components->read(111); // Person object with ID 111
var_dump($result);

$result = $components->batchRead([111, 222]); // Person objects with IDs 111 and 222
var_dump($result);

$result = $components->readByEMail('alice@example.org'); // Person object with email address
var_dump($result);

$result = $components->readByEMails(['alice@example.org', 'bob@example.org']); // Person objects with email addresses
var_dump($result);

Reports

List all reports:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBReports;

$api = new API([/* … */]);
$reports = new CMDBReports($api);

$result = $reports->listReports();

var_dump($result);

Fetch the result of a report:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBReports;

$api = new API([/* … */]);
$reports = new CMDBReports($api);

$result = $reports->read(1);

var_dump($result);

Fetch the result of one or more reports:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBReports;

$api = new API([/* … */]);
$reports = new CMDBReports($api);

$result = $reports->batchRead([1, 2]);

var_dump($result);

Fetch next free IP address from subnet

use bheisig\idoitapi\API;
use bheisig\idoitapi\Subnet;

$api = new API([/* … */]);

$subnet = new Subnet($api);
// Load subnet object by its identifier:
$nextIP = $subnet->load(123)->next();

echo 'Next IP address: ' . $nextIP . PHP_EOL;

Upload files

This API client library is able to upload a file, create a new "File" object an assigned it to an existing object identified by its ID:

use bheisig\idoitapi\API;
use bheisig\idoitapi\File;

$api = new API([/* … */]);

$file = new File($api);

// Assign one file to object with identifier 100:
$file->add(100, '/path/to/file', 'my file');

// Assign many files to this object:
$file->batchAdd(
    100,
    [
        'file1.txt' => 'File 1',
        'file2.txt' => 'File 2',
        'file3.txt' => 'File 3'
    ]
);

Upload images to a gallery

Each object may have an image gallery provided by assigned category "images". This is the way to upload image files and assign them to an existing object:

use bheisig\idoitapi\API;
use bheisig\idoitapi\Image;

$api = new API([/* … */]);

$image = new Image($api);

// Assign one image with a caption to object's gallery with identifier 100:
$image->add(100, '/path/to/flowers.jpg', 'nice picture of flowers');

// Assign many images to this object:
$file->batchAdd(
    100,
    [
        'file1.jpg' => 'JPEG file',
        'file2.png' => 'PNG file',
        'file3.bmp' => 'BMP file',
        'file3.gif' => 'Animated GIF file'
    ]
);

Self-defined request

Sometimes it is better to define a request on your own instead of using pre-defined methods provided by this API client library. Here is the way to perform a self-defined request:

use bheisig\idoitapi\API;

$api = new API([/* … */]);

$result = $api->request('idoit.version');

var_dump($result);

request() takes the method and optional parameters.

Self-defined batch request

Similar to a simple requests you may perform a batch requests with many sub-requests as you need:

use bheisig\idoitapi\API;

$api = new API([/* … */]);

$result = $api->batchRequest([
    [
        'method' => 'idoit.version'
    ],
    [
       'method' => 'cmdb.object.read',
       'params' => ['id' => 1]
    ]
]);

var_dump($result);

Read information about your CMDB design

Fetch information about object types, object types per group, categories assigned to object types, and attributes available in categories:

use bheisig\idoitapi\API;
use bheisig\idoitapi\CMDBObjectTypes;
use bheisig\idoitapi\CMDBObjectTypeGroups;
use bheisig\idoitapi\CMDBObjectTypeCategories;
use bheisig\idoitapi\CMDBCategoryInfo;

$api = new API([/* … */]);

// Object types:
$objectTypes = new CMDBObjectTypes($api);
$allObjectTypes = $objectTypes->read();
var_dump($allObjectTypes);
$server = $objectTypes->readOne('C__OBJTYPE__SERVER');
var_dump($server);
$someObjectTypes = $objectTypes->batchRead('C__OBJTYPE__SERVER', 'C__OBJTYPE__CLIENT');
var_dump($someObjectTypes);
$client = $objectTypes->readByTitle('LC__CMDB__OBJTYPE__CLIENT');
var_dump($client);

// Object types per group:
$objectTypesPerGroup = new CMDBObjectTypeGroups($api);
$objectTypes = $objectTypesPerGroup->read();
var_dump($objectTypes);

// Categories assigned to object types:
$assignedCategory = new CMDBObjectTypeCategories($api);
$serverCategories = $assignedCategory->readByConst('C__OBJTYPE__SERVER');
var_dump($serverCategories);
// Read by identifiers is also possible. And there are methods for batch requests.

// Attributes available in categories:
$categoryInfo = new CMDBCategoryInfo($api);
$modelCategory = $categoryInfo->read('C__CATG__MODEL');
var_dump($modelCategory);
$categories = $categoryInfo->batchRead([
    'C__CATG__MODEL',
    'C__CATG__FORMFACTOR',
    'C__CATS__PERSON_MASTER'
]);
var_dump($categories);

Read information about i-doit itself

use bheisig\idoitapi\API;
use bheisig\idoitapi\Idoit;

$api = new API([/* … */]);

$idoit = new Idoit($api);
$version = $idoit->readVersion();
$constants = $idoit->readConstants();

var_dump($constants);

Re-connect to server

Sometimes you need a fresh connection. You may explicitly disconnect from the i-doit server and re-connect to it:

use bheisig\idoitapi\API;

$api = new API([/* … */]);

// Do your stuff…
$api->disconnect();
$api->isConnected(); // Returns false
$api->connect();
$api->isConnected(); // Returns true

Debug API calls

For debugging purposes it is great to fetch some details about your API calls. This script uses some useful methods:

#!/usr/bin/env php
<?php

use bheisig\idoitapi\API;
use bheisig\idoitapi\Idoit;

$start = time();

require_once 'vendor/autoload.php';

$api = new API([/* … */]);

// @todo Insert your code here, for example:
$request = new Idoit($api);
$request->readVersion();

fwrite(STDERR, 'Last request:' . PHP_EOL);
fwrite(STDERR, '=============' . PHP_EOL);
fwrite(STDERR, $api->getLastRequestHeaders() . PHP_EOL);
fwrite(STDERR, json_encode($api->getLastRequestContent(), JSON_PRETTY_PRINT) . PHP_EOL);
fwrite(STDERR, PHP_EOL);
fwrite(STDERR, '--------------------------------------------------------------------------------' . PHP_EOL);
fwrite(STDERR, 'Last response:' . PHP_EOL);
fwrite(STDERR, '==============' . PHP_EOL);
fwrite(STDERR, $api->getLastResponseHeaders() . PHP_EOL);
fwrite(STDERR, json_encode($api->getLastResponse(), JSON_PRETTY_PRINT) . PHP_EOL);
fwrite(STDERR, PHP_EOL);
fwrite(STDERR, '--------------------------------------------------------------------------------' . PHP_EOL);
fwrite(STDERR, 'Last connection:' . PHP_EOL);
fwrite(STDERR, '================' . PHP_EOL);
$info = $api->getLastInfo();
unset($info['request_header']);
foreach ($info as $key => $value) {
    if (is_array($value)) {
        $value = '…';
    }
    fwrite(STDERR, $key . ': ' . $value . PHP_EOL);
}
fwrite(STDERR, '--------------------------------------------------------------------------------' . PHP_EOL);
fwrite(STDERR, 'Amount of requests: ' . $api->countRequests() . PHP_EOL);
$memoryUsage = memory_get_peak_usage(true);
fwrite(STDERR, sprintf('Memory usage: %s bytes', $memoryUsage) . PHP_EOL);
$duration = time() - $start;
fwrite(STDERR, sprintf('Duration: %s seconds', $duration) . PHP_EOL);

Contribute

Please, report any issues to our issue tracker. Pull requests are very welcomed. If you like to get involved see file CONTRIBUTING.md for details.

Projects using this API client library

Send pull requests to add yours.

Copyright & License

Copyright (C) 2016-18 Benjamin Heisig

Licensed under the GNU Affero GPL version 3 or later (AGPLv3+). This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.