cognetif/poka-api

This package is abandoned and no longer maintained. No replacement package was suggested.

Poka Api - To interact with Poka API

v1.4.2 2022-02-18 18:50 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 set
  • CollectionService::merge(ObjectModel[] $arrayOfObjects); Merges an array of ObjectModel into the current data set
  • CollectionService::count(): int; Returns the number of items in the collection
  • CollectionService::getById((int) $id, $idProperty = 'id'): ObjectModel Get 1 ObjectModel by searching by the property given as $idProperty
  • CollectionService::clear(); Clear the data set
  • CollectionService::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 array
  • CollectionService::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 request
  • CollectionService::offset(): int Returns the current pagination offset
  • CollectionService::nextPage(): int Returns the number of the next page
  • CollectionService::lastPage(): int Returns the number of the last page or 0 if none
  • CollectionService::page(): int Returns the number of the current page
  • CollectionService::limit(): int Returns the page size limit
  • CollectionService::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