Skip to content

PHP library that abstracts interactions with the Deputy API.

License

Notifications You must be signed in to change notification settings

communityds/deputy-api-wrapper

Repository files navigation

Deputy API Wrapper

Latest Stable Version Total Downloads GitHub Tests Action Status License

Allows interaction with the Deputy API (Version 1) using an object based interface that abstracts sending and receiving content from the REST API.

View the documentation on how to use the wrapper.

Use the CLI tool to explore the wrapper.

Installation

This package can be installed via Composer:

composer require communityds/deputy-api-wrapper

By default, this package uses the Guzzle library to send the API requests. Install the package via Composer:

composer require guzzlehttp/guzzle ^6.0

See the HTTP Clients documentation to see what other libraries can be used instead.

Usage

Create a singleton instance of the wrapper and provide at a minimum the authentication and target component configurations:

use CommunityDS\Deputy\Api\Wrapper;

$wrapper = Wrapper::setInstance(
    [
        'auth' => [
            'class' => 'CommunityDS\Deputy\Api\Adapter\Config\PermanentToken',
            'token' => '<YOUR_OAUTH_TOKEN_HERE>',
        ],
        'target' => [
            'class' => 'CommunityDS\Deputy\Api\Adapter\Config\TargetConfig',
            'domain' => '<YOUR_DOMAIN_HERE>',
        ],
    ]
);

Use the helper functions to get the records you are after. The example below returns all of today's schedules/rosters:

$today = mktime(0, 0, 0);
$shifts = $wrapper->findRosters()
    ->andWhere(['>=', 'startTime', $today])
    ->andWhere(['<', 'endTime', strtotime('+1 day', $today)])
    ->joinWith('employeeObject')
    ->joinWith('operationalUnitObject')
    ->all();
foreach ($shifts as $shift) {
    echo date('h:ia', $shift->startTime)
        . ' to ' . date('h:ia', $shift->endTime)
        . ' for ' . $shift->employeeObject->displayName
        . ' at ' . $shift->operationalUnitObject->displayName
        . PHP_EOL;
}

More details and examples can be found in the documentation.