Overview

The PHP Client Library is a simple object-oriented single file library which is designed to be a plug-and-play drop-in solution to quickly and easily integrate with any PHP project.

Client Library Version1.0
PHP Version CompatibilityPHP 5.6+ and PHP 7.x
Maintainer(s)CoMech Metrology Ltd.
API Version Compatibility3.0
Officially SupportedYes
Download Location

https://github.com/comech-metrology/trp-client

View Source

LicenseApache License, 2.0

Installation

Installation via Composer

You may install the API client via composer:

$ composer require comech/trp-api-client

Installation from GitHub via Git:

You may also install directly from GitHub using Git:

$ git clone https://github.com/comech-metrology/trp-client.git
$ cd trp-client
$ composer update

Including the library

To include the library in your PHP script, simply require the standard vendor/autoload.php in your project (this is created by composer, you must run composer update within the directory of the client library to create this file if you do not already have it):

require_once 'vendor/autoload.php';

Instantiating the Class

Once you have included the library in your script, you must then create an instance of the API class. The constructor takes one or two parameters which are a relative or absolute path to your SSL certificate, and optionally a PSR-3 compliant Logger Interface such as an instance of monolog. The SSL certificate should be both the private key and the certificate appended to each other, private key first, into one file;

$tr = new CoMech\TRP\API("tests/test.pem");

If you are using basic authentication with the API, no further action is needed and you can now start immediately calling methods (as documented in the child pages of this page). Alternatively if you are using impersonation, you must first log in with a username and password:

try {
    $tr->loginUser('test.user', 'P455W0rDD!@');
    print "Logged in, session ID: " . $tr->getSessionID() . "\n";
}
catch (CoMech\TRP\Exception\LoginException $e) {
    print "Can't log in: " . $e->getMessage() . "\n";
}

Calling Methods

Most methods within the TRPAPI class use the "magic method" functionality of PHP. This means that each API endpoint which is added to the API will be accessible via the client library, e.g. to fetch users you should call the getUsers() method, and to fetch companies you should call the getCompanies() method. You can update existing records with for example the updateUsers() method and create new users with the createUsers() method, deleting them with the deleteUsers() method.

For example:

/* Retrieve a user with IDs less than 100 */
$result = $tr->getUsers(["id<"=>100]);

/* Retrieve company with ID 42 */
$result = $tr->getCompanies(["id"=>42]);

/* Update first name of all users who's email contains mycompany.com to "Bob" */
$result = $tr->updateUsers(["email~"=>"mycompany.com"], ["first_name"=>"Bob"]);

Supported Methods