From a6e5afa1657f0c5c4baef4864c3b16164c0b19ee Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 6 Jun 2016 17:53:05 +0300 Subject: [PATCH] v4 initial commit, users, stores & telephony method updated --- composer.json | 2 +- lib/RetailCrm/ApiClient.php | 289 +++++++++++++++++++++++------------- 2 files changed, 190 insertions(+), 101 deletions(-) diff --git a/composer.json b/composer.json index 9bf2ea4..11898b4 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0.x-dev" } }, "config": { diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index de8ea4c..74fece3 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -31,7 +31,7 @@ use RetailCrm\Response\ApiResponse; class ApiClient { - const VERSION = 'v3'; + const VERSION = 'v4'; protected $client; @@ -53,7 +53,7 @@ class ApiClient */ public function __construct($url, $apiKey, $site = null) { - if ('/' !== substr($url, strlen($url) - 1, 1)) { + if ('/' !== $url[strlen($url) - 1]) { $url .= '/'; } @@ -63,6 +63,56 @@ class ApiClient $this->siteCode = $site; } + /** + * Returns users list + * + * @param array $filter + * @param null $page + * @param null $limit + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function usersList(array $filter = array(), $page = null, $limit = null) + { + $parameters = array(); + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/users', + Client::METHOD_GET, + $parameters + ); + } + + /** + * Returns user data + * + * @param integer $id user ID + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function usersGet($id) + { + return $this->client->makeRequest("/users/$id", Client::METHOD_GET); + } + /** * Returns filtered orders list * @@ -151,53 +201,6 @@ class ApiClient ); } - /** - * Returns a orders history - * - * @param \DateTime $startDate (default: null) - * @param \DateTime $endDate (default: null) - * @param int $limit (default: 100) - * @param int $offset (default: 0) - * @param bool $skipMyChanges (default: true) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersHistory( - \DateTime $startDate = null, - \DateTime $endDate = null, - $limit = 100, - $offset = 0, - $skipMyChanges = true - ) { - $parameters = array(); - - if ($startDate) { - $parameters['startDate'] = $startDate->format('Y-m-d H:i:s'); - } - if ($endDate) { - $parameters['endDate'] = $endDate->format('Y-m-d H:i:s'); - } - if ($limit) { - $parameters['limit'] = (int) $limit; - } - if ($offset) { - $parameters['offset'] = (int) $offset; - } - if ($skipMyChanges) { - $parameters['skipMyChanges'] = (bool) $skipMyChanges; - } - - return $this->client->makeRequest( - '/orders/history', - Client::METHOD_GET, - $parameters - ); - } - /** * Returns statuses of the orders * @@ -210,10 +213,8 @@ class ApiClient * * @return ApiResponse */ - public function ordersStatuses( - array $ids = array(), - array $externalIds = array() - ) { + public function ordersStatuses(array $ids = array(), array $externalIds = array()) + { $parameters = array(); if (count($ids)) { @@ -333,11 +334,8 @@ class ApiClient * * @return ApiResponse */ - public function customersList( - array $filter = array(), - $page = null, - $limit = null - ) { + public function customersList(array $filter = array(), $page = null, $limit = null) + { $parameters = array(); if (count($filter)) { @@ -513,11 +511,8 @@ class ApiClient * * @return ApiResponse */ - public function ordersPacksList( - array $filter = array(), - $page = null, - $limit = null - ) { + public function ordersPacksList(array $filter = array(), $page = null, $limit = null) + { $parameters = array(); if (count($filter)) { @@ -577,11 +572,8 @@ class ApiClient * * @return ApiResponse */ - public function ordersPacksHistory( - array $filter = array(), - $page = null, - $limit = null - ) { + public function ordersPacksHistory(array $filter = array(), $page = null, $limit = null) + { $parameters = array(); if (count($filter)) { @@ -687,11 +679,8 @@ class ApiClient * * @return ApiResponse */ - public function storeInventories( - array $filter = array(), - $page = null, - $limit = null - ) { + public function storeInventories(array $filter = array(), $page = null, $limit = null) + { $parameters = array(); if (count($filter)) { @@ -711,6 +700,56 @@ class ApiClient ); } + /** + * Get store settings + * + * @param string $code get settings code + * + * @return ApiResponse + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function storeSettingsGet($code) + { + if (empty($code)) { + throw new \InvalidArgumentException('Parameter `code` must be set'); + } + + return $this->client->makeRequest( + "/store/settings/$code", + Client::METHOD_GET + ); + } + + /** + * Edit store configuration + * + * @param array $configuration + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function storeSettingsEdit(array $configuration) + { + if (!count($configuration) || empty($configuration['code'])) { + throw new \InvalidArgumentException( + 'Parameter `configuration` must contains a data & configuration `code` must be set' + ); + } + + return $this->client->makeRequest( + sprintf('/store/settings/%s/edit', $configuration['code']), + Client::METHOD_POST, + $configuration + ); + } + /** * Upload store inventories * @@ -738,6 +777,40 @@ class ApiClient ); } + /** + * Get products + * + * @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 storeProducts(array $filter = array(), $page = null, $limit = null) + { + $parameters = array(); + + 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/products', + Client::METHOD_GET, + $parameters + ); + } + /** * Returns available county list * @@ -1209,7 +1282,29 @@ class ApiClient } /** - * Telephony settings + * Get telephony settings + * + * @param string $code + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function telephonySettingsGet($code) + { + if (empty($code)) { + throw new \InvalidArgumentException('Parameter `code` must be set'); + } + + return $this->client->makeRequest( + "/telephony/settings/$code", + Client::METHOD_GET + ); + } + /** + * Edit telephony settings * * @param string $code symbolic code * @param string $clientId client id @@ -1224,14 +1319,8 @@ class ApiClient * * @return ApiResponse */ - public function telephonySettings( - $code, - $clientId, - $active = false, - $makeCallUrl = false, - $name = false, - $image = false - ) { + public function telephonySettingsEdit($code, $clientId, $active = false, $makeCallUrl = false, $name = false, $image = false) + { if (!isset($code)) { throw new \InvalidArgumentException('Code must be set'); } @@ -1267,29 +1356,12 @@ class ApiClient } return $this->client->makeRequest( - "/telephony/setting/$code", + "/telephony/setting/$code/edit", Client::METHOD_POST, $parameters ); } - /** - * Update CRM basic statistic - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function statisticUpdate() - { - return $this->client->makeRequest( - '/statistic/update', - Client::METHOD_GET - ); - } - /** * Call event * @@ -1386,6 +1458,23 @@ class ApiClient ); } + /** + * Update CRM basic statistic + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function statisticUpdate() + { + return $this->client->makeRequest( + '/statistic/update', + Client::METHOD_GET + ); + } + /** * Return current site *