2014-11-06 02:44:52 +03:00
|
|
|
<?php
|
2016-03-09 02:31:29 +03:00
|
|
|
|
2016-04-10 00:46:08 +03:00
|
|
|
/**
|
2017-06-22 00:55:08 +03:00
|
|
|
* PHP version 5.4
|
2016-04-10 00:46:08 +03:00
|
|
|
*
|
|
|
|
* API client class
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
|
|
|
|
2014-11-06 02:44:52 +03:00
|
|
|
namespace RetailCrm;
|
|
|
|
|
2017-06-22 00:55:08 +03:00
|
|
|
use RetailCrm\Client\ApiVersion3;
|
|
|
|
use RetailCrm\Client\ApiVersion4;
|
|
|
|
use RetailCrm\Client\ApiVersion5;
|
2014-11-06 02:44:52 +03:00
|
|
|
|
|
|
|
/**
|
2017-06-22 00:55:08 +03:00
|
|
|
* PHP version 5.4
|
2016-03-09 02:31:29 +03:00
|
|
|
*
|
|
|
|
* API client class
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
2014-11-06 02:44:52 +03:00
|
|
|
*/
|
|
|
|
class ApiClient
|
|
|
|
{
|
2017-06-22 00:55:08 +03:00
|
|
|
public $request;
|
|
|
|
public $version;
|
2016-01-09 15:23:50 +03:00
|
|
|
|
2017-06-22 16:42:42 +03:00
|
|
|
const V3 = 'v3';
|
|
|
|
const V4 = 'v4';
|
|
|
|
const V5 = 'v5';
|
|
|
|
|
2016-01-09 15:23:50 +03:00
|
|
|
/**
|
2017-06-22 00:55:08 +03:00
|
|
|
* Init version based client
|
2016-01-09 15:23:50 +03:00
|
|
|
*
|
2017-06-22 00:55:08 +03:00
|
|
|
* @param string $url api url
|
|
|
|
* @param string $apiKey api key
|
|
|
|
* @param string $version api version
|
|
|
|
* @param string $site site code
|
2019-08-30 14:10:52 +03:00
|
|
|
* @param bool $debug debug mode
|
2016-01-09 15:23:50 +03:00
|
|
|
*/
|
2019-08-30 14:10:52 +03:00
|
|
|
public function __construct($url, $apiKey, $version = self::V5, $site = null, $debug = false)
|
2016-01-09 15:23:50 +03:00
|
|
|
{
|
2017-06-22 00:55:08 +03:00
|
|
|
$this->version = $version;
|
2016-01-09 15:23:50 +03:00
|
|
|
|
2017-06-22 00:55:08 +03:00
|
|
|
switch ($version) {
|
2017-06-22 16:42:42 +03:00
|
|
|
case self::V4:
|
2019-08-30 14:10:52 +03:00
|
|
|
$this->request = new ApiVersion4($url, $apiKey, $version, $site, $debug);
|
2017-06-22 00:55:08 +03:00
|
|
|
break;
|
2017-06-22 16:42:42 +03:00
|
|
|
case self::V3:
|
2019-08-30 14:10:52 +03:00
|
|
|
$this->request = new ApiVersion3($url, $apiKey, $version, $site, $debug);
|
2017-06-22 00:55:08 +03:00
|
|
|
break;
|
2018-02-20 17:50:45 +03:00
|
|
|
default:
|
2019-08-30 14:10:52 +03:00
|
|
|
$this->request = new ApiVersion5($url, $apiKey, $version, $site, $debug);
|
2018-02-20 17:50:45 +03:00
|
|
|
break;
|
2016-11-28 14:38:03 +03:00
|
|
|
}
|
2016-06-06 17:53:05 +03:00
|
|
|
}
|
|
|
|
|
2014-11-27 11:23:44 +03:00
|
|
|
/**
|
2017-06-22 00:55:08 +03:00
|
|
|
* Get API version
|
2014-11-27 11:23:44 +03:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-06-22 00:55:08 +03:00
|
|
|
public function getVersion()
|
2014-11-27 11:23:44 +03:00
|
|
|
{
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->version;
|
2014-11-27 11:23:44 +03:00
|
|
|
}
|
2014-11-10 03:12:50 +03:00
|
|
|
}
|