PHP code example of bluerocktel / php-sdk

1. Go to this page and download the library: Download bluerocktel/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bluerocktel / php-sdk example snippets


use BlueRockTEL\SDK\BlueRockTELConnector;

$api = new BlueRockTELConnector(
  'https://telecomxxxx-admin.bluerocktel.net/api/',
  '[email protected]',
  'secret',
);

$response = $api->helper()->version();

var_dump(
  $response->failed(), // true is the request returned 4xx or 5xx code.
  $response->json(),   // json response as an array
);

use BlueRockTEL\SDK\BlueRockTELConnector;
use BlueRockTEL\SDK\Endpoints;

$api = new BlueRockTELConnector(BLUEROCKTEL_API_URL, BLUEROCKTEL_API_USERNAME, BLUEROCKTEL_API_PASSWORD);

$response = $api->call(
  new Endpoints\GetVersionRequest()
);

$response = $api->call(
  new Endpoints\Prospects\GetProspectRequest(id: $prospectId)
);

use BlueRockTEL\SDK\BlueRockTELConnector;

$api = new BlueRockTELConnector(BLUEROCKTEL_API_URL, BLUEROCKTEL_API_USERNAME, BLUEROCKTEL_API_PASSWORD);

$query = [
    'filter' => [
        'name' => 'Acme Enterprise',
        'term_match' => 'PR0001'
    ],
    'sort' => '-created_at',
];

$response = $api->prospect()->index(
    query: $query,
    perPage: 20,
    page: 1,
);

class NamespaceResource
{
    public function index(array $params = [], int $perPage = 20, int $page = 1): Response;
    public function show(int $id): Response;
    public function store(Entity $entity): Response;
    public function update(Entity $entity): Response;
    public function upsert(Entity $entity): Response;
    public function delete(int $id): Response;
}

$connector = new BlueRockTELConnector(...);

$connector->note(): Resources\NoteResource
$connector->prospect(): Resources\ProspectResource
$connector->customerFile(): Resources\CustomerFileResource
...

use BlueRockTEL\SDK\BlueRockTELConnector;
use BlueRockTEL\SDK\Resources\ProspectResource;

$api = new BlueRockTELConnector();
$resource = new ProspectResource($api);

$prospect = $resource->show($prospectId);
$resource->upsert($prospect);

// Check response status
$response->ok();
$response->failed();
$response->status();
$response->headers();

// Get response data
$response->json(); # as an array
$response->body(); # as an raw string
$response->dtoOrFail(); # as a Data Transfer Object

$response = $api->prospect()->show(id: 92);

/** @var \BlueRockTEL\SDK\Entities\Prospect */
$prospect = $response->dtoOrFail();

$entity = $response->dtoOrFail();   // \BlueRockTEL\SDK\Contracts\Entity
$entity->getResponse();             // \Saloon\Http\Response

use BlueRockTEL\SDK\Entities\Prospect;

// create
$response = $api->prospect()->store(
    prospect: new Prospect(
        name: 'Acme Enterprise',
        customerAccount: 'PR0001',
    ),
);

$prospect = $response->dtoOrFail();

// update
$prospect->name = 'Acme Enterprise Inc.';
$api->prospect()->update($prospect);

$query = [
  'sort' => 'created_at',
];

# Create a PagedPaginator instance
$paginator = $api->paginate(new GetProspectsRequest($query));

# Iterate on all pages entities, using lazy loading for performance
foreach ($paginator->items() as $prospect) {
    $name = $prospect->name;
    $customerAccount = $prospect->customerAccount;
}

use BlueRockTEL\SDK\BlueRockTELConnector;

class MyCustomConnector extends BlueRockTELConnector
{
    public function defaultConfig(): array
    {
        return [
            'timeout' => 120,
        ];
    }

    public function customResource(): \App\Resources\CustomResource
    {
        return new \App\Resources\CustomResource($this);
    }
}

$api = new MyCustomConnector(BLUEROCKTEL_API_URL, BLUEROCKTEL_API_USERNAME, BLUEROCKTEL_API_PASSWORD);
$api->customResource()->index();

composer