cognetif / poka-api
Poka Api - To interact with Poka API
Requires
- php: ^8.0
- ext-json: *
- kitetail/zttp: ^0.6.0
Requires (Dev)
- illuminate/support: ^6.10
- phpunit/phpunit: ^9
- dev-develop
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.2
- 1.2.1
- v1.2.0
- v1.1.0
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.15.3
- v0.15.2
- v0.15.1
- v0.15.0
- v0.14.7
- v0.14.6
- v0.14.5
- v0.14.4
- v0.14.3
- v0.14.2
- v0.14.1
- v0.14.0
- v0.13.0
- v0.12.0
- v0.11.0
- v0.10.0
- v0.9.1
- v0.9.0
- v0.8.0
- v0.7.6
- v0.7.5
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.0
- v0.3.2
- v0.3.1
- v0.2.0
- v0.1.2
- v0.1.1
- v0.1.0
- dev-master
- dev-move-to-zttp
This package is auto-updated.
Last update: 2024-02-26 14:52:09 UTC
README
This library allows you to interact with the Poka API.
Notice
This library has not been approved, licensed, commissioned or endorsed by Poka. It has been created and is maintained by a 3rd party: Cognetif.com
Installation
Installation with composer:
$ compose require cognetif/poka-api
Usage
Services will extend either the CollectionService representing an array of objects or ObjectService representing a single object.
ObjectModel
All objects either in the CollectionService items or returned by an ObjectService are of the ObjectModel type and fields are dynamically accessible via their magic properties:
$myObject = new ObjectModel();
$myObject->populateFromArray([
'prop1' => 'hello',
'prop2' => 'world'
]);
echo $myObject->prop1 . ' ' . $myObject->prop2;
//Output: hello world
You can determine if an object model data has been loaded by its service with the loaded()
function:
$myService = new SomeCollectionService();
/** @var ObjectModel $item */
foreach ($myService->getAll() as $item) {
if ($item->loaded()) {
//Item has been loaded with data.
echo $item->property1;
}
}
ObjectServices
CollectionService is a PokaApi service and can do the following API related methods:
ObjectService::getById($id, $data = []):ObjectModel
- Will do a request for a specific API item id. optional parameters can be passed through the$data
array.
CollectionServices
CollectionServices can also do the following collection related methods:
CollectionService::add(ObjectModel $anObject);
Appends an ObjectModel onto the data setCollectionService::merge(ObjectModel[] $arrayOfObjects);
Merges an array of ObjectModel into the current data setCollectionService::count(): int;
Returns the number of items in the collectionCollectionService::getById((int) $id, $idProperty = 'id'): ObjectModel
Get 1 ObjectModel by searching by the property given as$idProperty
CollectionService::clear();
Clear the data setCollectionService::items(): array;
Returns the full data set of the collection
CollectionService is also a PokaApi services and can do the following API related methods:
CollectionService::getAll($data = [])
Get the entire data set. Multiple paginated API calls are made. Query Parameters can be passed via$data
arrayCollectionService::getPage($data = [], $refresh = true)
Get 1 page of data. Use pagination functions to move pages. Query Parameters can be passed via$data
array
CollectionService is also a Paginated service and can do the following API related methods:
CollectionService::incrementPage();
Increments the page for the next requestCollectionService::offset(): int
Returns the current pagination offsetCollectionService::nextPage(): int
Returns the number of the next pageCollectionService::lastPage(): int
Returns the number of the last page or 0 if noneCollectionService::page(): int
Returns the number of the current pageCollectionService::limit(): int
Returns the page size limitCollectionService::setLimit(int $limit)
Sets the page size limit
License
This library is protected under the MIT license. Please read the terms of the License.
Issues / Contributing
Contributions are welcome and encouraged. This library is open source but maintained by Cognetif.com. Please feel free to open an issue at: https://gitlab.com/cognetif-os/poka-api-client