diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index 0886aea..251b50e 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -14,10 +14,11 @@ namespace RetailCrm; -use RetailCrm\Client\V4\Loader as V4; -use RetailCrm\Client\V5\Loader as V5; -use RetailCrm\Traits\CoreTrait; -use RetailCrm\Traits\StatisticTrait; +use RetailCrm\Client\ApiVersion3; +use RetailCrm\Client\ApiVersion4; +use RetailCrm\Client\ApiVersion5; +use RetailCrm\Methods\Core; +use RetailCrm\Methods\Statistic; /** * PHP version 5.4 @@ -47,14 +48,17 @@ class ApiClient { switch ($version) { case 'v5': - $this->request = new V5($url, $apiKey, $version, $site); + $this->request = new ApiVersion5($url, $apiKey, $version, $site); break; case 'v4': - $this->request = new V4($url, $apiKey, $version, $site); + $this->request = new ApiVersion4($url, $apiKey, $version, $site); + break; + case 'v3': + $this->request = new ApiVersion3($url, $apiKey, $version, $site); break; } } - use CoreTrait; - use StatisticTrait; + use Core; + use Statistic; } diff --git a/lib/RetailCrm/Client/V4/Loader.php b/lib/RetailCrm/Client/AbstractLoader.php similarity index 69% rename from lib/RetailCrm/Client/V4/Loader.php rename to lib/RetailCrm/Client/AbstractLoader.php index dd348de..aa81dac 100644 --- a/lib/RetailCrm/Client/V4/Loader.php +++ b/lib/RetailCrm/Client/AbstractLoader.php @@ -12,10 +12,9 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Client\V4; +namespace RetailCrm\Client; use RetailCrm\Http\Client; -use RetailCrm\Traits\V4; /** * PHP version 5.4 @@ -28,7 +27,7 @@ use RetailCrm\Traits\V4; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -class Loader +abstract class AbstractLoader { protected $siteCode; protected $client; @@ -38,28 +37,24 @@ class Loader * * @param string $url api url * @param string $apiKey api key + * @param string $version api version * @param string $site site code - * */ - public function __construct($url, $apiKey, $site = null) + public function __construct($url, $apiKey, $version, $site = null) { if ('/' !== $url[strlen($url) - 1]) { $url .= '/'; } - $url = $url . 'api/v4'; + if (empty($version) || !in_array($version, ['v3', 'v4', 'v5'])) { + throw new \InvalidArgumentException( + 'Version parameter must be not empty and must be equal one of v3|v4|v5' + ); + } + + $url = $url . 'api/' . $version; $this->client = new Client($url, ['apiKey' => $apiKey]); $this->siteCode = $site; } - - use V4\CustomersTrait; - use V4\DeliveryTrait; - use V4\MarketplaceTrait; - use V4\OrdersTrait; - use V4\PacksTrait; - use V4\ReferencesTrait; - use V4\StoresTrait; - use V4\TelephonyTrait; - use V4\UsersTrait; } diff --git a/lib/RetailCrm/Client/V5/Loader.php b/lib/RetailCrm/Client/ApiVersion3.php similarity index 50% rename from lib/RetailCrm/Client/V5/Loader.php rename to lib/RetailCrm/Client/ApiVersion3.php index 46473fa..691c727 100644 --- a/lib/RetailCrm/Client/V5/Loader.php +++ b/lib/RetailCrm/Client/ApiVersion3.php @@ -12,10 +12,9 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Client\V5; +namespace RetailCrm\Client; -use RetailCrm\Http\Client; -use RetailCrm\Traits\V5; +use RetailCrm\Methods\V3; /** * PHP version 5.4 @@ -28,42 +27,26 @@ use RetailCrm\Traits\V5; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -class Loader +class ApiVersion3 extends AbstractLoader { - protected $siteCode; - protected $client; - /** * Init version based client * * @param string $url api url * @param string $apiKey api key + * @param string $version api version * @param string $site site code * */ - public function __construct($url, $apiKey, $site = null) + public function __construct($url, $apiKey, $version, $site) { - if ('/' !== $url[strlen($url) - 1]) { - $url .= '/'; - } - - $url = $url . 'api/v5'; - - $this->client = new Client($url, ['apiKey' => $apiKey]); - $this->siteCode = $site; + parent::__construct($url, $apiKey, $version, $site); } - - use V5\CustomersTrait; - use V5\CustomFieldsTrait; - use V5\DeliveryTrait; - use V5\MarketplaceTrait; - use V5\OrdersTrait; - use V5\PacksTrait; - use V5\ReferencesTrait; - use V5\SegmentsTrait; - use V5\StoresTrait; - use V5\TasksTrait; - use V5\TelephonyTrait; - use V5\UsersTrait; + use V3\Customers; + use V3\Orders; + use V3\Packs; + use V3\References; + use V3\Stores; + use V3\Telephony; } diff --git a/lib/RetailCrm/Client/ApiVersion4.php b/lib/RetailCrm/Client/ApiVersion4.php new file mode 100644 index 0000000..283021b --- /dev/null +++ b/lib/RetailCrm/Client/ApiVersion4.php @@ -0,0 +1,55 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Client; + +use RetailCrm\Methods\V4; + +/** + * PHP version 5.4 + * + * API client class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +class ApiVersion4 extends AbstractLoader +{ + /** + * Init version based client + * + * @param string $url api url + * @param string $apiKey api key + * @param string $version api version + * @param string $site site code + * + */ + public function __construct($url, $apiKey, $version, $site) + { + parent::__construct($url, $apiKey, $version, $site); + } + + use V4\Customers; + use V4\Delivery; + use V4\Marketplace; + use V4\Orders; + use V4\Packs; + use V4\References; + use V4\Stores; + use V4\Telephony; + use V4\Users; +} diff --git a/lib/RetailCrm/Client/ApiVersion5.php b/lib/RetailCrm/Client/ApiVersion5.php new file mode 100644 index 0000000..2fc69bb --- /dev/null +++ b/lib/RetailCrm/Client/ApiVersion5.php @@ -0,0 +1,58 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Client; + +use RetailCrm\Methods\V5; + +/** + * PHP version 5.4 + * + * API client class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +class ApiVersion5 extends AbstractLoader +{ + /** + * Init version based client + * + * @param string $url api url + * @param string $apiKey api key + * @param string $version api version + * @param string $site site code + * + */ + public function __construct($url, $apiKey, $version, $site) + { + parent::__construct($url, $apiKey, $version, $site); + } + + use V5\Customers; + use V5\CustomFields; + use V5\Delivery; + use V5\Marketplace; + use V5\Orders; + use V5\Packs; + use V5\References; + use V5\Segments; + use V5\Stores; + use V5\Tasks; + use V5\Telephony; + use V5\Users; +} diff --git a/lib/RetailCrm/Traits/CoreTrait.php b/lib/RetailCrm/Methods/Core.php similarity index 95% rename from lib/RetailCrm/Traits/CoreTrait.php rename to lib/RetailCrm/Methods/Core.php index 644b8ee..2669773 100644 --- a/lib/RetailCrm/Traits/CoreTrait.php +++ b/lib/RetailCrm/Methods/Core.php @@ -3,7 +3,7 @@ /** * PHP version 5.4 * - * CoreTrait class + * Core class * * @category RetailCrm * @package RetailCrm @@ -12,12 +12,12 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits; +namespace RetailCrm\Methods; /** * PHP version 5.4 * - * CoreTrait class + * Core class * * @category RetailCrm * @package RetailCrm @@ -25,7 +25,7 @@ namespace RetailCrm\Traits; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait CoreTrait +trait Core { /** * Return current site diff --git a/lib/RetailCrm/Traits/StatisticTrait.php b/lib/RetailCrm/Methods/Statistic.php similarity index 90% rename from lib/RetailCrm/Traits/StatisticTrait.php rename to lib/RetailCrm/Methods/Statistic.php index 657fbe6..64c3cdf 100644 --- a/lib/RetailCrm/Traits/StatisticTrait.php +++ b/lib/RetailCrm/Methods/Statistic.php @@ -3,7 +3,7 @@ /** * PHP version 5.4 * - * StatisticTrait class + * Statistic class * * @category RetailCrm * @package RetailCrm @@ -12,14 +12,14 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits; +namespace RetailCrm\Methods; use RetailCrm\Response\ApiResponse; /** * PHP version 5.4 * - * StatisticTrait class + * Statistic class * * @category RetailCrm * @package RetailCrm @@ -27,7 +27,7 @@ use RetailCrm\Response\ApiResponse; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait StatisticTrait +trait Statistic { /** * Update CRM basic statistic diff --git a/lib/RetailCrm/Traits/V4/CustomersTrait.php b/lib/RetailCrm/Methods/V3/Customers.php similarity index 88% rename from lib/RetailCrm/Traits/V4/CustomersTrait.php rename to lib/RetailCrm/Methods/V3/Customers.php index 5760a97..01c7e49 100644 --- a/lib/RetailCrm/Traits/V4/CustomersTrait.php +++ b/lib/RetailCrm/Methods/V3/Customers.php @@ -12,7 +12,7 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V4; +namespace RetailCrm\Methods\V3; /** * PHP version 5.4 @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V4; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait CustomersTrait +trait Customers { /** * Returns filtered customers list @@ -203,33 +203,4 @@ trait CustomersTrait ) ); } - - /** - * Get customers history - * @param array $filter - * @param null $page - * @param null $limit - * - * @return ApiResponse - */ - public function customersHistory(array $filter = [], $page = null, $limit = null) - { - $parameters = []; - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/customers/history', - $this->client::METHOD_GET, - $parameters - ); - } } diff --git a/lib/RetailCrm/Traits/V4/OrdersTrait.php b/lib/RetailCrm/Methods/V3/Orders.php similarity index 99% rename from lib/RetailCrm/Traits/V4/OrdersTrait.php rename to lib/RetailCrm/Methods/V3/Orders.php index b3a20bc..24a51c3 100644 --- a/lib/RetailCrm/Traits/V4/OrdersTrait.php +++ b/lib/RetailCrm/Methods/V3/Orders.php @@ -12,7 +12,7 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V4; +namespace RetailCrm\Methods\V3; /** * PHP version 5.4 @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V4; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait OrdersTrait +trait Orders { /** diff --git a/lib/RetailCrm/Traits/V4/PacksTrait.php b/lib/RetailCrm/Methods/V3/Packs.php similarity index 99% rename from lib/RetailCrm/Traits/V4/PacksTrait.php rename to lib/RetailCrm/Methods/V3/Packs.php index ab16954..90db61c 100644 --- a/lib/RetailCrm/Traits/V4/PacksTrait.php +++ b/lib/RetailCrm/Methods/V3/Packs.php @@ -12,7 +12,7 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V4; +namespace RetailCrm\Methods\V3; /** * PHP version 5.4 @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V4; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait PacksTrait +trait Packs { /** * Get orders assembly list diff --git a/lib/RetailCrm/Traits/V4/ReferencesTrait.php b/lib/RetailCrm/Methods/V3/References.php similarity index 90% rename from lib/RetailCrm/Traits/V4/ReferencesTrait.php rename to lib/RetailCrm/Methods/V3/References.php index d36c017..cf49674 100644 --- a/lib/RetailCrm/Traits/V4/ReferencesTrait.php +++ b/lib/RetailCrm/Methods/V3/References.php @@ -12,7 +12,7 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V4; +namespace RetailCrm\Methods\V3; /** * PHP version 5.4 @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V4; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait ReferencesTrait +trait References { /** * Returns available county list @@ -496,52 +496,4 @@ trait ReferencesTrait ['store' => json_encode($data)] ); } - - /** - * Get prices types - * - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function pricesTypes() - { - return $this->client->makeRequest( - '/reference/price-types', - $this->client::METHOD_GET - ); - } - - /** - * Edit price type - * - * @param array $data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function pricesEdit(array $data) - { - if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "code" parameter.' - ); - } - - if (!array_key_exists('name', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "name" parameter.' - ); - } - - return $this->client->makeRequest( - sprintf('/reference/price-types/%s/edit', $data['code']), - $this->client::METHOD_POST, - ['priceType' => json_encode($data)] - ); - } } diff --git a/lib/RetailCrm/Methods/V3/Stores.php b/lib/RetailCrm/Methods/V3/Stores.php new file mode 100644 index 0000000..4d847d2 --- /dev/null +++ b/lib/RetailCrm/Methods/V3/Stores.php @@ -0,0 +1,90 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Methods\V3; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait Stores +{ + /** + * Get purchace prices & stock balance + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function storeInventories(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/store/inventories', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Upload store inventories + * + * @param array $offers offers data + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function storeInventoriesUpload(array $offers, $site = null) + { + if (!count($offers)) { + throw new \InvalidArgumentException( + 'Parameter `offers` must contains array of the offers' + ); + } + + return $this->client->makeRequest( + '/store/inventories/upload', + $this->client::METHOD_POST, + $this->fillSite($site, ['offers' => json_encode($offers)]) + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/TelephonyTrait.php b/lib/RetailCrm/Methods/V3/Telephony.php similarity index 56% rename from lib/RetailCrm/Traits/V4/TelephonyTrait.php rename to lib/RetailCrm/Methods/V3/Telephony.php index 81ae7ad..ebb967d 100644 --- a/lib/RetailCrm/Traits/V4/TelephonyTrait.php +++ b/lib/RetailCrm/Methods/V3/Telephony.php @@ -3,7 +3,7 @@ /** * PHP version 5.4 * - * TelephonyTrait + * Telephony * * @category RetailCrm * @package RetailCrm @@ -12,12 +12,12 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V4; +namespace RetailCrm\Methods\V3; /** * PHP version 5.4 * - * TelephonyTrait class + * Telephony class * * @category RetailCrm * @package RetailCrm @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V4; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait TelephonyTrait +trait Telephony { /** * Get telephony settings @@ -50,110 +50,6 @@ trait TelephonyTrait ); } - /** - * Edit telephony settings - * - * @param string $code symbolic code - * @param string $clientId client id - * @param boolean $active telephony activity - * @param mixed $name service name - * @param mixed $makeCallUrl service init url - * @param mixed $image service logo url(svg file) - * - * @param array $additionalCodes - * @param array $externalPhones - * @param bool $allowEdit - * @param bool $inputEventSupported - * @param bool $outputEventSupported - * @param bool $hangupEventSupported - * @param bool $changeUserStatusUrl - * - * @return ApiResponse - */ - public function telephonySettingsEdit( - $code, - $clientId, - $active = false, - $name = false, - $makeCallUrl = false, - $image = false, - $additionalCodes = [], - $externalPhones = [], - $allowEdit = false, - $inputEventSupported = false, - $outputEventSupported = false, - $hangupEventSupported = false, - $changeUserStatusUrl = false - ) { - if (!isset($code)) { - throw new \InvalidArgumentException('Code must be set'); - } - - $parameters['code'] = $code; - - if (!isset($clientId)) { - throw new \InvalidArgumentException('client id must be set'); - } - - $parameters['clientId'] = $clientId; - - if (!isset($active)) { - $parameters['active'] = false; - } else { - $parameters['active'] = $active; - } - - if (!isset($name)) { - throw new \InvalidArgumentException('name must be set'); - } - - if (isset($name)) { - $parameters['name'] = $name; - } - - if (isset($makeCallUrl)) { - $parameters['makeCallUrl'] = $makeCallUrl; - } - - if (isset($image)) { - $parameters['image'] = $image; - } - - if (isset($additionalCodes)) { - $parameters['additionalCodes'] = $additionalCodes; - } - - if (isset($externalPhones)) { - $parameters['externalPhones'] = $externalPhones; - } - - if (isset($allowEdit)) { - $parameters['allowEdit'] = $allowEdit; - } - - if (isset($inputEventSupported)) { - $parameters['inputEventSupported'] = $inputEventSupported; - } - - if (isset($outputEventSupported)) { - $parameters['outputEventSupported'] = $outputEventSupported; - } - - if (isset($hangupEventSupported)) { - $parameters['hangupEventSupported'] = $hangupEventSupported; - } - - if (isset($changeUserStatusUrl)) { - $parameters['changeUserStatusUrl'] = $changeUserStatusUrl; - } - - return $this->client->makeRequest( - "/telephony/setting/$code/edit", - $this->client::METHOD_POST, - ['configuration' => json_encode($parameters)] - ); - } - /** * Call event * diff --git a/lib/RetailCrm/Methods/V4/Customers.php b/lib/RetailCrm/Methods/V4/Customers.php new file mode 100644 index 0000000..3101279 --- /dev/null +++ b/lib/RetailCrm/Methods/V4/Customers.php @@ -0,0 +1,62 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Methods\V4; + +use RetailCrm\Methods\V3\Customers as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait Customers +{ + use Previous; + + /** + * Get customers history + * @param array $filter + * @param null $page + * @param null $limit + * + * @return ApiResponse + */ + public function customersHistory(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/customers/history', + $this->client::METHOD_GET, + $parameters + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/DeliveryTrait.php b/lib/RetailCrm/Methods/V4/Delivery.php similarity index 98% rename from lib/RetailCrm/Traits/V4/DeliveryTrait.php rename to lib/RetailCrm/Methods/V4/Delivery.php index de1071a..2e94f8b 100644 --- a/lib/RetailCrm/Traits/V4/DeliveryTrait.php +++ b/lib/RetailCrm/Methods/V4/Delivery.php @@ -12,7 +12,7 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V4; +namespace RetailCrm\Methods\V4; /** * PHP version 5.4 @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V4; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait DeliveryTrait +trait Delivery { /** * Get delivery settings diff --git a/lib/RetailCrm/Traits/V4/MarketplaceTrait.php b/lib/RetailCrm/Methods/V4/Marketplace.php similarity index 93% rename from lib/RetailCrm/Traits/V4/MarketplaceTrait.php rename to lib/RetailCrm/Methods/V4/Marketplace.php index 334b343..116a8a1 100644 --- a/lib/RetailCrm/Traits/V4/MarketplaceTrait.php +++ b/lib/RetailCrm/Methods/V4/Marketplace.php @@ -3,7 +3,7 @@ /** * PHP version 5.4 * - * MarketplaceTrait + * Marketplace * * @category RetailCrm * @package RetailCrm @@ -12,12 +12,12 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V4; +namespace RetailCrm\Methods\V4; /** * PHP version 5.4 * - * MarketplaceTrait class + * Marketplace class * * @category RetailCrm * @package RetailCrm @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V4; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait MarketplaceTrait +trait Marketplace { /** diff --git a/lib/RetailCrm/Methods/V4/Orders.php b/lib/RetailCrm/Methods/V4/Orders.php new file mode 100644 index 0000000..4bda9ce --- /dev/null +++ b/lib/RetailCrm/Methods/V4/Orders.php @@ -0,0 +1,271 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Methods\V4; + +use RetailCrm\Methods\V3\Orders as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait Orders +{ + + use Previous; + + /** + * Returns filtered orders list + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersList(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/orders', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Create an order + * + * @param array $order order data + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersCreate(array $order, $site = null) + { + if (!count($order)) { + throw new \InvalidArgumentException( + 'Parameter `order` must contains a data' + ); + } + + return $this->client->makeRequest( + '/orders/create', + $this->client::METHOD_POST, + $this->fillSite($site, ['order' => json_encode($order)]) + ); + } + + /** + * Save order IDs' (id and externalId) association into CRM + * + * @param array $ids order identificators + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersFixExternalIds(array $ids) + { + if (! count($ids)) { + throw new \InvalidArgumentException( + 'Method parameter must contains at least one IDs pair' + ); + } + + return $this->client->makeRequest( + '/orders/fix-external-ids', + $this->client::METHOD_POST, + ['orders' => json_encode($ids) + ] + ); + } + + /** + * Returns statuses of the orders + * + * @param array $ids (default: array()) + * @param array $externalIds (default: array()) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersStatuses(array $ids = [], array $externalIds = []) + { + $parameters = []; + + if (count($ids)) { + $parameters['ids'] = $ids; + } + if (count($externalIds)) { + $parameters['externalIds'] = $externalIds; + } + + return $this->client->makeRequest( + '/orders/statuses', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Upload array of the orders + * + * @param array $orders array of orders + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersUpload(array $orders, $site = null) + { + if (!count($orders)) { + throw new \InvalidArgumentException( + 'Parameter `orders` must contains array of the orders' + ); + } + + return $this->client->makeRequest( + '/orders/upload', + $this->client::METHOD_POST, + $this->fillSite($site, ['orders' => json_encode($orders)]) + ); + } + + /** + * Get order by id or externalId + * + * @param string $id order identificator + * @param string $by (default: 'externalId') + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersGet($id, $by = 'externalId', $site = null) + { + $this->checkIdParameter($by); + + return $this->client->makeRequest( + "/orders/$id", + $this->client::METHOD_GET, + $this->fillSite($site, ['by' => $by]) + ); + } + + /** + * Edit an order + * + * @param array $order order data + * @param string $by (default: 'externalId') + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersEdit(array $order, $by = 'externalId', $site = null) + { + if (!count($order)) { + throw new \InvalidArgumentException( + 'Parameter `order` must contains a data' + ); + } + + $this->checkIdParameter($by); + + if (!array_key_exists($by, $order)) { + throw new \InvalidArgumentException( + sprintf('Order array must contain the "%s" parameter.', $by) + ); + } + + return $this->client->makeRequest( + sprintf('/orders/%s/edit', $order[$by]), + $this->client::METHOD_POST, + $this->fillSite( + $site, + ['order' => json_encode($order), 'by' => $by] + ) + ); + } + + /** + * Get orders history + * @param array $filter + * @param null $page + * @param null $limit + * + * @return ApiResponse + */ + public function ordersHistory(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/orders/history', + $this->client::METHOD_GET, + $parameters + ); + } +} diff --git a/lib/RetailCrm/Traits/V5/PacksTrait.php b/lib/RetailCrm/Methods/V4/Packs.php similarity index 85% rename from lib/RetailCrm/Traits/V5/PacksTrait.php rename to lib/RetailCrm/Methods/V4/Packs.php index fd36cfe..04fc4b9 100644 --- a/lib/RetailCrm/Traits/V5/PacksTrait.php +++ b/lib/RetailCrm/Methods/V4/Packs.php @@ -12,9 +12,9 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V4; -use RetailCrm\Traits\V4\PacksTrait as Previous; +use RetailCrm\Methods\V3\Packs as Previous; /** * PHP version 5.4 @@ -27,7 +27,7 @@ use RetailCrm\Traits\V4\PacksTrait as Previous; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait PacksTrait +trait Packs { use Previous; } diff --git a/lib/RetailCrm/Methods/V4/References.php b/lib/RetailCrm/Methods/V4/References.php new file mode 100644 index 0000000..ec1345a --- /dev/null +++ b/lib/RetailCrm/Methods/V4/References.php @@ -0,0 +1,81 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Methods\V4; + +use RetailCrm\Methods\V3\References as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait References +{ + use Previous; + + /** + * Get prices types + * + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function pricesTypes() + { + return $this->client->makeRequest( + '/reference/price-types', + $this->client::METHOD_GET + ); + } + + /** + * Edit price type + * + * @param array $data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function pricesTypesEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "name" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/price-types/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['priceType' => json_encode($data)] + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/StoresTrait.php b/lib/RetailCrm/Methods/V4/Stores.php similarity index 67% rename from lib/RetailCrm/Traits/V4/StoresTrait.php rename to lib/RetailCrm/Methods/V4/Stores.php index 8e3d8a4..bdd6e8c 100644 --- a/lib/RetailCrm/Traits/V4/StoresTrait.php +++ b/lib/RetailCrm/Methods/V4/Stores.php @@ -12,7 +12,9 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V4; +namespace RetailCrm\Methods\V4; + +use RetailCrm\Methods\V3\Stores as Previous; /** * PHP version 5.4 @@ -25,41 +27,9 @@ namespace RetailCrm\Traits\V4; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait StoresTrait +trait Stores { - /** - * Get purchace prices & stock balance - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function storeInventories(array $filter = [], $page = null, $limit = null) - { - $parameters = []; - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/store/inventories', - $this->client::METHOD_GET, - $parameters - ); - } + use Previous; /** * Get store settings @@ -111,33 +81,6 @@ trait StoresTrait ); } - /** - * Upload store inventories - * - * @param array $offers offers data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function storeInventoriesUpload(array $offers, $site = null) - { - if (!count($offers)) { - throw new \InvalidArgumentException( - 'Parameter `offers` must contains array of the offers' - ); - } - - return $this->client->makeRequest( - '/store/inventories/upload', - $this->client::METHOD_POST, - $this->fillSite($site, ['offers' => json_encode($offers)]) - ); - } - /** * Upload store prices * diff --git a/lib/RetailCrm/Methods/V4/Telephony.php b/lib/RetailCrm/Methods/V4/Telephony.php new file mode 100644 index 0000000..d1491a9 --- /dev/null +++ b/lib/RetailCrm/Methods/V4/Telephony.php @@ -0,0 +1,137 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Methods\V4; + +use RetailCrm\Methods\V3\Telephony as Previous; + +/** + * PHP version 5.4 + * + * Telephony class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait Telephony +{ + use Previous; + + /** + * Edit telephony settings + * + * @param string $code symbolic code + * @param string $clientId client id + * @param boolean $active telephony activity + * @param mixed $name service name + * @param mixed $makeCallUrl service init url + * @param mixed $image service logo url(svg file) + * + * @param array $additionalCodes + * @param array $externalPhones + * @param bool $allowEdit + * @param bool $inputEventSupported + * @param bool $outputEventSupported + * @param bool $hangupEventSupported + * @param bool $changeUserStatusUrl + * + * @return ApiResponse + */ + public function telephonySettingsEdit( + $code, + $clientId, + $active = false, + $name = false, + $makeCallUrl = false, + $image = false, + $additionalCodes = [], + $externalPhones = [], + $allowEdit = false, + $inputEventSupported = false, + $outputEventSupported = false, + $hangupEventSupported = false, + $changeUserStatusUrl = false + ) { + if (!isset($code)) { + throw new \InvalidArgumentException('Code must be set'); + } + + $parameters['code'] = $code; + + if (!isset($clientId)) { + throw new \InvalidArgumentException('client id must be set'); + } + + $parameters['clientId'] = $clientId; + + if (!isset($active)) { + $parameters['active'] = false; + } else { + $parameters['active'] = $active; + } + + if (!isset($name)) { + throw new \InvalidArgumentException('name must be set'); + } + + if (isset($name)) { + $parameters['name'] = $name; + } + + if (isset($makeCallUrl)) { + $parameters['makeCallUrl'] = $makeCallUrl; + } + + if (isset($image)) { + $parameters['image'] = $image; + } + + if (isset($additionalCodes)) { + $parameters['additionalCodes'] = $additionalCodes; + } + + if (isset($externalPhones)) { + $parameters['externalPhones'] = $externalPhones; + } + + if (isset($allowEdit)) { + $parameters['allowEdit'] = $allowEdit; + } + + if (isset($inputEventSupported)) { + $parameters['inputEventSupported'] = $inputEventSupported; + } + + if (isset($outputEventSupported)) { + $parameters['outputEventSupported'] = $outputEventSupported; + } + + if (isset($hangupEventSupported)) { + $parameters['hangupEventSupported'] = $hangupEventSupported; + } + + if (isset($changeUserStatusUrl)) { + $parameters['changeUserStatusUrl'] = $changeUserStatusUrl; + } + + return $this->client->makeRequest( + "/telephony/setting/$code/edit", + $this->client::METHOD_POST, + ['configuration' => json_encode($parameters)] + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/UsersTrait.php b/lib/RetailCrm/Methods/V4/Users.php similarity index 98% rename from lib/RetailCrm/Traits/V4/UsersTrait.php rename to lib/RetailCrm/Methods/V4/Users.php index 1f20c75..5ea8135 100644 --- a/lib/RetailCrm/Traits/V4/UsersTrait.php +++ b/lib/RetailCrm/Methods/V4/Users.php @@ -12,7 +12,7 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V4; +namespace RetailCrm\Methods\V4; /** * PHP version 5.4 @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V4; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait UsersTrait +trait Users { /** * Returns users list diff --git a/lib/RetailCrm/Traits/V5/CustomFieldsTrait.php b/lib/RetailCrm/Methods/V5/CustomFields.php similarity index 98% rename from lib/RetailCrm/Traits/V5/CustomFieldsTrait.php rename to lib/RetailCrm/Methods/V5/CustomFields.php index 693ecef..706c5ba 100644 --- a/lib/RetailCrm/Traits/V5/CustomFieldsTrait.php +++ b/lib/RetailCrm/Methods/V5/CustomFields.php @@ -3,7 +3,7 @@ /** * PHP version 5.4 * - * CustomFieldsTrait + * CustomFields * * @category RetailCrm * @package RetailCrm @@ -12,12 +12,12 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V5; /** * PHP version 5.4 * - * CustomFieldsTrait class + * CustomFields class * * @category RetailCrm * @package RetailCrm @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V5; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait CustomFieldsTrait +trait CustomFields { /** * Get custom fields list diff --git a/lib/RetailCrm/Traits/V5/CustomersTrait.php b/lib/RetailCrm/Methods/V5/Customers.php similarity index 92% rename from lib/RetailCrm/Traits/V5/CustomersTrait.php rename to lib/RetailCrm/Methods/V5/Customers.php index 6d53080..3b56107 100644 --- a/lib/RetailCrm/Traits/V5/CustomersTrait.php +++ b/lib/RetailCrm/Methods/V5/Customers.php @@ -12,9 +12,9 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V5; -use RetailCrm\Traits\V4\CustomersTrait as Previous; +use RetailCrm\Methods\V4\Customers as Previous; /** * PHP version 5.4 @@ -27,7 +27,7 @@ use RetailCrm\Traits\V4\CustomersTrait as Previous; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait CustomersTrait +trait Customers { use Previous; diff --git a/lib/RetailCrm/Traits/V5/DeliveryTrait.php b/lib/RetailCrm/Methods/V5/Delivery.php similarity index 84% rename from lib/RetailCrm/Traits/V5/DeliveryTrait.php rename to lib/RetailCrm/Methods/V5/Delivery.php index e66cf2c..71ce0a0 100644 --- a/lib/RetailCrm/Traits/V5/DeliveryTrait.php +++ b/lib/RetailCrm/Methods/V5/Delivery.php @@ -12,9 +12,9 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V5; -use RetailCrm\Traits\V4\DeliveryTrait as Previous; +use RetailCrm\Methods\V4\Delivery as Previous; /** * PHP version 5.4 @@ -27,7 +27,7 @@ use RetailCrm\Traits\V4\DeliveryTrait as Previous; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait DeliveryTrait +trait Delivery { use Previous; } diff --git a/lib/RetailCrm/Traits/V5/TelephonyTrait.php b/lib/RetailCrm/Methods/V5/Marketplace.php similarity index 78% rename from lib/RetailCrm/Traits/V5/TelephonyTrait.php rename to lib/RetailCrm/Methods/V5/Marketplace.php index 08e7f7d..0611933 100644 --- a/lib/RetailCrm/Traits/V5/TelephonyTrait.php +++ b/lib/RetailCrm/Methods/V5/Marketplace.php @@ -3,7 +3,7 @@ /** * PHP version 5.4 * - * TelephonyTrait + * Marketplace * * @category RetailCrm * @package RetailCrm @@ -12,14 +12,14 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V5; -use RetailCrm\Traits\V4\TelephonyTrait as Previous; +use RetailCrm\Methods\V4\Marketplace as Previous; /** * PHP version 5.4 * - * TelephonyTrait class + * Marketplace class * * @category RetailCrm * @package RetailCrm @@ -27,7 +27,7 @@ use RetailCrm\Traits\V4\TelephonyTrait as Previous; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait TelephonyTrait +trait Marketplace { use Previous; } diff --git a/lib/RetailCrm/Traits/V5/OrdersTrait.php b/lib/RetailCrm/Methods/V5/Orders.php similarity index 97% rename from lib/RetailCrm/Traits/V5/OrdersTrait.php rename to lib/RetailCrm/Methods/V5/Orders.php index b8db295..2c6fc46 100644 --- a/lib/RetailCrm/Traits/V5/OrdersTrait.php +++ b/lib/RetailCrm/Methods/V5/Orders.php @@ -12,10 +12,10 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V5; use RetailCrm\Response\ApiResponse; -use RetailCrm\Traits\V4\OrdersTrait as Previous; +use RetailCrm\Methods\V4\Orders as Previous; /** * PHP version 5.4 @@ -28,7 +28,7 @@ use RetailCrm\Traits\V4\OrdersTrait as Previous; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait OrdersTrait +trait Orders { use Previous; diff --git a/lib/RetailCrm/Traits/V5/ReferencesTrait.php b/lib/RetailCrm/Methods/V5/Packs.php similarity index 84% rename from lib/RetailCrm/Traits/V5/ReferencesTrait.php rename to lib/RetailCrm/Methods/V5/Packs.php index 58f576b..6db3a02 100644 --- a/lib/RetailCrm/Traits/V5/ReferencesTrait.php +++ b/lib/RetailCrm/Methods/V5/Packs.php @@ -12,9 +12,9 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V5; -use RetailCrm\Traits\V4\ReferencesTrait as Previous; +use RetailCrm\Methods\V4\Packs as Previous; /** * PHP version 5.4 @@ -27,7 +27,7 @@ use RetailCrm\Traits\V4\ReferencesTrait as Previous; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait ReferencesTrait +trait Packs { use Previous; } diff --git a/lib/RetailCrm/Methods/V5/References.php b/lib/RetailCrm/Methods/V5/References.php new file mode 100644 index 0000000..df6caf4 --- /dev/null +++ b/lib/RetailCrm/Methods/V5/References.php @@ -0,0 +1,33 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Methods\V5; + +use RetailCrm\Methods\V4\References as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait References +{ + use Previous; +} diff --git a/lib/RetailCrm/Traits/V5/SegmentsTrait.php b/lib/RetailCrm/Methods/V5/Segments.php similarity index 93% rename from lib/RetailCrm/Traits/V5/SegmentsTrait.php rename to lib/RetailCrm/Methods/V5/Segments.php index d481fda..ae0b74c 100644 --- a/lib/RetailCrm/Traits/V5/SegmentsTrait.php +++ b/lib/RetailCrm/Methods/V5/Segments.php @@ -3,7 +3,7 @@ /** * PHP version 5.4 * - * SegmentsTrait + * Segments * * @category RetailCrm * @package RetailCrm @@ -12,12 +12,12 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V5; /** * PHP version 5.4 * - * SegmentsTrait class + * Segments class * * @category RetailCrm * @package RetailCrm @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V5; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait SegmentsTrait +trait Segments { /** * Get segments list diff --git a/lib/RetailCrm/Traits/V5/StoresTrait.php b/lib/RetailCrm/Methods/V5/Stores.php similarity index 93% rename from lib/RetailCrm/Traits/V5/StoresTrait.php rename to lib/RetailCrm/Methods/V5/Stores.php index c6f8fe6..bb18e9e 100644 --- a/lib/RetailCrm/Traits/V5/StoresTrait.php +++ b/lib/RetailCrm/Methods/V5/Stores.php @@ -12,9 +12,9 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V5; -use RetailCrm\Traits\V4\StoresTrait as Previous; +use RetailCrm\Methods\V4\Stores as Previous; /** * PHP version 5.4 @@ -27,7 +27,7 @@ use RetailCrm\Traits\V4\StoresTrait as Previous; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait StoresTrait +trait Stores { use Previous; diff --git a/lib/RetailCrm/Traits/V5/TasksTrait.php b/lib/RetailCrm/Methods/V5/Tasks.php similarity index 98% rename from lib/RetailCrm/Traits/V5/TasksTrait.php rename to lib/RetailCrm/Methods/V5/Tasks.php index 6d9850e..738ce72 100644 --- a/lib/RetailCrm/Traits/V5/TasksTrait.php +++ b/lib/RetailCrm/Methods/V5/Tasks.php @@ -12,7 +12,7 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V5; /** * PHP version 5.4 @@ -25,7 +25,7 @@ namespace RetailCrm\Traits\V5; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait TasksTrait +trait Tasks { /** * Get tasks list diff --git a/lib/RetailCrm/Methods/V5/Telephony.php b/lib/RetailCrm/Methods/V5/Telephony.php new file mode 100644 index 0000000..03ed217 --- /dev/null +++ b/lib/RetailCrm/Methods/V5/Telephony.php @@ -0,0 +1,33 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Methods\V5; + +use RetailCrm\Methods\V4\Telephony as Previous; + +/** + * PHP version 5.4 + * + * Telephony class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait Telephony +{ + use Previous; +} diff --git a/lib/RetailCrm/Traits/V5/UsersTrait.php b/lib/RetailCrm/Methods/V5/Users.php similarity index 93% rename from lib/RetailCrm/Traits/V5/UsersTrait.php rename to lib/RetailCrm/Methods/V5/Users.php index 64560fa..1bd7fcb 100644 --- a/lib/RetailCrm/Traits/V5/UsersTrait.php +++ b/lib/RetailCrm/Methods/V5/Users.php @@ -12,10 +12,10 @@ * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -namespace RetailCrm\Traits\V5; +namespace RetailCrm\Methods\V5; use RetailCrm\Response\ApiResponse; -use RetailCrm\Traits\V4\UsersTrait as Previous; +use RetailCrm\Methods\V4\Users as Previous; /** * PHP version 5.4 @@ -28,7 +28,7 @@ use RetailCrm\Traits\V4\UsersTrait as Previous; * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -trait UsersTrait +trait Users { use Previous; diff --git a/lib/RetailCrm/Traits/V5/MarketplaceTrait.php b/lib/RetailCrm/Traits/V5/MarketplaceTrait.php deleted file mode 100644 index 48d4faf..0000000 --- a/lib/RetailCrm/Traits/V5/MarketplaceTrait.php +++ /dev/null @@ -1,33 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 - */ - -namespace RetailCrm\Traits\V5; - -use RetailCrm\Traits\V4\MarketplaceTrait as Previous; - -/** - * PHP version 5.4 - * - * MarketplaceTrait class - * - * @category RetailCrm - * @package RetailCrm - * @author RetailCrm - * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 - */ -trait MarketplaceTrait -{ - use Previous; -} diff --git a/tests/RetailCrm/Test/TestCase.php b/tests/RetailCrm/Test/TestCase.php index 69c16a0..fd18902 100644 --- a/tests/RetailCrm/Test/TestCase.php +++ b/tests/RetailCrm/Test/TestCase.php @@ -29,16 +29,23 @@ class TestCase extends \PHPUnit_Framework_TestCase * * @param string $url (default: null) * @param string $apiKey (default: null) + * @param string $version (default: null) * @param string $site (default: null) * * @return ApiClient */ - public static function getApiClient($url = null, $apiKey = null, $site = null) + public static function getApiClient($url = null, $apiKey = null, $version = null, $site = null) { + $configUrl = getenv('CRM_API_URL') ?: $_SERVER['CRM_API_URL']; + $configKey = getenv('CRM_API_KEY') ?: $_SERVER['CRM_API_KEY']; + $configVersion = getenv('CRM_API_VERSION') ?: $_SERVER['CRM_API_VERSION']; + $configSite = getenv('CRM_API_SITE') ?: $_SERVER['CRM_API_SITE']; + return new ApiClient( - $url ?: $_SERVER['CRM_URL'], - $apiKey ?: $_SERVER['CRM_API_KEY'], - $site ?: (isset($_SERVER['CRM_SITE']) ? $_SERVER['CRM_SITE'] : null) + $url ?: $configUrl, + $apiKey ?: $configKey, + $version ?: $configVersion, + $site ?: (isset($configSite) ? $configSite: null) ); } @@ -53,7 +60,7 @@ class TestCase extends \PHPUnit_Framework_TestCase public static function getClient($url = null, $defaultParameters = []) { return new Client( - $url ?: $_SERVER['CRM_URL'] . '/api/' . ApiClient::VERSION, + $url ?: $_SERVER['CRM_URL'] . '/api/' . getenv('CRM_API_VERSION') ?: $_SERVER['CRM_API_VERSION'], [ 'apiKey' => array_key_exists('apiKey', $defaultParameters) ? $defaultParameters['apiKey']