pimssas/pims-api-client-php

Simple PHP client for the Pims API

1.0.0 2018-04-17 15:31 UTC

README

Build Status

Pims PHP API client

Simple PHP client for the Pims API (documentation here).

Requirement

php >= 7.0

Installation

Use Composer to install. Simply add this line to your composer.json file:

"require": {
	"pimssas/pims-api-client-php": "dev-master"
}

and then run:

$ composer update 

Or install directly from the command line:

$ composer require pimssas/pims-api-client-php:"dev-master"

Usage

First step, you have to create a Client instance.

use Pims\Api\Client;
use Pims\Api\Exception\ClientException;

try {
    // Minimal setup
    $client = new Client(
    	'https://demo.pims.io/api',
    	'username',
    	'password');
    
    // ... or full setup, with language and version
    $client = new Client(
    	'https://demo.pims.io/api',
    	'username',
    	'password',
    	'fr',
    	'v1');
} catch (ClientException $e) {
    echo $e->getMessage();
}

Then you can call it on various endpoints, like this:

use Pims\Api\Endpoint;

try {
    // Display the label of the event by ID 2127
    $event = $client->getOne(
    	Endpoint::EVENTS,
    	2127);
    echo $event->getProperty('label');
    
    // Get the 10 last promotions applied to the event by ID 2127
    $promotions = $client->getAll(
       	Endpoint::EVENTS_PROMOTIONS,
       	[
       	    ':event_id' => 2127,
       	    'sort'      => '-date', 
       	    'page_size' => 10
       	]);
    
    // Get all events occuring in April 2018:
    $results = $client->getAll(
    	Endpoint::EVENTS,
    	[
    	    'from_date'	=> '2018-04-01',
    	    'to_date' 	=> '2018-04-30'
    	]);
    $events = $results->getResource('events');
    while ($results->hasLink('next')) {
    	$results = $client->getNext($results);
        $events = array_merge($events, $results->getResource('events'));
    }
    
    // Delete the venue by ID 234
    $client->deleteOne(
     	Endpoint::VENUES,
       	234);
} catch (ClientException $e) {
    echo $e->getMessage();
}

License

Copyright (c) 2010-2018 Pims SAS. Released under the MIT License.