fw4 / whise-api
PHP library for implementing the Whise API
Installs: 3 370
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 5
Forks: 9
Open Issues: 2
Requires
- php: ^7.4|^8.0|^8.1
- guzzlehttp/guzzle: ~6.0|~7.0
- ocramius/package-versions: ^2.1
Requires (Dev)
- cache/array-adapter: ^1.1
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.7
- dev-main
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- dev-develop
- dev-release/v1.8.1
- dev-feature/endpoints
- dev-release/v1.8.0
- dev-feature/remove-countless
- dev-release/v1.7.0
- dev-feature/validation-codes
- dev-release/v1.6.2
- dev-feature/office-status
- dev-release/v1.6.1
- dev-feature/purpose-status
- dev-release/v1.6.0
- dev-feature/estate-details
- dev-release/v1.5.4
This package is auto-updated.
Last update: 2024-12-09 16:53:43 UTC
README
PHP client for the Whise API. For terms of use and API credentials, refer to the official documentation.
Installation
composer require fw4/whise-api
Usage
use Whise\Api\WhiseApi; $api = new WhiseApi(); // Retrieve existing access token from storage (getAccessTokenFromDataStore to be implemented) $accessToken = getAccessTokenFromDataStore(); if (!$accessToken) { // Request and store new access token (saveAccessTokenToDataStore to be implemented) $accessToken = $api->requestAccessToken('username', 'password'); saveAccessTokenToDataStore($accessToken); } $api->setAccessToken($accessToken);
All endpoints are provided as methods of the WhiseApi class. For more information about available endpoints and response format, refer to the official API documentation.
Available endpoints
Use the following methods to access available endpoints:
Administration
$api->admin()->clients()->list($parameters); $api->admin()->clients()->settings($parameters); $api->admin()->clients()->updateSettings($parameters); $api->admin()->clients()->token($parameters); $api->admin()->offices()->list($parameters); $api->admin()->representatives()->list($parameters);
Estates
$api->estates()->list($filter, $sorting, $fields); $api->estates()->get($id, $filter, $fields); $api->estates()->regions()->list($parameters); $api->estates()->usedCities()->list($filter); $api->estates()->usedCountries()->list($filter); $api->estates()->exports()->list($office_id, $parameters); $api->estates()->exports()->changeStatus($estate_id, $export_status, $id_in_media, $export_message); $api->estates()->owned()->list($username, $password, $filter, $sorting, $fields);
Contacts
$api->contacts()->upsert($parameters); $api->contacts()->origins()->list($parameters); $api->contacts()->titles()->list($parameters); $api->contacts()->types()->list($parameters);
Calendars
$api->calendars()->list($filter, $sorting, $fields, $aggregation); $api->calendars()->create($parameters); $api->calendars()->delete($id); $api->calendars()->update($parameters); $api->calendars()->actions()->list($parameters);
Activity
$api->activities()->calendars($filter, $aggregation); $api->activities()->histories($filter, $aggregation); $api->activities()->audits($filter, $aggregation); $api->activities()->historyExports($filter, $aggregation);
Pagination
Endpoints that retrieve multiple items return a traversable list of objects. Pagination for large lists happens automatically.
$estates = $api->estates()->list(); // Traversing over the response takes care of pagination in the background foreach ($estates as $estate) { echo $estate->name . PHP_EOL; }
Manual pagination
For situations where manual pagination is required, a page
method is provided. Calling this method with both a
desired page index (starting at 0), and the amount of items to retrieve per page, returns a traversable list of
objects. This list also provides multiple methods for dealing with paging metadata:
getPage()
to retrieve the current page index (starting at 0).getPageSize()
to retrieve the maximum amount of items per page.count()
to retrieve the actual amount of items on the current page.getTotalCount()
to retrieve the total amount of items across all pages. This method is currently not available onactivities
endpoints.getPageCount()
to retrieve the total amount of pages. This method is currently not available onactivities
endpoints.
Example
$page_index = 2; $items_per_page = 20; $estates = $api->estates()->list([ 'CategoryIds' => [1] ]); $page = $estates->page($page_index, $items_per_page); echo 'Showing ' . $page->count() . ' items out of ' . $page->getTotalCount() . PHP_EOL; echo 'Page ' . ($page->getPage() + 1) . ' of ' . $page->getPageCount() . PHP_EOL; foreach ($page as $estate) { echo $estate->name . PHP_EOL; }
Caching
It's possible to enable caching by using a PSR-6 compatible cache adapter. Do note that this will cause all read operations to be cached, overriding any cache-control policy used by the Whise API, violating RFC.
use Cache\Adapter\Redis\RedisCachePool; $redis = new \Redis(); $redis->connect('127.0.0.1', 6379); $cache = new RedisCachePool($redis); $api = new Whise\Api\WhiseApi($access_token); $api->setCache($cache);
You can change the default cache lifetime of one hour, as well as the cache key prefix, by using the second and third
parameters of setCache
respectively. These can also be changed at runtime by using the setCacheTtl
and
setCachePrefix
methods.
Responses are cached per access token, so make sure to reuse your access token to share a cache across script executions.
To determine whether a response was returned from cache, call the isCacheHit
method. This method is not available
when using automatic pagination.
$estate = $api->estates()->get(1); if ($estate->isCacheHit()) { echo 'Response fetched from cache' . PHP_EOL; } else { echo 'Response fetched from API' . PHP_EOL; }
License
fw4/whise-api
is licensed under the MIT License (MIT). Please see LICENSE for more information.