PHP code example of sspat / profiru

1. Go to this page and download the library: Download sspat/profiru 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/ */

    

sspat / profiru example snippets


use GuzzleHttp\RequestOptions;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
use sspat\ProfiRu\Client;
use sspat\ProfiRu\Constants\Domains;

// Create an instance of any PSR-18 compliant HTTP Client and pass your partnership SSL certificate and key paths
$httpClient = GuzzleAdapter::createWithConfig([
    RequestOptions::TIMEOUT => 5,
    RequestOptions::SSL_KEY => 'partner.key',
    RequestOptions::CERT => 'partner.crt',
    RequestOptions::VERIFY => false,
]);
// Create an instance of the API client, passing the HTTP client to it
$api = new Client($httpClient);

// Get Locations dictionary
$locations = $api->getLocations();
// Get Services dictionary
$services = $api->getServices();

// For requests to the pagination API an API domain must be specified
$organizations = $api->getOrganizations(Domains::HEALTHCARE);
$specialists = $api->getSpecialists(Domains::BEAUTY);

$organizations = $api->getOrganizations(
    Domains::HEALTHCARE,
    [
         'city'   => Cities::MOSCOW,
         'from'   => 220,
         'count'  => 10,
         'scope'  => Scopes::SCOPE_FULL,
         'ip'     => '144.135.23.1',
         'models' => [
             Models::ASSOCIATION,
             Models::ASSOCIATION_STRUCTURE_UNIT
         ]
    ]
);

// Get Locations dictionary
$locations = $api->getLocations();
// Get response body as Array
$locationsArray = $locations->asArray();
// Get PSR-7 response object
$psrResponse = $locations->response();
var_dump((string) $psrResponse->getBody());

use sspat\ProfiRu\Exceptions\ErrorResponse;

try {
    $services = $api->getServices();
} catch (ErrorResponse $e) {
    var_dump($e->getErrors());
}