PHP code example of vgip / intime

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

    

vgip / intime example snippets




use Vgip\Intime\Api\Config AS IntimeApiConfig;
use Vgip\Intime\Api\Api AS IntimeApi;

$apiKey = '10000000000001234567';

/** Set default configuration */
$intimeApiConfig        = new IntimeApiConfig();

/** Set configuration (rewrite defaults) */
$intimeApiConfig->setKey($apiKey);
$intimeApiConfig->setRestRequestType('POST');

/** Connect to API and get all district in region with id 2 */
$intimeApi              = new IntimeApi($intimeApiConfig);
$resultConnection       = $intimeApi->getLocalityByRegionId(20);

$availableResultVariant = [
    1 => 'Raw data as string',
    2 => 'Raw data as array',
    3 => 'Converted and validated data as array',
    4 => 'Converted and validated data as object',
];

/** Set the format and actions for the received data */
$resultVariant = 3;

/** Limitations - under construction 
 * 
 *      ResultConnection methods getAnswerArray() (3) and getAnswer() (4) are available only 
 *  for IntimeApi directories (methods):
 * 
 *  getBranch()
 *  getCountry()
 *  getDistrict()
 *  getLocality()
 *  getRegion()
 * and similar.
 */

if (1 === $resultVariant) {
    $dataRaw        = $resultConnection->getAnswerRaw();
    $resData = $dataRaw;
} elseif (2 === $resultVariant) {
    $dataArrayRaw   = $resultConnection->getAnswerArrayRaw();
    $resData = $dataArrayRaw;
} elseif (3 === $resultVariant) {
    $data           = $resultConnection->getAnswerArray();
    $resData = $data;
} elseif (4 === $resultVariant) {
    $dataObj        = $resultConnection->getAnswer();
    $resData = $dataObj;
}

/** Error view if present */
$error = $resultConnection->getError();
$errorCounter = $error->getErrorCounter();
if ($errorCounter > 0) {
    print_r($error->getErrorAll());
}

print_r($resData);