communityds / deputy-api-wrapper
Deputy API Wrapper
Installs: 17 454
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 4
Forks: 3
Open Issues: 0
Requires
- php: >=5.6
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^5.0 || ^10.5
README
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.