Download the PHP package bluerocktel/php-sdk without Composer
On this page you can find all versions of the php package bluerocktel/php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bluerocktel/php-sdk
More information about bluerocktel/php-sdk
Files in bluerocktel/php-sdk
Package php-sdk
Short Description The Official BlueRockTEL API PHP Client/SDK
License MIT
Informations about the package php-sdk
php-sdk
This package is a light PHP Wrapper / SDK for the BlueRockTEL Admin API.
- Installation
- Authentication
- Client Code Grant
- Password Grant
- Usage
- Requests
- Resources
- Responses
- Entities
- Pagination
- Extending the SDK
Installation
This library requires PHP >=8.1
.
You can install the package via composer:
Authentication
BlueRockTEL APIs supports OAuth2 for authentication. However, this package currently only supports the Password Grant authentication flow.
Client Code Grant
Not supported yet.
Password Grant
To connect using your usual BlueRockTEL credentials, first initiate the BlueRockTELConnector
class providing your instance URL, email and password :
If the connector fails to retrive a Bearer token from the provided credentials, a BlueRockTEL\SDK\Exceptions\AuthenticationException
will be thrown.
Otherwise, you can start testing the API by calling the version()
method of Helper resource :
Usage
To query the API, you can either call each API Endpoints requests individually, or make use of provided Resources classes which groups the requests into clusters.
Using Requests
Using single requests is pretty straightforward. You can use the call()
method of the BlueRockTELConnector
class to send the desired request to the instance :
Using Resources
Using resources is a more convenient way to query the API. Each Resource class groups requests by specific API namespaces (Customer, Prospect...).
Resources classes usually provide (but are not limited to) the following methods :
👉 The
upsert()
method is a simple alias : it will call theupdate()
method if the given entity has an id, or thestore()
method if not.
Each of those namespace resources can be accessed using the BlueRockTELConnector
instance :
If needed, it is also possible to create the desired resource instance manually.
Responses
Weither you are using Requests or Resources, the response is always an instance of Saloon\Http\Response
class.
It provides some useful methods to check the response status and get the response data.
You can learn more about responses by reading the Saloon documentation, which this SDK uses underneath.
Entities (DTO)
When working with APIs, dealing with a raw or JSON response can be tedious and unpredictable.
To make it easier, this SDK provides a way to transform the response data into a Data Transfer Object (DTO) (later called Entities). This way, you are aware of the structure of the data you are working with, and you can access the data using object typed properties instead of untyped array keys.
Although you can use the dto()
method to transform the response data into an entity, it is recommended to use the dtoOrFail()
method instead. This method will throw an exception if the response status is not 2xx, instead of returning an empty DTO.
It is still possible to access the underlying response object using the getResponse()
method of the DTO :
Learn more about working with Data tranfert objects on the Saloon documentation.
The create/update/upsert routes will often ask for a DTO as first parameter :
Pagination
On some index/search routes, the BlueRockTEL API will use a pagination.
If you need to iterate on all pages of the endpoint, you may find handy to use the connector's paginate()
method :
Read more about lazy paginations on the Saloon documentation.
Extending the SDK
You may easily extend the SDK by creating your own Resources, Requests, and Entities.
Then, by extending the BlueRockTELConnector
class, add you new resources to the connector :
All versions of php-sdk with dependencies
nesbot/carbon Version ^2.68
illuminate/collections Version >=9.0
saloonphp/saloon Version ^3.0
saloonphp/rate-limit-plugin Version ^2.0
saloonphp/pagination-plugin Version ^2.0