From 921dbda7563900aefc740f9f909fe2cedaf7e33b Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 02:44:52 +0300 Subject: [PATCH 01/10] New version of PHP client for API v3. Not all methods implements --- .gitignore | 3 + README.md | 50 +- composer.json | 19 +- lib/IntaroCrm/Exception/ApiException.php | 6 - lib/IntaroCrm/Exception/CurlException.php | 6 - lib/IntaroCrm/RestApi.php | 581 ------------------ lib/RetailCrm/ApiClient.php | 101 +++ lib/RetailCrm/Exception/CurlException.php | 7 + .../Exception/InvalidJsonException.php | 7 + lib/RetailCrm/Http/Client.php | 81 +++ lib/RetailCrm/Response/ApiResponse.php | 112 ++++ phpunit.xml.dist | 21 + tests/RetailCrm/Test/TestCase.php | 20 + tests/RetailCrm/Tests/ApiClientTest.php | 127 ++++ tests/RetailCrm/Tests/Http/ClientTest.php | 61 ++ .../Tests/Response/ApiResponseTest.php | 233 +++++++ tests/bootstrap.php | 4 + 17 files changed, 791 insertions(+), 648 deletions(-) delete mode 100644 lib/IntaroCrm/Exception/ApiException.php delete mode 100644 lib/IntaroCrm/Exception/CurlException.php delete mode 100644 lib/IntaroCrm/RestApi.php create mode 100644 lib/RetailCrm/ApiClient.php create mode 100644 lib/RetailCrm/Exception/CurlException.php create mode 100644 lib/RetailCrm/Exception/InvalidJsonException.php create mode 100644 lib/RetailCrm/Http/Client.php create mode 100644 lib/RetailCrm/Response/ApiResponse.php create mode 100644 phpunit.xml.dist create mode 100644 tests/RetailCrm/Test/TestCase.php create mode 100644 tests/RetailCrm/Tests/ApiClientTest.php create mode 100644 tests/RetailCrm/Tests/Http/ClientTest.php create mode 100644 tests/RetailCrm/Tests/Response/ApiResponseTest.php create mode 100644 tests/bootstrap.php diff --git a/.gitignore b/.gitignore index e43b0f9..7ce5942 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .DS_Store +phpunit.xml +vendor/ +composer.lock \ No newline at end of file diff --git a/README.md b/README.md index 2af9afe..16ad6d8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -IntaroCRM REST API client +PHP client for retailCRM API ================= -PHP Client for [IntaroCRM REST API](http://docs.intarocrm.ru/rest-api/). +PHP client for [retailCRM API](http://www.retailcrm.ru/docs/Разработчики/Разработчики#api). Requirements ------------ @@ -14,47 +14,7 @@ Installation 1) Install [composer](https://getcomposer.org/download/) into the project directory. -2) Add IntaroCRM REST API client in your composer.json: -```js -{ - "require": { - "intarocrm/rest-api-client": "1.3.*" - } -} -``` -3) Use command `php composer.phar update intarocrm/rest-api-client` to install new vendor into `vendor/` folder. - - - -Usage ------------- - -### Create API clent class - -``` php - -$crmApiClient = new \IntaroCrm\RestApi( - 'https://demo.intarocrm.ru', - 'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH' -); -``` -Constructor arguments are: - -1. Your IntaroCRM acount URL-address -2. Your site API Token - -### Example: get order types list - -``` php - -try { - $orderTypes = $crmApiClient->orderTypesList(); -} -catch (\IntaroCrm\Exception\CurlException $e) { - //$logger->addError('orderTypesList: connection error'); -} -catch (\IntaroCrm\Exception\ApiException $e) { - //$logger->addError('orderTypesList: ' . $e->getMessage()); -} - +2) Run: +```bash +composer require retailcrm/api-client-php 3.0 ``` diff --git a/composer.json b/composer.json index 4a0745b..aad1734 100644 --- a/composer.json +++ b/composer.json @@ -1,29 +1,28 @@ { - "name": "intarocrm/rest-api-client", - "description": "PHP Client for IntaroCRM REST API", + "name": "retailcrm/api-client-php", + "description": "PHP client for retailCRM API", "type": "library", - "keywords": ["api", "Intaro CRM", "rest"], - "homepage": "http://www.intarocrm.ru/", + "keywords": ["API", "retailCRM", "REST"], + "homepage": "http://www.retailcrm.ru/", "authors": [ { - "name": "Kruglov Kirill", - "email": "kruglov@intaro.ru", - "role": "Developer" + "name": "retailCRM", + "email": "support@retailcrm.ru" } ], "require": { - "php": ">=5.2.0", + "php": ">=5.3.0", "ext-curl": "*" }, "support": { "email": "support@intarocrm.ru" }, "autoload": { - "psr-0": { "IntaroCrm\\": "lib/" } + "psr-0": { "RetailCrm\\": "lib/" } }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "3.0.x-dev" } } } \ No newline at end of file diff --git a/lib/IntaroCrm/Exception/ApiException.php b/lib/IntaroCrm/Exception/ApiException.php deleted file mode 100644 index 75e4d8d..0000000 --- a/lib/IntaroCrm/Exception/ApiException.php +++ /dev/null @@ -1,6 +0,0 @@ -apiUrl = $crmUrl.'/api/v'.$this->apiVersion.'/'; - $this->apiKey = $apiKey; - $this->parameters = array('apiKey' => $this->apiKey); - } - - /* Методы для работы с заказами */ - /** - * Получение заказа по id - * - * @param string $id - идентификатор заказа - * @param string $by - поиск заказа по id или externalId - * @return array - информация о заказе - */ - public function orderGet($id, $by = 'externalId') - { - $url = $this->apiUrl.'orders/'.$id; - - if ($by != 'externalId') - $this->parameters['by'] = $by; - $result = $this->curlRequest($url); - return $result; - } - - /** - * Создание заказа - * - * @param array $order- информация о заказе - * @return array - */ - public function orderCreate($order) - { - $dataJson = json_encode($order); - $this->parameters['order'] = $dataJson; - - $url = $this->apiUrl.'orders/create'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - /** - * Изменение заказа - * - * @param array $order- информация о заказе - * @return array - */ - public function orderEdit($order) - { - $dataJson = json_encode($order); - $this->parameters['order'] = $dataJson; - - $url = $this->apiUrl.'orders/'.$order['externalId'].'/edit'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - /** - * Пакетная загрузка заказов - * - * @param array $orders - массив заказов - * @return array - */ - public function orderUpload($orders) - { - $dataJson = json_encode($orders); - $this->parameters['orders'] = $dataJson; - - $url = $this->apiUrl.'orders/upload'; - $result = $this->curlRequest($url, 'POST'); - if (is_null($result) && isset($result['uploadedOrders'])) - return $result['uploadedOrders']; - return $result; - } - - /** - * Обновление externalId у заказов с переданными id - * - * @param array $orders- массив, содержащий id и externalId заказа - * @return array - */ - public function orderFixExternalIds($order) - { - $dataJson = json_encode($order); - $this->parameters['orders'] = $dataJson; - - $url = $this->apiUrl.'orders/fix-external-ids'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - /** - * Получение последних измененных заказов - * - * @param \DateTime|string|int $startDate - начальная дата и время выборки (Y-m-d H:i:s) - * @param \DateTime|string|int $endDate - конечная дата и время выборки (Y-m-d H:i:s) - * @param int $limit - ограничение на размер выборки - * @param int $offset - сдвиг - * @return array - массив заказов - */ - public function orderHistory($startDate = null, $endDate = null, $limit = 100, $offset = 0) - { - $url = $this->apiUrl.'orders/history'; - $this->parameters['startDate'] = $this->ensureDateTime($startDate); - $this->parameters['endDate'] = $this->ensureDateTime($endDate); - $this->parameters['limit'] = $limit; - $this->parameters['offset'] = $offset; - - $result = $this->curlRequest($url); - return $result; - } - - /* Методы для работы с клиентами */ - /** - * Получение клиента по id - * - * @param string $id - идентификатор - * @param string $by - поиск заказа по id или externalId - * @return array - информация о клиенте - */ - public function customerGet($id, $by = 'externalId') - { - $url = $this->apiUrl.'customers/'.$id; - if ($by != 'externalId') - $this->parameters['by'] = $by; - $result = $this->curlRequest($url); - return $result; - } - - /** - * Получение списка клиентов в соответсвии с запросом - * - * @param string $phone - телефон - * @param string $email - почтовый адрес - * @param string $fio - фио пользователя - * @param int $limit - ограничение на размер выборки - * @param int $offset - сдвиг - * @return array - массив клиентов - */ - public function customers($phone = null, $email = null, $fio = null, $limit = 200, $offset = 0) - { - $url = $this->apiUrl.'customers'; - if($phone) $this->parameters['phone'] = $phone; - if($email) $this->parameters['email'] = $email; - if($fio) $this->parameters['fio'] = $fio; - $this->parameters['limit'] = $limit; - $this->parameters['offset'] = $offset; - - $result = $this->curlRequest($url); - return $result; - } - - /** - * Создание клиента - * - * @param array $customer - информация о клиенте - * @return array - */ - public function customerCreate($customer) - { - $dataJson = json_encode($customer); - $this->parameters['customer'] = $dataJson; - - $url = $this->apiUrl.'customers/create'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - /** - * Редактирование клиента - * - * @param array $customer - информация о клиенте - * @return array - */ - public function customerEdit($customer) - { - $dataJson = json_encode($customer); - $this->parameters['customer'] = $dataJson; - - $url = $this->apiUrl.'customers/'.$customer['externalId'].'/edit'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - /** - * Пакетная загрузка клиентов - * - * @param array $customers - массив клиентов - * @return array - */ - public function customerUpload($customers) - { - $dataJson = json_encode($customers); - $this->parameters['customers'] = $dataJson; - - $url = $this->apiUrl.'customers/upload'; - $result = $this->curlRequest($url, 'POST'); - if (is_null($result) && isset($result['uploaded'])) - return $result['uploaded']; - return $result; - } - - /** - * Обновление externalId у клиентов с переданными id - * - * @param array $customers- массив, содержащий id и externalId заказа - * @return array - */ - public function customerFixExternalIds($customers) - { - $dataJson = json_encode($customers); - $this->parameters['customers'] = $dataJson; - - $url = $this->apiUrl.'customers/fix-external-ids'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - /** - * Получение списка заказов клиента - * - * @param string $id - идентификатор клиента - * @param string $by - поиск заказа по id или externalId - * @param \DateTime|string|int $startDate - начальная дата выборки (Y-m-d H:i:s) - * @param \DateTime|string|int $endDate - конечная дата выборки (Y-m-d H:i:s) - * @param int $limit - ограничение на размер выборки - * @param int $offset - сдвиг - * @return array - массив заказов - */ - public function customerOrdersList($id, $startDate = null, $endDate = null, - $limit = 100, $offset = 0, $by = 'externalId') - { - $url = $this->apiUrl.'customers/'.$id.'/orders'; - if ($by != 'externalId') - $this->parameters['by'] = $by; - $this->parameters['startDate'] = $this->ensureDateTime($startDate); - $this->parameters['endDate'] = $this->ensureDateTime($endDate); - $this->parameters['limit'] = $limit; - $this->parameters['offset'] = $offset; - - $result = $this->curlRequest($url); - return $result; - } - - /* Методы для работы со справочниками */ - /** - * Получение списка типов доставки - * - * @return array - массив типов доставки - */ - public function deliveryTypesList() - { - $url = $this->apiUrl.'reference/delivery-types'; - $result = $this->curlRequest($url); - return $result; - } - - /** - * Редактирование типа доставки - * - * @param array $deliveryType - информация о типе доставки - * @return array - */ - public function deliveryTypeEdit($deliveryType) - { - $dataJson = json_encode($deliveryType); - $this->parameters['deliveryType'] = $dataJson; - - $url = $this->apiUrl.'reference/delivery-types/'.$deliveryType['code'].'/edit'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - /** - * Получение списка служб доставки - * - * @return array - массив типов доставки - */ - public function deliveryServicesList() - { - $url = $this->apiUrl.'reference/delivery-services'; - $result = $this->curlRequest($url); - return $result; - } - - /** - * Редактирование службы доставки - * - * @param array $deliveryService - информация о типе доставки - * @return array - */ - public function deliveryServiceEdit($deliveryService) - { - $dataJson = json_encode($deliveryService); - $this->parameters['deliveryService'] = $dataJson; - - $url = $this->apiUrl.'reference/delivery-services/'.$deliveryService['code'].'/edit'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - - /** - * Получение списка типов оплаты - * - * @return array - массив типов оплаты - */ - public function paymentTypesList() - { - $url = $this->apiUrl.'reference/payment-types'; - $result = $this->curlRequest($url); - return $result; - } - - /** - * Редактирование типа оплаты - * - * @param array $paymentType - информация о типе оплаты - * @return array - */ - public function paymentTypesEdit($paymentType) - { - $dataJson = json_encode($paymentType); - $this->parameters['paymentType'] = $dataJson; - - $url = $this->apiUrl.'reference/payment-types/'.$paymentType['code'].'/edit'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - - /** - * Получение списка статусов оплаты - * - * @return array - массив статусов оплаты - */ - public function paymentStatusesList() - { - $url = $this->apiUrl.'reference/payment-statuses'; - $result = $this->curlRequest($url); - return $result; - } - - /** - * Редактирование статуса оплаты - * - * @param array $paymentStatus - информация о статусе оплаты - * @return array - */ - public function paymentStatusesEdit($paymentStatus) - { - $dataJson = json_encode($paymentStatus); - $this->parameters['paymentStatus'] = $dataJson; - - $url = $this->apiUrl.'reference/payment-statuses/'.$paymentStatus['code'].'/edit'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - - /** - * Получение списка типов заказа - * - * @return array - массив типов заказа - */ - public function orderTypesList() - { - $url = $this->apiUrl.'reference/order-types'; - $result = $this->curlRequest($url); - return $result; - } - - /** - * Редактирование типа заказа - * - * @param array $orderType - информация о типе заказа - * @return array - */ - public function orderTypesEdit($orderType) - { - $dataJson = json_encode($orderType); - $this->parameters['orderType'] = $dataJson; - - $url = $this->apiUrl.'reference/order-types/'.$orderType['code'].'/edit'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - - /** - * Получение списка способов оформления заказа - * - * @return array - массив способов оформления заказа - */ - public function orderMethodsList() - { - $url = $this->apiUrl.'reference/order-methods'; - $result = $this->curlRequest($url); - return $result; - } - - /** - * Редактирование способа оформления заказа - * - * @param array $orderMethod - информация о способе оформления заказа - * @return array - */ - public function orderMethodsEdit($orderMethod) - { - $dataJson = json_encode($orderMethod); - $this->parameters['orderMethod'] = $dataJson; - - $url = $this->apiUrl.'reference/order-methods/'.$orderMethod['code'].'/edit'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - /** - * Получение списка статусов заказа - * - * @return array - массив статусов заказа - */ - public function orderStatusesList() - { - $url = $this->apiUrl.'reference/statuses'; - $result = $this->curlRequest($url); - return $result; - } - - /** - * Редактирование статуса заказа - * - * @param array $status - информация о статусе заказа - * @return array - */ - public function orderStatusEdit($status) - { - $dataJson = json_encode($status); - $this->parameters['status'] = $dataJson; - - $url = $this->apiUrl.'reference/statuses/'.$status['code'].'/edit'; - $result = $this->curlRequest($url, 'POST'); - return $result; - } - - - /** - * Получение списка групп статусов заказа - * - * @return array - массив групп статусов заказа - */ - public function orderStatusGroupsList() - { - $url = $this->apiUrl.'reference/status-groups'; - $result = $this->curlRequest($url); - return $result; - } - - /** - * Обновление статистики - * - * @return array - статус вып обновления - */ - public function statisticUpdate() - { - $url = $this->apiUrl.'statistic/update'; - $result = $this->curlRequest($url); - return $result; - } - - /** - * @return \DateTime - */ - public function getGeneratedAt() - { - return $this->generatedAt; - } - - protected function ensureDateTime($value) - { - if ($value instanceof \DateTime) { - return $value->format('Y-m-d H:i:s'); - } elseif (is_int($value)) { - return date('Y-m-d H:i:s', $value); - } - - return $value; - } - - protected function getErrorMessage($response) - { - $str = ''; - if (isset($response['message'])) - $str = $response['message']; - elseif (isset($response[0]['message'])) - $str = $response[0]['message']; - elseif (isset($response['error']) && isset($response['error']['message'])) - $str = $response['error']['message']; - elseif (isset($response['errorMsg'])) - $str = $response['errorMsg']; - - if (isset($response['errors']) && sizeof($response['errors'])) { - foreach ($response['errors'] as $error) - $str .= '. ' . $error; - } - - if (!strlen($str)) - return 'Application Error'; - - return $str; - } - - protected function curlRequest($url, $method = 'GET', $format = 'json') - { - if ($method == 'GET' && !is_null($this->parameters)) - $url .= '?'.http_build_query($this->parameters); - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_FAILONERROR, FALSE); - //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable - curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 30s - //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - - - if ($method == 'POST') - { - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $this->parameters); - } - - $response = curl_exec($ch); - $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - unset($this->parameters); - /* Сброс массива с параметрами */ - $this->parameters = array('apiKey' => $this->apiKey); - - $errno = curl_errno($ch); - $error = curl_error($ch); - curl_close($ch); - - if ($errno) - throw new Exception\CurlException($error, $errno); - - $result = json_decode($response, true); - - if ($statusCode >= 400 || isset($result['success']) && $result['success'] === false) { - throw new Exception\ApiException($this->getErrorMessage($result), $statusCode); - } - - if (isset($result['generatedAt'])) { - $this->generatedAt = new \DateTime($result['generatedAt']); - unset($result['generatedAt']); - } - - unset($result['success']); - - if (count($result) == 0) - return true; - - return reset($result); - } -} diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php new file mode 100644 index 0000000..f79b6e3 --- /dev/null +++ b/lib/RetailCrm/ApiClient.php @@ -0,0 +1,101 @@ +client = new Client($url, array('apiKey' => $apiKey)); + } + + /** + * Create a order + * + * @param array $order + * @return ApiResponse + */ + public function ordersCreate(array $order) + { + return $this->client->makeRequest("/orders/create", Client::METHOD_POST, array( + 'order' => json_encode($order) + )); + } + + /** + * Edit a order + * + * @param array $order + * @return ApiResponse + */ + public function ordersEdit(array $order, $by = 'externalId') + { + $this->checkIdParameter($by); + + if (!isset($order[$by])) { + throw new \InvalidArgumentException(sprintf('Order array must contain the "%s" parameter.', $by)); + } + + return $this->client->makeRequest("/orders/" . $order[$by] . "/edit", Client::METHOD_POST, array( + 'order' => json_encode($order), + 'by' => $by, + )); + } + + /** + * Get order by id or externalId + * + * @param string $id + * @param string $by (default: 'externalId') + * @return ApiResponse + */ + public function ordersGet($id, $by = 'externalId') + { + $this->checkIdParameter($by); + + return $this->client->makeRequest("/orders/$id", Client::METHOD_GET, array('by' => $by)); + } + + /** + * Check ID parameter + * + * @param string $by + * @return bool + */ + protected function checkIdParameter($by) + { + $allowedForBy = array('externalId', 'id'); + if (!in_array($by, $allowedForBy)) { + throw new \InvalidArgumentException(sprintf( + 'Value "%s" for parameter "by" is not valid. Allowed values are %s.', + $by, + implode(', ', $allowedForBy) + )); + } + + return true; + } +} \ No newline at end of file diff --git a/lib/RetailCrm/Exception/CurlException.php b/lib/RetailCrm/Exception/CurlException.php new file mode 100644 index 0000000..098fc30 --- /dev/null +++ b/lib/RetailCrm/Exception/CurlException.php @@ -0,0 +1,7 @@ +url = $url; + $this->defaultParameters = $defaultParameters; + } + + /** + * Make HTTP request + * + * @param string $path + * @param string $method (default: 'GET') + * @param array $parameters (default: array()) + * @return ApiResponse + */ + public function makeRequest($path, $method, array $parameters = array(), $timeout = 30) + { + $allowedMethods = array(self::METHOD_GET, self::METHOD_POST); + if (!in_array($method, $allowedMethods)) { + throw new \InvalidArgumentException(sprintf( + 'Method "%s" is not valid. Allowed methods are %s', + $method, + implode(', ', $allowedMethods) + )); + } + + $parameters = array_merge($this->defaultParameters, $parameters); + + $path = $this->url . $path; + if (self::METHOD_GET === $method && sizeof($parameters)) { + $path .= '?' . http_build_query($parameters); + } + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $path); + curl_setopt($ch, CURLOPT_FAILONERROR, FALSE); + // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable + curl_setopt($ch, CURLOPT_TIMEOUT, (int) $timeout); // times out after 30s + // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + + if (self::METHOD_POST === $method) { + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters); + } + + $responseBody = curl_exec($ch); + $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + $errno = curl_errno($ch); + $error = curl_error($ch); + curl_close($ch); + + if ($errno) { + throw new CurlException($error, $errno); + } + + return new ApiResponse($statusCode, $responseBody); + } + } diff --git a/lib/RetailCrm/Response/ApiResponse.php b/lib/RetailCrm/Response/ApiResponse.php new file mode 100644 index 0000000..c35c6db --- /dev/null +++ b/lib/RetailCrm/Response/ApiResponse.php @@ -0,0 +1,112 @@ +statusCode = (int) $statusCode; + + if (!empty($responseBody)) { + $response = json_decode($responseBody, true); + + if (!$response && JSON_ERROR_NONE !== ($error = json_last_error())) { + throw new InvalidJsonException( + "Invalid JSON in the API response body. Error code #$error", + $error + ); + } + + $this->response = $response; + } + } + + /** + * Return HTTP response status code + * + * @return int + */ + public function getStatusCode() + { + return $this->statusCode; + } + + /** + * HTTP request was successful + * + * @return bool + */ + public function isSuccessful() + { + return $this->statusCode < 400; + } + + /** + * Allow to access for the property throw class method + * + * @param string $name + * @return mixed + */ + public function __call($name, $arguments) + { + // convert getSomeProperty to someProperty + $propertyName = strtolower(substr($name, 3, 1)) . substr($name, 4); + + if (!isset($this->response[$propertyName])) { + throw new \InvalidArgumentException("Method \"$name\" not found"); + } + + return $this->response[$propertyName]; + } + + /** + * Allow to access for the property throw object property + * + * @param string $name + * @return mixed + */ + public function __get($name) + { + if (!isset($this->response[$name])) { + throw new \InvalidArgumentException("Property \"$name\" not found"); + } + + return $this->response[$name]; + } + + public function offsetSet($offset, $value) + { + throw new \BadMethodCallException('This activity not allowed'); + } + + public function offsetUnset($offset) + { + throw new \BadMethodCallException('This call not allowed'); + } + + public function offsetExists($offset) + { + return isset($this->response[$offset]); + } + + public function offsetGet($offset) + { + if (!isset($this->response[$offset])) { + throw new \InvalidArgumentException("Property \"$offset\" not found"); + } + + return $this->response[$offset]; + } +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..ac37b0e --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,21 @@ + + + + + + + + + + + + tests/RetailCrm/Tests + + + + + + ./src/RetailCrm + + + diff --git a/tests/RetailCrm/Test/TestCase.php b/tests/RetailCrm/Test/TestCase.php new file mode 100644 index 0000000..c004a66 --- /dev/null +++ b/tests/RetailCrm/Test/TestCase.php @@ -0,0 +1,20 @@ +assertInstanceOf('RetailCrm\ApiClient', $client); + } + + /** + * @group integration + */ + public function testOrdersCreate() + { + $client = static::getApiClient(); + + $externalId = time(); + + $response = $client->ordersCreate(array( + 'firstName' => self::FIRST_NAME, + 'externalId' => $externalId, + )); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(201, $response->getStatusCode()); + $this->assertTrue(is_int($response->getId())); + + return array( + 'id' => $response->getId(), + 'externalId' => $externalId, + ); + } + + /** + * @group integration + * @depends testOrdersCreate + */ + public function testOrdersGet(array $ids) + { + $client = static::getApiClient(); + + $response = $client->ordersGet(678678678); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(404, $response->getStatusCode()); + $this->assertFalse($response->success); + + $response = $client->ordersGet($ids['id'], 'id'); + $orderById = $response->order; + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + $this->assertEquals(self::FIRST_NAME, $response->order['firstName']); + + $response = $client->ordersGet($ids['externalId'], 'externalId'); + $this->assertEquals($orderById['id'], $response->order['id']); + + return $ids; + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testOrdersGetException() + { + $client = static::getApiClient(); + + $response = $client->ordersGet(678678678, 'asdf'); + } + + /** + * @group integration + * @depends testOrdersGet + */ + public function testOrdersEdit(array $ids) + { + $client = static::getApiClient(); + + $response = $client->ordersEdit( + array( + 'id' => 22342134, + 'lastName' => '12345', + ), + 'id' + ); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(404, $response->getStatusCode()); + + $response = $client->ordersEdit(array( + 'externalId' => $ids['externalId'], + 'lastName' => '12345', + )); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + + $response = $client->ordersEdit(array( + 'externalId' => time(), + 'lastName' => '12345', + )); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(201, $response->getStatusCode()); + $this->assertTrue($response->success); + } + + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testOrdersEditException() + { + $client = static::getApiClient(); + + $response = $client->ordersEdit(array('id' => 678678678), 'asdf'); + } +} diff --git a/tests/RetailCrm/Tests/Http/ClientTest.php b/tests/RetailCrm/Tests/Http/ClientTest.php new file mode 100644 index 0000000..59b8260 --- /dev/null +++ b/tests/RetailCrm/Tests/Http/ClientTest.php @@ -0,0 +1,61 @@ +assertInstanceOf('RetailCrm\Http\Client', $client); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testHttpRequiring() + { + $client = new Client('http://a.intarocrm.ru', array('apiKey' => '123')); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testMakeRequestWrongMethod() + { + $client = new Client('https://asdf.df', array()); + $client->makeRequest('/a', 'adsf'); + } + + /** + * @group integration + * @expectedException RetailCrm\Exception\CurlException + */ + public function testMakeRequestWrongUrl() + { + $client = new Client('https://asdf.df', array()); + $client->makeRequest('/a', Client::METHOD_GET, array(), 1); + } + + /** + * @group integration + */ + public function testMakeRequestSuccess() + { + $client = new Client('https://demo.intarocrm.ru/api/' . ApiClient::VERSION, array()); + $response = $client->makeRequest('/a', Client::METHOD_GET); + + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(403, $response->getStatusCode()); + } +} diff --git a/tests/RetailCrm/Tests/Response/ApiResponseTest.php b/tests/RetailCrm/Tests/Response/ApiResponseTest.php new file mode 100644 index 0000000..fa70176 --- /dev/null +++ b/tests/RetailCrm/Tests/Response/ApiResponseTest.php @@ -0,0 +1,233 @@ +assertInstanceOf( + 'RetailCrm\Response\ApiResponse', + $response, + 'Response object created' + ); + + $response = new ApiResponse(201, '{ "success": true }'); + $this->assertInstanceOf( + 'RetailCrm\Response\ApiResponse', + $response, + 'Response object created' + ); + } + + /** + * @group unit + * @expectedException RetailCrm\Exception\InvalidJsonException + */ + public function testJsonInvalid() + { + $response = new ApiResponse(400, '{ "asdf": }'); + } + + /** + * @group unit + */ + public function testStatusCodeGetting() + { + $response = new ApiResponse(200); + $this->assertEquals( + 200, + $response->getStatusCode(), + 'Response object returns the right status code' + ); + + $response = new ApiResponse(460, '{ "success": false }'); + $this->assertEquals( + 460, + $response->getStatusCode(), + 'Response object returns the right status code' + ); + } + + /** + * @group unit + */ + public function testIsSuccessful() + { + $response = new ApiResponse(200); + $this->assertTrue( + $response->isSuccessful(), + 'Request was successful' + ); + + $response = new ApiResponse(460, '{ "success": false }'); + $this->assertFalse( + $response->isSuccessful(), + 'Request was failed' + ); + } + + /** + * @group unit + */ + public function testMagicCall() + { + $response = new ApiResponse(201, '{ "success": true }'); + $this->assertEquals( + true, + $response->getSuccess(), + 'Response object returns property value throw magic method' + ); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testMagicCallException1() + { + $response = new ApiResponse(200); + $response->getSome(); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testMagicCallException2() + { + $response = new ApiResponse(201, '{ "success": true }'); + $response->getSomeSuccess(); + } + + /** + * @group unit + */ + public function testMagicGet() + { + $response = new ApiResponse(201, '{ "success": true }'); + $this->assertEquals( + true, + $response->success, + 'Response object returns property value throw magic get' + ); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testMagicGetException1() + { + $response = new ApiResponse(200); + $response->some; + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testMagicGetException2() + { + $response = new ApiResponse(201, '{ "success": true }'); + $response->someSuccess; + } + + /** + * @group unit + */ + public function testArrayGet() + { + $response = new ApiResponse(201, '{ "success": true }'); + $this->assertEquals( + true, + $response['success'], + 'Response object returns property value throw magic array get' + ); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testArrayGetException1() + { + $response = new ApiResponse(200); + $response['some']; + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testArrayGetException2() + { + $response = new ApiResponse(201, '{ "success": true }'); + $response['someSuccess']; + } + + /** + * @group unit + */ + public function testArrayIsset() + { + $response = new ApiResponse(201, '{ "success": true }'); + + $this->assertTrue( + isset($response['success']), + 'Response object returns property existing' + ); + + $this->assertFalse( + isset($response['suess']), + 'Response object returns property existing' + ); + } + + /** + * @group unit + * @expectedException \BadMethodCallException + */ + public function testArraySetException1() + { + $response = new ApiResponse(201, '{ "success": true }'); + $response['success'] = 'a'; + } + + /** + * @group unit + * @expectedException \BadMethodCallException + */ + public function testArraySetException2() + { + $response = new ApiResponse(201, '{ "success": true }'); + $response['sssssssuccess'] = 'a'; + } + + /** + * @group unit + * @expectedException \BadMethodCallException + */ + public function testArrayUnsetException1() + { + $response = new ApiResponse(201, '{ "success": true }'); + unset($response['success']); + } + + /** + * @group unit + * @expectedException \BadMethodCallException + */ + public function testArrayUnsetException2() + { + $response = new ApiResponse(201, '{ "success": true }'); + unset($response['sssssssuccess']); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..f1cd65b --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,4 @@ +add('RetailCrm\\Test', __DIR__); From 5a9c0bdb7b5959c514697c39a94c5b47a9a1c3b2 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 02:55:09 +0300 Subject: [PATCH 02/10] Added example of usage --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 16ad6d8..a9f5326 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,29 @@ Installation ```bash composer require retailcrm/api-client-php 3.0 ``` + +Usage +----- + +Example of the usage: +```php + +$client = new \RetailCrm\ApiClient( + 'https://demo.intarocrm.ru', + 'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH' +); + +try { + $response = $client->ordersGet('M-2342'); +} catch (\RetailCrm\Exception\CurlException $e) { + echo "CRM connection error: " . $e->getMessage(); +} + +if ($response->isSuccessful()) { + echo $response->order['totalSumm']; + // or $response['order']['totalSumm']; + // or + // $order = $response->getOrder(); + // $order['totalSumm']; +} +``` \ No newline at end of file From 8b59f079ef14f96bf9f9f1e728921dc25d598477 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 03:18:39 +0300 Subject: [PATCH 03/10] Added ordersHistory. Fix test --- README.md | 33 ++++++++++++++++++++++- lib/RetailCrm/ApiClient.php | 29 ++++++++++++++++++++ tests/RetailCrm/Tests/ApiClientTest.php | 15 ++++++++++- tests/RetailCrm/Tests/Http/ClientTest.php | 2 +- 4 files changed, 76 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a9f5326..9d9dfef 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ composer require retailcrm/api-client-php 3.0 Usage ----- -Example of the usage: +Example of the receipt of order: ```php $client = new \RetailCrm\ApiClient( @@ -43,4 +43,35 @@ if ($response->isSuccessful()) { // $order = $response->getOrder(); // $order['totalSumm']; } +``` + +Example of the order creating: +```php + +$client = new \RetailCrm\ApiClient( + 'https://demo.intarocrm.ru', + 'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH' +); + +try { + $response = $client->ordersCreate(array( + 'externalId' => 'some-shop-order-id', + 'firstName' => 'Vasily', + 'lastName' => 'Pupkin', + 'items' => array( + //... + ), + delivery => array( + 'code' => 'russian-post', + ) + )); +} catch (\RetailCrm\Exception\CurlException $e) { + echo "CRM connection error: " . $e->getMessage(); +} + +if ($response->isSuccessful() && 201 === $response->getStatusCode()) { + echo 'Order created successfully! Order ID in CRM - ' . $response->id; + // or $response['id']; + // or $response->getId(); +} ``` \ No newline at end of file diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index f79b6e3..a787f1f 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -79,6 +79,35 @@ class ApiClient return $this->client->makeRequest("/orders/$id", Client::METHOD_GET, array('by' => $by)); } + /** + * Returns a orders history + * + * @param \DateTime $startDate (default: null) + * @param \DateTime $endDate (default: null) + * @param int $limit (default: 100) + * @param int $offset (default: 0) + * @return ApiResponse + */ + public function ordersHistory(\DateTime $startDate = null, \DateTime $endDate = null, $limit = 100, $offset = 0) + { + $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; + } + + return $this->client->makeRequest('/orders/history', Client::METHOD_GET, $parameters); + } + /** * Check ID parameter * diff --git a/tests/RetailCrm/Tests/ApiClientTest.php b/tests/RetailCrm/Tests/ApiClientTest.php index 108a97e..d4b80a5 100644 --- a/tests/RetailCrm/Tests/ApiClientTest.php +++ b/tests/RetailCrm/Tests/ApiClientTest.php @@ -113,7 +113,6 @@ class ApiClientTest extends TestCase $this->assertTrue($response->success); } - /** * @group unit * @expectedException \InvalidArgumentException @@ -124,4 +123,18 @@ class ApiClientTest extends TestCase $response = $client->ordersEdit(array('id' => 678678678), 'asdf'); } + + /** + * @group integration + */ + public function testOrdersHistory() + { + $client = static::getApiClient(); + + $response = $client->ordersHistory(); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + $this->assertTrue(isset($response['orders'])); + } } diff --git a/tests/RetailCrm/Tests/Http/ClientTest.php b/tests/RetailCrm/Tests/Http/ClientTest.php index 59b8260..6e46653 100644 --- a/tests/RetailCrm/Tests/Http/ClientTest.php +++ b/tests/RetailCrm/Tests/Http/ClientTest.php @@ -53,7 +53,7 @@ class ClientTest extends TestCase public function testMakeRequestSuccess() { $client = new Client('https://demo.intarocrm.ru/api/' . ApiClient::VERSION, array()); - $response = $client->makeRequest('/a', Client::METHOD_GET); + $response = $client->makeRequest('/orders', Client::METHOD_GET); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(403, $response->getStatusCode()); From be29e86d73e13e430122537a33cd6422909e5b45 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 03:20:32 +0300 Subject: [PATCH 04/10] fix in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d9dfef..6d9c243 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Requirements Installation ------------ -1) Install [composer](https://getcomposer.org/download/) into the project directory. +1) Install [composer](https://getcomposer.org/download/) 2) Run: ```bash @@ -61,7 +61,7 @@ try { 'items' => array( //... ), - delivery => array( + 'delivery' => array( 'code' => 'russian-post', ) )); From a1aa7da86d805165e0ae289b5c12d75f74c407d6 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 03:50:15 +0300 Subject: [PATCH 05/10] Add ordersList method --- lib/RetailCrm/ApiClient.php | 25 +++++++++++++++++++++++++ tests/RetailCrm/Tests/ApiClientTest.php | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index a787f1f..beab987 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -108,6 +108,31 @@ class ApiClient return $this->client->makeRequest('/orders/history', Client::METHOD_GET, $parameters); } + /** + * Returns filtered orders list + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * @return void + */ + public function ordersList(array $filter = array(), $page = null, $limit = null) + { + $parameters = array(); + + if (sizeof($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest('/orders', Client::METHOD_GET, $parameters); + } + /** * Check ID parameter * diff --git a/tests/RetailCrm/Tests/ApiClientTest.php b/tests/RetailCrm/Tests/ApiClientTest.php index d4b80a5..cf5bc03 100644 --- a/tests/RetailCrm/Tests/ApiClientTest.php +++ b/tests/RetailCrm/Tests/ApiClientTest.php @@ -137,4 +137,25 @@ class ApiClientTest extends TestCase $this->assertTrue($response->success); $this->assertTrue(isset($response['orders'])); } + + /** + * @group integration + */ + public function testOrdersList() + { + $client = static::getApiClient(); + + $response = $client->ordersList(); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue($response->isSuccessful()); + $this->assertTrue(isset($response['orders'])); + + $response = $client->ordersList(array(), 1, 300); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertFalse($response->isSuccessful()); + + $response = $client->ordersList(array('paymentStatus' => 'paid'), 1); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue($response->isSuccessful()); + } } From 5b1e5651e7868c44006fd5d6240af53def4d90f6 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 11:31:47 +0300 Subject: [PATCH 06/10] Fix examples --- README.md | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6d9c243..d804928 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,12 @@ if ($response->isSuccessful()) { // or // $order = $response->getOrder(); // $order['totalSumm']; +} else { + echo sprintf( + "Error of the order receipt: [Code %s] %s", + $response->getStatusCode(), + $response->getErrorMsg() + ); } ``` @@ -69,9 +75,19 @@ try { echo "CRM connection error: " . $e->getMessage(); } -if ($response->isSuccessful() && 201 === $response->getStatusCode()) { - echo 'Order created successfully! Order ID in CRM - ' . $response->id; - // or $response['id']; - // or $response->getId(); +if ($response->isSuccessful()) { + if (201 === $response->getStatusCode()) { + echo 'Order created successfully! Order ID in CRM = ' . $response->id; + // or $response['id']; + // or $response->getId(); + } else { + echo 'Order updated successfully!'; + } +} else { + echo sprintf( + "Error of the order creating: [Code %s] %s", + $response->getStatusCode(), + $response->getErrorMsg() + ); } ``` \ No newline at end of file From a0f583406cccee238e5f81a9a7bb0c4068cda1ee Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 13:48:07 +0300 Subject: [PATCH 07/10] Complete orders and customers methods --- lib/RetailCrm/ApiClient.php | 164 +++++++++- .../Tests/ApiClientCustomersTest.php | 271 +++++++++++++++++ tests/RetailCrm/Tests/ApiClientOrdersTest.php | 282 ++++++++++++++++++ tests/RetailCrm/Tests/ApiClientTest.php | 143 --------- 4 files changed, 713 insertions(+), 147 deletions(-) create mode 100644 tests/RetailCrm/Tests/ApiClientCustomersTest.php create mode 100644 tests/RetailCrm/Tests/ApiClientOrdersTest.php diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index beab987..3671e2f 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -40,6 +40,10 @@ class ApiClient */ public function ordersCreate(array $order) { + if (!sizeof($order)) { + throw new \InvalidArgumentException('Parameter `order` must contains a data'); + } + return $this->client->makeRequest("/orders/create", Client::METHOD_POST, array( 'order' => json_encode($order) )); @@ -53,6 +57,10 @@ class ApiClient */ public function ordersEdit(array $order, $by = 'externalId') { + if (!sizeof($order)) { + throw new \InvalidArgumentException('Parameter `order` must contains a data'); + } + $this->checkIdParameter($by); if (!isset($order[$by])) { @@ -65,6 +73,23 @@ class ApiClient )); } + /** + * Upload array of the orders + * + * @param array $orders + * @return ApiResponse + */ + public function ordersUpload(array $orders) + { + if (!sizeof($orders)) { + throw new \InvalidArgumentException('Parameter `orders` must contains array of the orders'); + } + + return $this->client->makeRequest("/orders/upload", Client::METHOD_POST, array( + 'orders' => json_encode($orders), + )); + } + /** * Get order by id or externalId * @@ -111,10 +136,10 @@ class ApiClient /** * Returns filtered orders list * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * @return void + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * @return ApiResponse */ public function ordersList(array $filter = array(), $page = null, $limit = null) { @@ -133,6 +158,137 @@ class ApiClient return $this->client->makeRequest('/orders', Client::METHOD_GET, $parameters); } + /** + * Save order IDs' (id and externalId) association in the CRM + * + * @param array $ids + * @return ApiResponse + */ + public function ordersFixExternalIds(array $ids) + { + if (!sizeof($ids)) { + throw new \InvalidArgumentException('Method parameter must contains at least one IDs pair'); + } + + return $this->client->makeRequest("/orders/fix-external-ids", Client::METHOD_POST, array( + 'orders' => json_encode($ids), + )); + } + + /** + * Create a customer + * + * @param array $customer + * @return ApiResponse + */ + public function customersCreate(array $customer) + { + if (!sizeof($customer)) { + throw new \InvalidArgumentException('Parameter `customer` must contains a data'); + } + + return $this->client->makeRequest("/customers/create", Client::METHOD_POST, array( + 'customer' => json_encode($customer) + )); + } + + /** + * Edit a customer + * + * @param array $customer + * @return ApiResponse + */ + public function customersEdit(array $customer, $by = 'externalId') + { + if (!sizeof($customer)) { + throw new \InvalidArgumentException('Parameter `customer` must contains a data'); + } + + $this->checkIdParameter($by); + + if (!isset($customer[$by])) { + throw new \InvalidArgumentException(sprintf('Customer array must contain the "%s" parameter.', $by)); + } + + return $this->client->makeRequest("/customers/" . $customer[$by] . "/edit", Client::METHOD_POST, array( + 'customer' => json_encode($customer), + 'by' => $by, + )); + } + + /** + * Upload array of the customers + * + * @param array $customers + * @return ApiResponse + */ + public function customersUpload(array $customers) + { + if (!sizeof($customers)) { + throw new \InvalidArgumentException('Parameter `customers` must contains array of the customers'); + } + + return $this->client->makeRequest("/customers/upload", Client::METHOD_POST, array( + 'customers' => json_encode($customers), + )); + } + + /** + * Get customer by id or externalId + * + * @param string $id + * @param string $by (default: 'externalId') + * @return ApiResponse + */ + public function customersGet($id, $by = 'externalId') + { + $this->checkIdParameter($by); + + return $this->client->makeRequest("/customers/$id", Client::METHOD_GET, array('by' => $by)); + } + + /** + * Returns filtered customers list + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * @return ApiResponse + */ + public function customersList(array $filter = array(), $page = null, $limit = null) + { + $parameters = array(); + + if (sizeof($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest('/customers', Client::METHOD_GET, $parameters); + } + + /** + * Save customer IDs' (id and externalId) association in the CRM + * + * @param array $ids + * @return ApiResponse + */ + public function customersFixExternalIds(array $ids) + { + if (!sizeof($ids)) { + throw new \InvalidArgumentException('Method parameter must contains at least one IDs pair'); + } + + return $this->client->makeRequest("/customers/fix-external-ids", Client::METHOD_POST, array( + 'customers' => json_encode($ids), + )); + } + /** * Check ID parameter * diff --git a/tests/RetailCrm/Tests/ApiClientCustomersTest.php b/tests/RetailCrm/Tests/ApiClientCustomersTest.php new file mode 100644 index 0000000..cde18d6 --- /dev/null +++ b/tests/RetailCrm/Tests/ApiClientCustomersTest.php @@ -0,0 +1,271 @@ +customersCreate(array( + 'firstName' => self::FIRST_NAME, + 'externalId' => $externalId, + )); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(201, $response->getStatusCode()); + $this->assertTrue(is_int($response->getId())); + + return array( + 'id' => $response->getId(), + 'externalId' => $externalId, + ); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testCustomersCreateExceptionEmpty() + { + $client = static::getApiClient(); + + $response = $client->customersCreate(array()); + } + + /** + * @group integration + * @depends testCustomersCreate + */ + public function testCustomersGet(array $ids) + { + $client = static::getApiClient(); + + $response = $client->customersGet(678678678); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(404, $response->getStatusCode()); + $this->assertFalse($response->success); + + $response = $client->customersGet($ids['id'], 'id'); + $customerById = $response->customer; + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + $this->assertEquals(self::FIRST_NAME, $response->customer['firstName']); + + $response = $client->customersGet($ids['externalId'], 'externalId'); + $this->assertEquals($customerById['id'], $response->customer['id']); + + return $ids; + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testCustomersGetException() + { + $client = static::getApiClient(); + + $response = $client->customersGet(678678678, 'asdf'); + } + + /** + * @group integration + * @depends testCustomersGet + */ + public function testCustomersEdit(array $ids) + { + $client = static::getApiClient(); + + $response = $client->customersEdit( + array( + 'id' => 22342134, + 'lastName' => '12345', + ), + 'id' + ); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(404, $response->getStatusCode()); + + $response = $client->customersEdit(array( + 'externalId' => $ids['externalId'], + 'lastName' => '12345', + )); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + + $response = $client->customersEdit(array( + 'externalId' => 'c-edit-' . time(), + 'lastName' => '12345', + )); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(201, $response->getStatusCode()); + $this->assertTrue($response->success); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testCustomersEditExceptionEmpty() + { + $client = static::getApiClient(); + + $response = $client->customersEdit(array(), 'asdf'); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testCustomersEditException() + { + $client = static::getApiClient(); + + $response = $client->customersEdit(array('id' => 678678678), 'asdf'); + } + + /** + * @group integration + */ + public function testCustomersList() + { + $client = static::getApiClient(); + + $response = $client->customersList(); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue($response->isSuccessful()); + $this->assertTrue(isset($response['customers'])); + + $response = $client->customersList(array(), 1, 300); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertFalse( + $response->isSuccessful(), + 'Pagination error' + ); + + $response = $client->customersList(array('maxOrdersCount' => 10), 1); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue( + $response->isSuccessful(), + 'API returns customers list' + ); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testCustomersFixExternalIdsException() + { + $client = static::getApiClient(); + + $response = $client->customersFixExternalIds(array()); + } + + /** + * @group integration + */ + public function testCustomersFixExternalIds() + { + $client = static::getApiClient(); + + $response = $client->ordersCreate(array( + 'firstName' => 'Aaa111', + )); + $this->assertTrue( + $response->isSuccessful(), + 'Order created' + ); + + $response = $client->ordersGet($response->id, 'id'); + $this->assertTrue( + $response->isSuccessful(), + 'Order fetched' + ); + + $id = $response->order['customer']['id']; + $externalId = 'asdf' . time(); + + $response = $client->customersFixExternalIds(array( + array('id' => $id, 'externalId' => $externalId) + )); + + $this->assertTrue( + $response->isSuccessful(), + 'Fixed customer ids' + ); + + $response = $client->customersGet($externalId); + $this->assertTrue( + $response->isSuccessful(), + 'Got customer' + ); + $this->assertEquals( + $id, + $response->customer['id'], + 'Fixing of customer ids were right' + ); + $this->assertEquals( + $externalId, + $response->customer['externalId'], + 'Fixing of customer ids were right' + ); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testCustomersUploadExceptionEmpty() + { + $client = static::getApiClient(); + + $response = $client->customersUpload(array()); + } + + /** + * @group integration + */ + public function testCustomersUpload() + { + $client = static::getApiClient(); + + $externalIdA = 'upload-a-' . time(); + $externalIdB = 'upload-b-' . time(); + + $response = $client->customersUpload(array( + array( + 'externalId' => $externalIdA, + 'firstName' => 'Aaa', + ), + array( + 'externalId' => $externalIdB, + 'lastName' => 'Bbb', + ), + )); + $this->assertTrue( + $response->isSuccessful(), + 'Got customer' + ); + $this->assertEquals( + $externalIdA, + $response->uploadedCustomers[0]['externalId'] + ); + $this->assertEquals( + $externalIdB, + $response->uploadedCustomers[1]['externalId'] + ); + } +} diff --git a/tests/RetailCrm/Tests/ApiClientOrdersTest.php b/tests/RetailCrm/Tests/ApiClientOrdersTest.php new file mode 100644 index 0000000..2b50977 --- /dev/null +++ b/tests/RetailCrm/Tests/ApiClientOrdersTest.php @@ -0,0 +1,282 @@ +ordersCreate(array( + 'firstName' => self::FIRST_NAME, + 'externalId' => $externalId, + )); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(201, $response->getStatusCode()); + $this->assertTrue(is_int($response->getId())); + + return array( + 'id' => $response->getId(), + 'externalId' => $externalId, + ); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testOrdersCreateExceptionEmpty() + { + $client = static::getApiClient(); + + $response = $client->ordersCreate(array()); + } + + /** + * @group integration + * @depends testOrdersCreate + */ + public function testOrdersGet(array $ids) + { + $client = static::getApiClient(); + + $response = $client->ordersGet(678678678); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(404, $response->getStatusCode()); + $this->assertFalse($response->success); + + $response = $client->ordersGet($ids['id'], 'id'); + $orderById = $response->order; + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + $this->assertEquals(self::FIRST_NAME, $response->order['firstName']); + + $response = $client->ordersGet($ids['externalId'], 'externalId'); + $this->assertEquals($orderById['id'], $response->order['id']); + + return $ids; + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testOrdersGetException() + { + $client = static::getApiClient(); + + $response = $client->ordersGet(678678678, 'asdf'); + } + + /** + * @group integration + * @depends testOrdersGet + */ + public function testOrdersEdit(array $ids) + { + $client = static::getApiClient(); + + $response = $client->ordersEdit( + array( + 'id' => 22342134, + 'lastName' => '12345', + ), + 'id' + ); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(404, $response->getStatusCode()); + + $response = $client->ordersEdit(array( + 'externalId' => $ids['externalId'], + 'lastName' => '12345', + )); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + + $response = $client->ordersEdit(array( + 'externalId' => time(), + 'lastName' => '12345', + )); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(201, $response->getStatusCode()); + $this->assertTrue($response->success); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testOrdersEditExceptionEmpty() + { + $client = static::getApiClient(); + + $response = $client->ordersEdit(array(), 'asdf'); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testOrdersEditException() + { + $client = static::getApiClient(); + + $response = $client->ordersEdit(array('id' => 678678678), 'asdf'); + } + + /** + * @group integration + */ + public function testOrdersHistory() + { + $client = static::getApiClient(); + + $response = $client->ordersHistory(); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + $this->assertTrue( + isset($response['orders']), + 'API returns orders history' + ); + } + + /** + * @group integration + */ + public function testOrdersList() + { + $client = static::getApiClient(); + + $response = $client->ordersList(); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue($response->isSuccessful()); + $this->assertTrue(isset($response['orders'])); + + $response = $client->ordersList(array(), 1, 300); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertFalse( + $response->isSuccessful(), + 'Pagination error' + ); + + $response = $client->ordersList(array('paymentStatus' => 'paid'), 1); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue( + $response->isSuccessful(), + 'API returns orders list' + ); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testOrdersFixExternalIdsException() + { + $client = static::getApiClient(); + + $response = $client->ordersFixExternalIds(array()); + } + + /** + * @group integration +] */ + public function testOrdersFixExternalIds() + { + $client = static::getApiClient(); + + $response = $client->ordersCreate(array( + 'firstName' => 'Aaa', + )); + $this->assertTrue( + $response->isSuccessful(), + 'Order created' + ); + + $id = $response->id; + $externalId = 'asdf' . time(); + + $response = $client->ordersFixExternalIds(array( + array('id' => $id, 'externalId' => $externalId) + )); + + $this->assertTrue( + $response->isSuccessful(), + 'Fixed order ids' + ); + + $response = $client->ordersGet($externalId); + $this->assertTrue( + $response->isSuccessful(), + 'Got order' + ); + $this->assertEquals( + $id, + $response->order['id'], + 'Fixing of order ids were right' + ); + $this->assertEquals( + $externalId, + $response->order['externalId'], + 'Fixing of order ids were right' + ); + } + + /** + * @group unit + * @expectedException \InvalidArgumentException + */ + public function testOrdersUploadExceptionEmpty() + { + $client = static::getApiClient(); + + $response = $client->ordersUpload(array()); + } + + /** + * @group integration + */ + public function testOrdersUpload() + { + $client = static::getApiClient(); + + $externalIdA = 'upload-a-' . time(); + $externalIdB = 'upload-b-' . time(); + + $response = $client->ordersUpload(array( + array( + 'externalId' => $externalIdA, + 'firstName' => 'Aaa', + ), + array( + 'externalId' => $externalIdB, + 'lastName' => 'Bbb', + ), + )); + $this->assertTrue( + $response->isSuccessful(), + 'Got order' + ); + $this->assertEquals( + $externalIdA, + $response->uploadedOrders[0]['externalId'] + ); + $this->assertEquals( + $externalIdB, + $response->uploadedOrders[1]['externalId'] + ); + } +} diff --git a/tests/RetailCrm/Tests/ApiClientTest.php b/tests/RetailCrm/Tests/ApiClientTest.php index cf5bc03..fe78cc1 100644 --- a/tests/RetailCrm/Tests/ApiClientTest.php +++ b/tests/RetailCrm/Tests/ApiClientTest.php @@ -6,8 +6,6 @@ use RetailCrm\Test\TestCase; class ApiClientTest extends TestCase { - const FIRST_NAME = 'Иннокентий'; - /** * @group unit */ @@ -17,145 +15,4 @@ class ApiClientTest extends TestCase $this->assertInstanceOf('RetailCrm\ApiClient', $client); } - - /** - * @group integration - */ - public function testOrdersCreate() - { - $client = static::getApiClient(); - - $externalId = time(); - - $response = $client->ordersCreate(array( - 'firstName' => self::FIRST_NAME, - 'externalId' => $externalId, - )); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(201, $response->getStatusCode()); - $this->assertTrue(is_int($response->getId())); - - return array( - 'id' => $response->getId(), - 'externalId' => $externalId, - ); - } - - /** - * @group integration - * @depends testOrdersCreate - */ - public function testOrdersGet(array $ids) - { - $client = static::getApiClient(); - - $response = $client->ordersGet(678678678); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(404, $response->getStatusCode()); - $this->assertFalse($response->success); - - $response = $client->ordersGet($ids['id'], 'id'); - $orderById = $response->order; - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); - $this->assertEquals(self::FIRST_NAME, $response->order['firstName']); - - $response = $client->ordersGet($ids['externalId'], 'externalId'); - $this->assertEquals($orderById['id'], $response->order['id']); - - return $ids; - } - - /** - * @group unit - * @expectedException \InvalidArgumentException - */ - public function testOrdersGetException() - { - $client = static::getApiClient(); - - $response = $client->ordersGet(678678678, 'asdf'); - } - - /** - * @group integration - * @depends testOrdersGet - */ - public function testOrdersEdit(array $ids) - { - $client = static::getApiClient(); - - $response = $client->ordersEdit( - array( - 'id' => 22342134, - 'lastName' => '12345', - ), - 'id' - ); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(404, $response->getStatusCode()); - - $response = $client->ordersEdit(array( - 'externalId' => $ids['externalId'], - 'lastName' => '12345', - )); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); - - $response = $client->ordersEdit(array( - 'externalId' => time(), - 'lastName' => '12345', - )); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(201, $response->getStatusCode()); - $this->assertTrue($response->success); - } - - /** - * @group unit - * @expectedException \InvalidArgumentException - */ - public function testOrdersEditException() - { - $client = static::getApiClient(); - - $response = $client->ordersEdit(array('id' => 678678678), 'asdf'); - } - - /** - * @group integration - */ - public function testOrdersHistory() - { - $client = static::getApiClient(); - - $response = $client->ordersHistory(); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertEquals(200, $response->getStatusCode()); - $this->assertTrue($response->success); - $this->assertTrue(isset($response['orders'])); - } - - /** - * @group integration - */ - public function testOrdersList() - { - $client = static::getApiClient(); - - $response = $client->ordersList(); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertTrue($response->isSuccessful()); - $this->assertTrue(isset($response['orders'])); - - $response = $client->ordersList(array(), 1, 300); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertFalse($response->isSuccessful()); - - $response = $client->ordersList(array('paymentStatus' => 'paid'), 1); - $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - $this->assertTrue($response->isSuccessful()); - } } From 5a8151692226ddb89a0ca6294f512b8c31fda3a4 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 14:05:32 +0300 Subject: [PATCH 08/10] Example of the docs --- composer.json | 3 + docs/ApiIndex.md | 13 + docs/RetailCrm-ApiClient.md | 329 +++++++ docs/RetailCrm-Exception-CurlException.md | 19 + ...etailCrm-Exception-InvalidJsonException.md | 19 + docs/RetailCrm-Http-Client.md | 110 +++ docs/RetailCrm-Response-ApiResponse.md | 205 +++++ docs/structure.xml | 812 ++++++++++++++++++ 8 files changed, 1510 insertions(+) create mode 100644 docs/ApiIndex.md create mode 100644 docs/RetailCrm-ApiClient.md create mode 100644 docs/RetailCrm-Exception-CurlException.md create mode 100644 docs/RetailCrm-Exception-InvalidJsonException.md create mode 100644 docs/RetailCrm-Http-Client.md create mode 100644 docs/RetailCrm-Response-ApiResponse.md create mode 100644 docs/structure.xml diff --git a/composer.json b/composer.json index aad1734..7303063 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,9 @@ "php": ">=5.3.0", "ext-curl": "*" }, + "require-dev" : { + "evert/phpdoc-md": "~0.0.7" + }, "support": { "email": "support@intarocrm.ru" }, diff --git a/docs/ApiIndex.md b/docs/ApiIndex.md new file mode 100644 index 0000000..37c82b3 --- /dev/null +++ b/docs/ApiIndex.md @@ -0,0 +1,13 @@ +API Index +========= + +* RetailCrm + * [ApiClient](RetailCrm-ApiClient.md) + * RetailCrm\Exception + * [CurlException](RetailCrm-Exception-CurlException.md) + * [InvalidJsonException](RetailCrm-Exception-InvalidJsonException.md) + * RetailCrm\Http + * [Client](RetailCrm-Http-Client.md) + * RetailCrm\Response + * [ApiResponse](RetailCrm-Response-ApiResponse.md) + diff --git a/docs/RetailCrm-ApiClient.md b/docs/RetailCrm-ApiClient.md new file mode 100644 index 0000000..7094ddd --- /dev/null +++ b/docs/RetailCrm-ApiClient.md @@ -0,0 +1,329 @@ +RetailCrm\ApiClient +=============== + +retailCRM API client class + + + + +* Class name: ApiClient +* Namespace: RetailCrm + + + +Constants +---------- + + +### VERSION + +``` +const VERSION = 'v3' +``` + + + + + +Properties +---------- + + +### $client + +``` +protected mixed $client +``` + + + + + +* Visibility: **protected** + + +Methods +------- + + +### \RetailCrm\ApiClient::__construct() + +``` +void RetailCrm\ApiClient::\RetailCrm\ApiClient::__construct()(string $url, string $apiKey) +``` + +Client creating + + + +* Visibility: **public** + +#### Arguments + +* $url **string** +* $apiKey **string** + + + +### \RetailCrm\ApiClient::ordersCreate() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersCreate()(array $order) +``` + +Create a order + + + +* Visibility: **public** + +#### Arguments + +* $order **array** + + + +### \RetailCrm\ApiClient::ordersEdit() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersEdit()(array $order, $by) +``` + +Edit a order + + + +* Visibility: **public** + +#### Arguments + +* $order **array** +* $by **mixed** + + + +### \RetailCrm\ApiClient::ordersUpload() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersUpload()(array $orders) +``` + +Upload array of the orders + + + +* Visibility: **public** + +#### Arguments + +* $orders **array** + + + +### \RetailCrm\ApiClient::ordersGet() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersGet()(string $id, string $by) +``` + +Get order by id or externalId + + + +* Visibility: **public** + +#### Arguments + +* $id **string** +* $by **string** - <p>(default: 'externalId')</p> + + + +### \RetailCrm\ApiClient::ordersHistory() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersHistory()(\DateTime $startDate, \DateTime $endDate, integer $limit, integer $offset) +``` + +Returns a orders history + + + +* Visibility: **public** + +#### Arguments + +* $startDate **DateTime** - <p>(default: null)</p> +* $endDate **DateTime** - <p>(default: null)</p> +* $limit **integer** - <p>(default: 100)</p> +* $offset **integer** - <p>(default: 0)</p> + + + +### \RetailCrm\ApiClient::ordersList() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersList()(array $filter, integer $page, integer $limit) +``` + +Returns filtered orders list + + + +* Visibility: **public** + +#### Arguments + +* $filter **array** - <p>(default: array())</p> +* $page **integer** - <p>(default: null)</p> +* $limit **integer** - <p>(default: null)</p> + + + +### \RetailCrm\ApiClient::ordersFixExternalIds() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersFixExternalIds()(array $ids) +``` + +Save order IDs' (id and externalId) association in the CRM + + + +* Visibility: **public** + +#### Arguments + +* $ids **array** + + + +### \RetailCrm\ApiClient::customersCreate() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersCreate()(array $customer) +``` + +Create a customer + + + +* Visibility: **public** + +#### Arguments + +* $customer **array** + + + +### \RetailCrm\ApiClient::customersEdit() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersEdit()(array $customer, $by) +``` + +Edit a customer + + + +* Visibility: **public** + +#### Arguments + +* $customer **array** +* $by **mixed** + + + +### \RetailCrm\ApiClient::customersUpload() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersUpload()(array $customers) +``` + +Upload array of the customers + + + +* Visibility: **public** + +#### Arguments + +* $customers **array** + + + +### \RetailCrm\ApiClient::customersGet() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersGet()(string $id, string $by) +``` + +Get customer by id or externalId + + + +* Visibility: **public** + +#### Arguments + +* $id **string** +* $by **string** - <p>(default: 'externalId')</p> + + + +### \RetailCrm\ApiClient::customersList() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersList()(array $filter, integer $page, integer $limit) +``` + +Returns filtered customers list + + + +* Visibility: **public** + +#### Arguments + +* $filter **array** - <p>(default: array())</p> +* $page **integer** - <p>(default: null)</p> +* $limit **integer** - <p>(default: null)</p> + + + +### \RetailCrm\ApiClient::customersFixExternalIds() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersFixExternalIds()(array $ids) +``` + +Save customer IDs' (id and externalId) association in the CRM + + + +* Visibility: **public** + +#### Arguments + +* $ids **array** + + + +### \RetailCrm\ApiClient::checkIdParameter() + +``` +boolean RetailCrm\ApiClient::\RetailCrm\ApiClient::checkIdParameter()(string $by) +``` + +Check ID parameter + + + +* Visibility: **protected** + +#### Arguments + +* $by **string** + + diff --git a/docs/RetailCrm-Exception-CurlException.md b/docs/RetailCrm-Exception-CurlException.md new file mode 100644 index 0000000..5bdff30 --- /dev/null +++ b/docs/RetailCrm-Exception-CurlException.md @@ -0,0 +1,19 @@ +RetailCrm\Exception\CurlException +=============== + + + + + + +* Class name: CurlException +* Namespace: RetailCrm\Exception +* Parent class: RuntimeException + + + + + + + + diff --git a/docs/RetailCrm-Exception-InvalidJsonException.md b/docs/RetailCrm-Exception-InvalidJsonException.md new file mode 100644 index 0000000..cf03b0d --- /dev/null +++ b/docs/RetailCrm-Exception-InvalidJsonException.md @@ -0,0 +1,19 @@ +RetailCrm\Exception\InvalidJsonException +=============== + + + + + + +* Class name: InvalidJsonException +* Namespace: RetailCrm\Exception +* Parent class: DomainException + + + + + + + + diff --git a/docs/RetailCrm-Http-Client.md b/docs/RetailCrm-Http-Client.md new file mode 100644 index 0000000..bc70f2c --- /dev/null +++ b/docs/RetailCrm-Http-Client.md @@ -0,0 +1,110 @@ +RetailCrm\Http\Client +=============== + +HTTP client + + + + +* Class name: Client +* Namespace: RetailCrm\Http + + + +Constants +---------- + + +### METHOD_GET + +``` +const METHOD_GET = 'GET' +``` + + + + + +### METHOD_POST + +``` +const METHOD_POST = 'POST' +``` + + + + + +Properties +---------- + + +### $url + +``` +protected mixed $url +``` + + + + + +* Visibility: **protected** + + +### $defaultParameters + +``` +protected mixed $defaultParameters +``` + + + + + +* Visibility: **protected** + + +Methods +------- + + +### \RetailCrm\Http\Client::__construct() + +``` +mixed RetailCrm\Http\Client::\RetailCrm\Http\Client::__construct()($url, array $defaultParameters) +``` + + + + + +* Visibility: **public** + +#### Arguments + +* $url **mixed** +* $defaultParameters **array** + + + +### \RetailCrm\Http\Client::makeRequest() + +``` +\RetailCrm\Response\ApiResponse RetailCrm\Http\Client::\RetailCrm\Http\Client::makeRequest()(string $path, string $method, array $parameters, $timeout) +``` + +Make HTTP request + + + +* Visibility: **public** + +#### Arguments + +* $path **string** +* $method **string** - <p>(default: 'GET')</p> +* $parameters **array** - <p>(default: array())</p> +* $timeout **mixed** + + diff --git a/docs/RetailCrm-Response-ApiResponse.md b/docs/RetailCrm-Response-ApiResponse.md new file mode 100644 index 0000000..24e768f --- /dev/null +++ b/docs/RetailCrm-Response-ApiResponse.md @@ -0,0 +1,205 @@ +RetailCrm\Response\ApiResponse +=============== + +Response from retailCRM API + + + + +* Class name: ApiResponse +* Namespace: RetailCrm\Response +* This class implements: ArrayAccess + + + + +Properties +---------- + + +### $statusCode + +``` +protected mixed $statusCode +``` + + + + + +* Visibility: **protected** + + +### $response + +``` +protected mixed $response +``` + + + + + +* Visibility: **protected** + + +Methods +------- + + +### \RetailCrm\Response\ApiResponse::__construct() + +``` +mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::__construct()($statusCode, $responseBody) +``` + + + + + +* Visibility: **public** + +#### Arguments + +* $statusCode **mixed** +* $responseBody **mixed** + + + +### \RetailCrm\Response\ApiResponse::getStatusCode() + +``` +integer RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::getStatusCode()() +``` + +Return HTTP response status code + + + +* Visibility: **public** + + + +### \RetailCrm\Response\ApiResponse::isSuccessful() + +``` +boolean RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::isSuccessful()() +``` + +HTTP request was successful + + + +* Visibility: **public** + + + +### \RetailCrm\Response\ApiResponse::__call() + +``` +mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::__call()(string $name, $arguments) +``` + +Allow to access for the property throw class method + + + +* Visibility: **public** + +#### Arguments + +* $name **string** +* $arguments **mixed** + + + +### \RetailCrm\Response\ApiResponse::__get() + +``` +mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::__get()(string $name) +``` + +Allow to access for the property throw object property + + + +* Visibility: **public** + +#### Arguments + +* $name **string** + + + +### \RetailCrm\Response\ApiResponse::offsetSet() + +``` +mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::offsetSet()($offset, $value) +``` + + + + + +* Visibility: **public** + +#### Arguments + +* $offset **mixed** +* $value **mixed** + + + +### \RetailCrm\Response\ApiResponse::offsetUnset() + +``` +mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::offsetUnset()($offset) +``` + + + + + +* Visibility: **public** + +#### Arguments + +* $offset **mixed** + + + +### \RetailCrm\Response\ApiResponse::offsetExists() + +``` +mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::offsetExists()($offset) +``` + + + + + +* Visibility: **public** + +#### Arguments + +* $offset **mixed** + + + +### \RetailCrm\Response\ApiResponse::offsetGet() + +``` +mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::offsetGet()($offset) +``` + + + + + +* Visibility: **public** + +#### Arguments + +* $offset **mixed** + + diff --git a/docs/structure.xml b/docs/structure.xml new file mode 100644 index 0000000..e11e4aa --- /dev/null +++ b/docs/structure.xml @@ -0,0 +1,812 @@ + + + + + + + + + + \RetailCrm\Http\Client + \RetailCrm\Response\ApiResponse + + + ApiClient + \RetailCrm\ApiClient + + retailCRM API client class + + + + + VERSION + \RetailCrm\ApiClient::VERSION + 'v3' + + + + + + + $client + \RetailCrm\ApiClient::client + + + + + + + + __construct + \RetailCrm\ApiClient::__construct() + + Client creating + + + string + + + string + + + void + + + + $url + + string + + + $apiKey + + string + + + + ordersCreate + \RetailCrm\ApiClient::ordersCreate() + + Create a order + + + array + + + \RetailCrm\Response\ApiResponse + + + + $order + + array + + + + ordersEdit + \RetailCrm\ApiClient::ordersEdit() + + Edit a order + + + array + + + \RetailCrm\Response\ApiResponse + + + + $order + + array + + + $by + 'externalId' + + + + + ordersUpload + \RetailCrm\ApiClient::ordersUpload() + + Upload array of the orders + + + array + + + \RetailCrm\Response\ApiResponse + + + + $orders + + array + + + + ordersGet + \RetailCrm\ApiClient::ordersGet() + + Get order by id or externalId + + + string + + + string + + + \RetailCrm\Response\ApiResponse + + + + $id + + string + + + $by + 'externalId' + string + + + + ordersHistory + \RetailCrm\ApiClient::ordersHistory() + + Returns a orders history + + + \DateTime + + + \DateTime + + + integer + + + integer + + + \RetailCrm\Response\ApiResponse + + + + $startDate + null + \DateTime + + + $endDate + null + \DateTime + + + $limit + 100 + integer + + + $offset + 0 + integer + + + + ordersList + \RetailCrm\ApiClient::ordersList() + + Returns filtered orders list + + + array + + + integer + + + integer + + + \RetailCrm\Response\ApiResponse + + + + $filter + array() + array + + + $page + null + integer + + + $limit + null + integer + + + + ordersFixExternalIds + \RetailCrm\ApiClient::ordersFixExternalIds() + + Save order IDs' (id and externalId) association in the CRM + + + array + + + \RetailCrm\Response\ApiResponse + + + + $ids + + array + + + + customersCreate + \RetailCrm\ApiClient::customersCreate() + + Create a customer + + + array + + + \RetailCrm\Response\ApiResponse + + + + $customer + + array + + + + customersEdit + \RetailCrm\ApiClient::customersEdit() + + Edit a customer + + + array + + + \RetailCrm\Response\ApiResponse + + + + $customer + + array + + + $by + 'externalId' + + + + + customersUpload + \RetailCrm\ApiClient::customersUpload() + + Upload array of the customers + + + array + + + \RetailCrm\Response\ApiResponse + + + + $customers + + array + + + + customersGet + \RetailCrm\ApiClient::customersGet() + + Get customer by id or externalId + + + string + + + string + + + \RetailCrm\Response\ApiResponse + + + + $id + + string + + + $by + 'externalId' + string + + + + customersList + \RetailCrm\ApiClient::customersList() + + Returns filtered customers list + + + array + + + integer + + + integer + + + \RetailCrm\Response\ApiResponse + + + + $filter + array() + array + + + $page + null + integer + + + $limit + null + integer + + + + customersFixExternalIds + \RetailCrm\ApiClient::customersFixExternalIds() + + Save customer IDs' (id and externalId) association in the CRM + + + array + + + \RetailCrm\Response\ApiResponse + + + + $ids + + array + + + + checkIdParameter + \RetailCrm\ApiClient::checkIdParameter() + + Check ID parameter + + + string + + + boolean + + + + $by + + string + + + + + No summary was found for this file + Argument $url is missing from the Docblock of __construct + Argument $order is missing from the Docblock of ordersCreate + Argument $order is missing from the Docblock of ordersEdit + Argument $by is missing from the Docblock of ordersEdit + Argument $orders is missing from the Docblock of ordersUpload + Argument $id is missing from the Docblock of ordersGet + Argument $startDate is missing from the Docblock of ordersHistory + Argument $filter is missing from the Docblock of ordersList + Argument $ids is missing from the Docblock of ordersFixExternalIds + Argument $customer is missing from the Docblock of customersCreate + Argument $customer is missing from the Docblock of customersEdit + Argument $by is missing from the Docblock of customersEdit + Argument $customers is missing from the Docblock of customersUpload + Argument $id is missing from the Docblock of customersGet + Argument $filter is missing from the Docblock of customersList + Argument $ids is missing from the Docblock of customersFixExternalIds + Argument $by is missing from the Docblock of checkIdParameter + No summary for property $client + + eJztWW1P40YQ/p5fsRdxsoMSAuq30NBS4A7UUlCgJ1XHidvYa9ieY/u8ayCt+O+dfbWdEOPE0UFP9Rdi77w/s7Ozw48/JbdJqxXhCWEJ9ggaEY5peJBOdlutjBXer445T64OQkoivjuzNALmOGLkaj+h5jfw9zc3W2gToVQRjk7R/vkJ8qQI+IMZg+V+S/5CwKqEt/5pIXg8EMLRh6PRxcnZ72iInLsfHJAplpI05sTjxEcbnrZHfpf6xLOJDrSSlGBOoxv92az+nOAUTxBiPIVFtJGl4aIlnNBfydSugitZGqG7mPr6W1+ZlI1D6qEgizxO4whdX0v708zjrhDfNZI6kly5KB4aINfpO+jNELFsDByaHH6FJJIvHdRDO1200+kU+MQjFtEWhKYPkTEfH1ut0vpQkyEHDABFW4iRMBgMdGR3C+T8lrLensZniCJyr+OobcJpiqeuoxxx0HDPOtVR+h/ncRAAEIRRnPokXQCDlGuMKBLaeBfyqjLskpkppa4SqwQ+FfY3jP5N4sDVFLPR5bdpfC+DcHUS3eGQ+vvpTTaBcBw9eCQR+lznXHhAOEnRZynlM5pkkLYAPqR8xMBxH3PsdJ7ERztXintvb4K/kBH5mhHG3XZfedSXiUzaXQ3IYHB6dHl8dnh9fnZxaYApWe9IRgnSXyyOrknkxT5xi9EQz2LkjnzKvzFuQmUJNdg146nY++QBQhzh8MR3XiWSBsJb4n058a0oF8zvFHaYtJUyRrg29SMQfFrJXpZAfeKB65wJORqKosUghaD2W9ZGiTFny5EB7TTOxjZUkYID8NbuEwBvbfnZLdOOdbUZT7s1MvePJIyxr0MSBzIQyvDaecyaJbKyoJTK7Pm8ZetJXDaXufOBaF6QMuni0oCzBYizTh1k3xOuHEBQFqgPv1FeGarPeAWuPbWfXgaprk8CnIV88ETRWTkf3osNT/065axmJVkCKVA8D9P7I4tSYXctjvxI6mPmQGAI9PI4nS4I+tUhnFaXdEKER4zjlIsPheBGWRh2KrlI5NfhgSJoU2wjpBM4tHKOne3taoY4CKAYFzi2GyJ9rMLi5q4U3B9KF7oFP62XZkm7MBSmd619Q2NXIU9sVWewrJCcPWpy1XOdY8790bFUzifRLdrX3l4QpxPMXefP3qTno+MBHcxUjpI27UulLk2jNOmXZfXIEFVqkRRShwtwd3RUFwpUUa6UqEiKItWXFcuoYzan3kbO0xu0YMKzOzOgIdAR32zQECTXOe8UX2EL6Fyq3jgJvmm2NcscK+2138BDc8ZqL+xO6GoT5/ZVrne5vWROaqVo/ipWTBZFo3Jc/V6UesIauPoNlbWVQgVBMf/E+/Ni17FXVsjrBvl8ge90l4JODqFdcOGcx5FfOOg7CDMWexTLXNCd7sHotE62U79ha/eOPhxZS5hJPxBb2d+J9ZWau1PCb2M/b+FnWzuOQoLhSxwRES4gpGnz5i6gDz0T7x7Yvo42T4SgTo9nJwYeeBpP6l0+Z2iXxtbwz4wOzOdKbC1R0+7dCFr7DMF6t8IYwfDOA1oOTjWoepjwIpAWpwrm49KDhZcFeYXxgtGzhgnDgRb1rYYMebrKOUPJk5VGDTVyeO0DB+vEMrm+8tlkBZQnD/ZzrdxuPn+wkipHEJZqLSVt+UFErn9hPtQfRxiO/8xEwrr4MkOJHLi1ziXs7cfK/64vQNbL/+9Ar/AOlBeYhtcgW1xe103I+vd9X4byUtXkPlRx2tS+Eom6Cx7lnlefLFAxZ6Edx3FYxtT+Dz2H9anyPlsmcBjG98R/F6e/TG2hKJ4dXeRQvxh11ZVG14pUtFRlKY2a0xKjjPcHHGa6Jw3gNM6TpT2ethFlKIo5klK30L4yQ7wC5uAMQW8ZNLBzUkuNoHVsAq0H4ChcnvWpRFzdC/M0Iwb5x38BdwOakQ== + + + + + + + + + \RuntimeException + CurlException + \RetailCrm\Exception\CurlException + + + + + + + + No summary was found for this file + No summary for class "" + + eJyzsS/IKODiykvMTS0uSExOVQhKLUnMzHEuyo1xrUhOLSjJzM+z5uJKzkksLlZwLi3KgYsqpFaUpOalFCvEBJXmlWTmpsJluKq5agF9TCAz + + + + + + + + + \DomainException + InvalidJsonException + \RetailCrm\Exception\InvalidJsonException + + + + + + + + No summary was found for this file + No summary for class "" + + eJyzsS/IKODiykvMTS0uSExOVQhKLUnMzHEuyo1xrUhOLSjJzM+z5uJKzkksLlbwzCtLzMlM8SrOz4NLKqRWlKTmpRQrxLjk5yZmIiS4qrlqAUhQInI= + + + + + + + + \RetailCrm\Exception\CurlException + \RetailCrm\Response\ApiResponse + + + Client + \RetailCrm\Http\Client + + HTTP client + + + + + METHOD_GET + \RetailCrm\Http\Client::METHOD_GET + 'GET' + + + + + + + METHOD_POST + \RetailCrm\Http\Client::METHOD_POST + 'POST' + + + + + + + $url + \RetailCrm\Http\Client::url + + + + + + + + $defaultParameters + \RetailCrm\Http\Client::defaultParameters + + + + + + + + __construct + \RetailCrm\Http\Client::__construct() + + + + + + $url + + + + + $defaultParameters + array() + array + + + + makeRequest + \RetailCrm\Http\Client::makeRequest() + + Make HTTP request + + + string + + + string + + + array + + + \RetailCrm\Response\ApiResponse + + + + $path + + string + + + $method + + string + + + $parameters + array() + array + + + $timeout + 30 + + + + + + No summary was found for this file + Argument $url is missing from the Docblock of __construct + Argument $defaultParameters is missing from the Docblock of __construct + No summary for method "" + Argument $path is missing from the Docblock of makeRequest + Argument $timeout is missing from the Docblock of makeRequest + No summary for property $url + No summary for property $defaultParameters + + eJydVm1v2zYQ/u5fcSvSSgq0eMO+xc06z5EXA45lyMqGAgEEhqJiYpKoktTSbNh/71FvlmSnKUoYkMS7e+7tOdLvPxT7YjLJScZUQSiDgGnC04XM7m+0LmaTSan6m95nygrNRX6/KGXafc1GagGiiVyx+3nB23fEmp6fT+AcbsJwCzTlLNf4OZ3QlCgFi3rjvwngomih4dYLb/zr6A8vhCuw8GHNjqVbf1eJzRPllUIhhWZUsxjOMMzZeC9mCSlTvSUS89ZMqtasfEg5haTMqckKoqjyJEuqbQPkApGSPJ8AwAAqke04FVKdhVk8ATshKZbn6uoKEIwXQjVo1h5rrC6nU8txeiZm6b0UT5CzJ7hf5f+QlMdz+VhmWKGu6LY1365A0T3LCEj2qeSSqaq4uypZQUVqObMO9v9J93qm91z9+CsGgYEfStQTncrwVN16wFV3zTqHW/I3q9ts4mJKN4JW/lthIKAqR/7YOC6I3n9VAX3uRQx2E8ZlTQlnbFP3qAPtEjjYDVplLCXTpcyhx9ZGND3JiwzTC+rE7Cpstw2uY0hxghqopXnGRKlx75efxkw5I2kqnlh8WyEd7BRLk8vLwyy4MNgxvO912fDtB55HtW0X1gj8u/imCmyGTuyBoVlWjQpv3qo3wBXkQkOFcQHz2i1kTVJEMnirLPcIo430SMCzIhUxsy2cl+M8BurOC2w/bkaUMfnI7JfI7vZtnNkASu/NKBwG6KLeHHZg3LNq+FsCv3sHiv/LRGL3vYw7Uru6wJPtg4VOzFERPZQ8jSMknny2hxGeSpuaSCnGGPGca7unVW0qpkWBBKZI38VdsPa3YYQPt/b8LdrL+Wrtb7wg8AMXlvP1zutZTadfMfTXa/+vtb+Yhyt/48LPzszoV73FIyPGk4xq9XoAgRfeBZswmG92Sy/ocJpxRrIKIMhEyclDyl6HC1e3nn+HA2ajqdNNaw1qPhSY4SUJFh0HWH1TrrvdOvrTC1bLj1vPxFhdBn1OHfGlvtEOhBkz40VXxtAFvK9Yrw+vWixX3vp6N6b8KULJ5nD8XcTPLbXYZ0YNZs/kTGmiS7XAqW21HpnmeSIOzlebpR+ZGyJa+NfeYMSYlLno4M3HGB83hexpCDnSqAQ0FYo1gkGxaw8vn4CDvzZ27c1t4jpdmYZwxrh3h9i9QrjD6jntzYm/L1gtwjI= + + + + + + + + \RetailCrm\Exception\InvalidJsonException + + + \ArrayAccess + ApiResponse + \RetailCrm\Response\ApiResponse + + Response from retailCRM API + + + + + $statusCode + \RetailCrm\Response\ApiResponse::statusCode + + + + + + + + $response + \RetailCrm\Response\ApiResponse::response + + + + + + + + __construct + \RetailCrm\Response\ApiResponse::__construct() + + + + + + $statusCode + + + + + $responseBody + null + + + + + getStatusCode + \RetailCrm\Response\ApiResponse::getStatusCode() + + Return HTTP response status code + + + integer + + + + + isSuccessful + \RetailCrm\Response\ApiResponse::isSuccessful() + + HTTP request was successful + + + boolean + + + + + __call + \RetailCrm\Response\ApiResponse::__call() + + Allow to access for the property throw class method + + + string + + + mixed + + + + $name + + string + + + $arguments + + + + + + __get + \RetailCrm\Response\ApiResponse::__get() + + Allow to access for the property throw object property + + + string + + + mixed + + + + $name + + string + + + + offsetSet + \RetailCrm\Response\ApiResponse::offsetSet() + + + + + + $offset + + + + + $value + + + + + + offsetUnset + \RetailCrm\Response\ApiResponse::offsetUnset() + + + + + + $offset + + + + + + offsetExists + \RetailCrm\Response\ApiResponse::offsetExists() + + + + + + $offset + + + + + + offsetGet + \RetailCrm\Response\ApiResponse::offsetGet() + + + + + + $offset + + + + + + + No summary was found for this file + Argument $statusCode is missing from the Docblock of __construct + Argument $responseBody is missing from the Docblock of __construct + No summary for method "" + Argument $name is missing from the Docblock of __call + Argument $arguments is missing from the Docblock of __call + Argument $name is missing from the Docblock of __get + Argument $offset is missing from the Docblock of offsetSet + Argument $value is missing from the Docblock of offsetSet + No summary for method "" + Argument $offset is missing from the Docblock of offsetUnset + No summary for method "" + Argument $offset is missing from the Docblock of offsetExists + No summary for method "" + Argument $offset is missing from the Docblock of offsetGet + No summary for method "" + No summary for property $statusCode + No summary for property $response + + eJy1VF1P2zAUfc+vuOsqSFBHmcYbsK2gagOJglr2tKLKTdzWKLEz2wGqif++a+ezadMxqvkpse/HOfeee0+/xIvYcTiJqIqJT2FINWHhhYzGQ7wRXNETx0lU9aH/7NNYM8HHl/yRhCy4UoIXl2jePThw4ADyADCTIgKZ+g+voXd7ic9dxw+JUtCLWWHIojikEeVawbgnJVn2fJ8q5fx2AE+3C9/v7m4xUmauNNGJAl8E1BrEUmjqaxpAO326wBfEkzkXfphW+EBMgrqfLEnbl2QaMh9mCfcNN5hMfHzVMvG1W8nRKR3PRbCEM+BJGHo2RIrdnLZeMPXhc+mGdi7j2tsA1xw2A/cdjWK9dFfCe14lqA1cMDuDB+zFJKCmJqteHUDY1KvEL3KU/nt7cDW6GUz6w+HNcDK4GfTh3RmibFMphczDY9/0xN643hoYc/RCiifg9Ak2KcRdszenlZlaAMA4BqFGKmXbpsjiEPoWieEH71NYrc7GgOnj2hNWoPr7slqPrEeVglYkUfpUPK3YzTGC14nkfxEpFOZfZWqPEsiuuhtFN6d6VOjDrasqC7ImrpMGkBm6XwlVGp6IApXYIZslYQO+qRDhVoBMjYoYr8YHp3B8dNSEsheGqCAtgNjAMMOeG0HgqMZU6mUmsXSFRFQvRFBHHxNJIsD6S8bn0DYrrs4sYs802EoNB56EoWu9ccqJnCd2P9VZ4nrBzfCI0Gy7RERvC6QCVOW/XAc5lwHGRqEhUC2QNZWuSqb4l2f91IGPOGaHsHp97NV3BVOK4l5alfDPlTz3a/Nazmq+znsZyXJgW9e2wjBu2dzjFnChsScJD1pedS4aut6AZcfmi+kDbu3i9j/1f25KapzrLd9Wcv72Uhe62b3YfK3IdXpiNkP8I0Mh/USNI7BkjWwF+jkJUjlc4GSUwPfvMDt2TLNHhugNZmL6SIN97xUYfnBVonhrdjOr/5y5/8yUVk2p8x29uc+pz/1r0nxrprdNSXmGnbWUBtpBTRmSnOrLH9NZDJM= + + + + + + + + + + From de8514fe1402f0b306b33cedc942f87cd2acddf9 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 14:10:48 +0300 Subject: [PATCH 09/10] Removed docs --- composer.json | 3 - docs/ApiIndex.md | 13 - docs/RetailCrm-ApiClient.md | 329 ------- docs/RetailCrm-Exception-CurlException.md | 19 - ...etailCrm-Exception-InvalidJsonException.md | 19 - docs/RetailCrm-Http-Client.md | 110 --- docs/RetailCrm-Response-ApiResponse.md | 205 ----- docs/structure.xml | 812 ------------------ 8 files changed, 1510 deletions(-) delete mode 100644 docs/ApiIndex.md delete mode 100644 docs/RetailCrm-ApiClient.md delete mode 100644 docs/RetailCrm-Exception-CurlException.md delete mode 100644 docs/RetailCrm-Exception-InvalidJsonException.md delete mode 100644 docs/RetailCrm-Http-Client.md delete mode 100644 docs/RetailCrm-Response-ApiResponse.md delete mode 100644 docs/structure.xml diff --git a/composer.json b/composer.json index 7303063..aad1734 100644 --- a/composer.json +++ b/composer.json @@ -14,9 +14,6 @@ "php": ">=5.3.0", "ext-curl": "*" }, - "require-dev" : { - "evert/phpdoc-md": "~0.0.7" - }, "support": { "email": "support@intarocrm.ru" }, diff --git a/docs/ApiIndex.md b/docs/ApiIndex.md deleted file mode 100644 index 37c82b3..0000000 --- a/docs/ApiIndex.md +++ /dev/null @@ -1,13 +0,0 @@ -API Index -========= - -* RetailCrm - * [ApiClient](RetailCrm-ApiClient.md) - * RetailCrm\Exception - * [CurlException](RetailCrm-Exception-CurlException.md) - * [InvalidJsonException](RetailCrm-Exception-InvalidJsonException.md) - * RetailCrm\Http - * [Client](RetailCrm-Http-Client.md) - * RetailCrm\Response - * [ApiResponse](RetailCrm-Response-ApiResponse.md) - diff --git a/docs/RetailCrm-ApiClient.md b/docs/RetailCrm-ApiClient.md deleted file mode 100644 index 7094ddd..0000000 --- a/docs/RetailCrm-ApiClient.md +++ /dev/null @@ -1,329 +0,0 @@ -RetailCrm\ApiClient -=============== - -retailCRM API client class - - - - -* Class name: ApiClient -* Namespace: RetailCrm - - - -Constants ----------- - - -### VERSION - -``` -const VERSION = 'v3' -``` - - - - - -Properties ----------- - - -### $client - -``` -protected mixed $client -``` - - - - - -* Visibility: **protected** - - -Methods -------- - - -### \RetailCrm\ApiClient::__construct() - -``` -void RetailCrm\ApiClient::\RetailCrm\ApiClient::__construct()(string $url, string $apiKey) -``` - -Client creating - - - -* Visibility: **public** - -#### Arguments - -* $url **string** -* $apiKey **string** - - - -### \RetailCrm\ApiClient::ordersCreate() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersCreate()(array $order) -``` - -Create a order - - - -* Visibility: **public** - -#### Arguments - -* $order **array** - - - -### \RetailCrm\ApiClient::ordersEdit() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersEdit()(array $order, $by) -``` - -Edit a order - - - -* Visibility: **public** - -#### Arguments - -* $order **array** -* $by **mixed** - - - -### \RetailCrm\ApiClient::ordersUpload() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersUpload()(array $orders) -``` - -Upload array of the orders - - - -* Visibility: **public** - -#### Arguments - -* $orders **array** - - - -### \RetailCrm\ApiClient::ordersGet() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersGet()(string $id, string $by) -``` - -Get order by id or externalId - - - -* Visibility: **public** - -#### Arguments - -* $id **string** -* $by **string** - <p>(default: 'externalId')</p> - - - -### \RetailCrm\ApiClient::ordersHistory() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersHistory()(\DateTime $startDate, \DateTime $endDate, integer $limit, integer $offset) -``` - -Returns a orders history - - - -* Visibility: **public** - -#### Arguments - -* $startDate **DateTime** - <p>(default: null)</p> -* $endDate **DateTime** - <p>(default: null)</p> -* $limit **integer** - <p>(default: 100)</p> -* $offset **integer** - <p>(default: 0)</p> - - - -### \RetailCrm\ApiClient::ordersList() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersList()(array $filter, integer $page, integer $limit) -``` - -Returns filtered orders list - - - -* Visibility: **public** - -#### Arguments - -* $filter **array** - <p>(default: array())</p> -* $page **integer** - <p>(default: null)</p> -* $limit **integer** - <p>(default: null)</p> - - - -### \RetailCrm\ApiClient::ordersFixExternalIds() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::ordersFixExternalIds()(array $ids) -``` - -Save order IDs' (id and externalId) association in the CRM - - - -* Visibility: **public** - -#### Arguments - -* $ids **array** - - - -### \RetailCrm\ApiClient::customersCreate() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersCreate()(array $customer) -``` - -Create a customer - - - -* Visibility: **public** - -#### Arguments - -* $customer **array** - - - -### \RetailCrm\ApiClient::customersEdit() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersEdit()(array $customer, $by) -``` - -Edit a customer - - - -* Visibility: **public** - -#### Arguments - -* $customer **array** -* $by **mixed** - - - -### \RetailCrm\ApiClient::customersUpload() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersUpload()(array $customers) -``` - -Upload array of the customers - - - -* Visibility: **public** - -#### Arguments - -* $customers **array** - - - -### \RetailCrm\ApiClient::customersGet() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersGet()(string $id, string $by) -``` - -Get customer by id or externalId - - - -* Visibility: **public** - -#### Arguments - -* $id **string** -* $by **string** - <p>(default: 'externalId')</p> - - - -### \RetailCrm\ApiClient::customersList() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersList()(array $filter, integer $page, integer $limit) -``` - -Returns filtered customers list - - - -* Visibility: **public** - -#### Arguments - -* $filter **array** - <p>(default: array())</p> -* $page **integer** - <p>(default: null)</p> -* $limit **integer** - <p>(default: null)</p> - - - -### \RetailCrm\ApiClient::customersFixExternalIds() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\ApiClient::\RetailCrm\ApiClient::customersFixExternalIds()(array $ids) -``` - -Save customer IDs' (id and externalId) association in the CRM - - - -* Visibility: **public** - -#### Arguments - -* $ids **array** - - - -### \RetailCrm\ApiClient::checkIdParameter() - -``` -boolean RetailCrm\ApiClient::\RetailCrm\ApiClient::checkIdParameter()(string $by) -``` - -Check ID parameter - - - -* Visibility: **protected** - -#### Arguments - -* $by **string** - - diff --git a/docs/RetailCrm-Exception-CurlException.md b/docs/RetailCrm-Exception-CurlException.md deleted file mode 100644 index 5bdff30..0000000 --- a/docs/RetailCrm-Exception-CurlException.md +++ /dev/null @@ -1,19 +0,0 @@ -RetailCrm\Exception\CurlException -=============== - - - - - - -* Class name: CurlException -* Namespace: RetailCrm\Exception -* Parent class: RuntimeException - - - - - - - - diff --git a/docs/RetailCrm-Exception-InvalidJsonException.md b/docs/RetailCrm-Exception-InvalidJsonException.md deleted file mode 100644 index cf03b0d..0000000 --- a/docs/RetailCrm-Exception-InvalidJsonException.md +++ /dev/null @@ -1,19 +0,0 @@ -RetailCrm\Exception\InvalidJsonException -=============== - - - - - - -* Class name: InvalidJsonException -* Namespace: RetailCrm\Exception -* Parent class: DomainException - - - - - - - - diff --git a/docs/RetailCrm-Http-Client.md b/docs/RetailCrm-Http-Client.md deleted file mode 100644 index bc70f2c..0000000 --- a/docs/RetailCrm-Http-Client.md +++ /dev/null @@ -1,110 +0,0 @@ -RetailCrm\Http\Client -=============== - -HTTP client - - - - -* Class name: Client -* Namespace: RetailCrm\Http - - - -Constants ----------- - - -### METHOD_GET - -``` -const METHOD_GET = 'GET' -``` - - - - - -### METHOD_POST - -``` -const METHOD_POST = 'POST' -``` - - - - - -Properties ----------- - - -### $url - -``` -protected mixed $url -``` - - - - - -* Visibility: **protected** - - -### $defaultParameters - -``` -protected mixed $defaultParameters -``` - - - - - -* Visibility: **protected** - - -Methods -------- - - -### \RetailCrm\Http\Client::__construct() - -``` -mixed RetailCrm\Http\Client::\RetailCrm\Http\Client::__construct()($url, array $defaultParameters) -``` - - - - - -* Visibility: **public** - -#### Arguments - -* $url **mixed** -* $defaultParameters **array** - - - -### \RetailCrm\Http\Client::makeRequest() - -``` -\RetailCrm\Response\ApiResponse RetailCrm\Http\Client::\RetailCrm\Http\Client::makeRequest()(string $path, string $method, array $parameters, $timeout) -``` - -Make HTTP request - - - -* Visibility: **public** - -#### Arguments - -* $path **string** -* $method **string** - <p>(default: 'GET')</p> -* $parameters **array** - <p>(default: array())</p> -* $timeout **mixed** - - diff --git a/docs/RetailCrm-Response-ApiResponse.md b/docs/RetailCrm-Response-ApiResponse.md deleted file mode 100644 index 24e768f..0000000 --- a/docs/RetailCrm-Response-ApiResponse.md +++ /dev/null @@ -1,205 +0,0 @@ -RetailCrm\Response\ApiResponse -=============== - -Response from retailCRM API - - - - -* Class name: ApiResponse -* Namespace: RetailCrm\Response -* This class implements: ArrayAccess - - - - -Properties ----------- - - -### $statusCode - -``` -protected mixed $statusCode -``` - - - - - -* Visibility: **protected** - - -### $response - -``` -protected mixed $response -``` - - - - - -* Visibility: **protected** - - -Methods -------- - - -### \RetailCrm\Response\ApiResponse::__construct() - -``` -mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::__construct()($statusCode, $responseBody) -``` - - - - - -* Visibility: **public** - -#### Arguments - -* $statusCode **mixed** -* $responseBody **mixed** - - - -### \RetailCrm\Response\ApiResponse::getStatusCode() - -``` -integer RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::getStatusCode()() -``` - -Return HTTP response status code - - - -* Visibility: **public** - - - -### \RetailCrm\Response\ApiResponse::isSuccessful() - -``` -boolean RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::isSuccessful()() -``` - -HTTP request was successful - - - -* Visibility: **public** - - - -### \RetailCrm\Response\ApiResponse::__call() - -``` -mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::__call()(string $name, $arguments) -``` - -Allow to access for the property throw class method - - - -* Visibility: **public** - -#### Arguments - -* $name **string** -* $arguments **mixed** - - - -### \RetailCrm\Response\ApiResponse::__get() - -``` -mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::__get()(string $name) -``` - -Allow to access for the property throw object property - - - -* Visibility: **public** - -#### Arguments - -* $name **string** - - - -### \RetailCrm\Response\ApiResponse::offsetSet() - -``` -mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::offsetSet()($offset, $value) -``` - - - - - -* Visibility: **public** - -#### Arguments - -* $offset **mixed** -* $value **mixed** - - - -### \RetailCrm\Response\ApiResponse::offsetUnset() - -``` -mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::offsetUnset()($offset) -``` - - - - - -* Visibility: **public** - -#### Arguments - -* $offset **mixed** - - - -### \RetailCrm\Response\ApiResponse::offsetExists() - -``` -mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::offsetExists()($offset) -``` - - - - - -* Visibility: **public** - -#### Arguments - -* $offset **mixed** - - - -### \RetailCrm\Response\ApiResponse::offsetGet() - -``` -mixed RetailCrm\Response\ApiResponse::\RetailCrm\Response\ApiResponse::offsetGet()($offset) -``` - - - - - -* Visibility: **public** - -#### Arguments - -* $offset **mixed** - - diff --git a/docs/structure.xml b/docs/structure.xml deleted file mode 100644 index e11e4aa..0000000 --- a/docs/structure.xml +++ /dev/null @@ -1,812 +0,0 @@ - - - - - - - - - - \RetailCrm\Http\Client - \RetailCrm\Response\ApiResponse - - - ApiClient - \RetailCrm\ApiClient - - retailCRM API client class - - - - - VERSION - \RetailCrm\ApiClient::VERSION - 'v3' - - - - - - - $client - \RetailCrm\ApiClient::client - - - - - - - - __construct - \RetailCrm\ApiClient::__construct() - - Client creating - - - string - - - string - - - void - - - - $url - - string - - - $apiKey - - string - - - - ordersCreate - \RetailCrm\ApiClient::ordersCreate() - - Create a order - - - array - - - \RetailCrm\Response\ApiResponse - - - - $order - - array - - - - ordersEdit - \RetailCrm\ApiClient::ordersEdit() - - Edit a order - - - array - - - \RetailCrm\Response\ApiResponse - - - - $order - - array - - - $by - 'externalId' - - - - - ordersUpload - \RetailCrm\ApiClient::ordersUpload() - - Upload array of the orders - - - array - - - \RetailCrm\Response\ApiResponse - - - - $orders - - array - - - - ordersGet - \RetailCrm\ApiClient::ordersGet() - - Get order by id or externalId - - - string - - - string - - - \RetailCrm\Response\ApiResponse - - - - $id - - string - - - $by - 'externalId' - string - - - - ordersHistory - \RetailCrm\ApiClient::ordersHistory() - - Returns a orders history - - - \DateTime - - - \DateTime - - - integer - - - integer - - - \RetailCrm\Response\ApiResponse - - - - $startDate - null - \DateTime - - - $endDate - null - \DateTime - - - $limit - 100 - integer - - - $offset - 0 - integer - - - - ordersList - \RetailCrm\ApiClient::ordersList() - - Returns filtered orders list - - - array - - - integer - - - integer - - - \RetailCrm\Response\ApiResponse - - - - $filter - array() - array - - - $page - null - integer - - - $limit - null - integer - - - - ordersFixExternalIds - \RetailCrm\ApiClient::ordersFixExternalIds() - - Save order IDs' (id and externalId) association in the CRM - - - array - - - \RetailCrm\Response\ApiResponse - - - - $ids - - array - - - - customersCreate - \RetailCrm\ApiClient::customersCreate() - - Create a customer - - - array - - - \RetailCrm\Response\ApiResponse - - - - $customer - - array - - - - customersEdit - \RetailCrm\ApiClient::customersEdit() - - Edit a customer - - - array - - - \RetailCrm\Response\ApiResponse - - - - $customer - - array - - - $by - 'externalId' - - - - - customersUpload - \RetailCrm\ApiClient::customersUpload() - - Upload array of the customers - - - array - - - \RetailCrm\Response\ApiResponse - - - - $customers - - array - - - - customersGet - \RetailCrm\ApiClient::customersGet() - - Get customer by id or externalId - - - string - - - string - - - \RetailCrm\Response\ApiResponse - - - - $id - - string - - - $by - 'externalId' - string - - - - customersList - \RetailCrm\ApiClient::customersList() - - Returns filtered customers list - - - array - - - integer - - - integer - - - \RetailCrm\Response\ApiResponse - - - - $filter - array() - array - - - $page - null - integer - - - $limit - null - integer - - - - customersFixExternalIds - \RetailCrm\ApiClient::customersFixExternalIds() - - Save customer IDs' (id and externalId) association in the CRM - - - array - - - \RetailCrm\Response\ApiResponse - - - - $ids - - array - - - - checkIdParameter - \RetailCrm\ApiClient::checkIdParameter() - - Check ID parameter - - - string - - - boolean - - - - $by - - string - - - - - No summary was found for this file - Argument $url is missing from the Docblock of __construct - Argument $order is missing from the Docblock of ordersCreate - Argument $order is missing from the Docblock of ordersEdit - Argument $by is missing from the Docblock of ordersEdit - Argument $orders is missing from the Docblock of ordersUpload - Argument $id is missing from the Docblock of ordersGet - Argument $startDate is missing from the Docblock of ordersHistory - Argument $filter is missing from the Docblock of ordersList - Argument $ids is missing from the Docblock of ordersFixExternalIds - Argument $customer is missing from the Docblock of customersCreate - Argument $customer is missing from the Docblock of customersEdit - Argument $by is missing from the Docblock of customersEdit - Argument $customers is missing from the Docblock of customersUpload - Argument $id is missing from the Docblock of customersGet - Argument $filter is missing from the Docblock of customersList - Argument $ids is missing from the Docblock of customersFixExternalIds - Argument $by is missing from the Docblock of checkIdParameter - No summary for property $client - - eJztWW1P40YQ/p5fsRdxsoMSAuq30NBS4A7UUlCgJ1XHidvYa9ieY/u8ayCt+O+dfbWdEOPE0UFP9Rdi77w/s7Ozw48/JbdJqxXhCWEJ9ggaEY5peJBOdlutjBXer445T64OQkoivjuzNALmOGLkaj+h5jfw9zc3W2gToVQRjk7R/vkJ8qQI+IMZg+V+S/5CwKqEt/5pIXg8EMLRh6PRxcnZ72iInLsfHJAplpI05sTjxEcbnrZHfpf6xLOJDrSSlGBOoxv92az+nOAUTxBiPIVFtJGl4aIlnNBfydSugitZGqG7mPr6W1+ZlI1D6qEgizxO4whdX0v708zjrhDfNZI6kly5KB4aINfpO+jNELFsDByaHH6FJJIvHdRDO1200+kU+MQjFtEWhKYPkTEfH1ut0vpQkyEHDABFW4iRMBgMdGR3C+T8lrLensZniCJyr+OobcJpiqeuoxxx0HDPOtVR+h/ncRAAEIRRnPokXQCDlGuMKBLaeBfyqjLskpkppa4SqwQ+FfY3jP5N4sDVFLPR5bdpfC+DcHUS3eGQ+vvpTTaBcBw9eCQR+lznXHhAOEnRZynlM5pkkLYAPqR8xMBxH3PsdJ7ERztXintvb4K/kBH5mhHG3XZfedSXiUzaXQ3IYHB6dHl8dnh9fnZxaYApWe9IRgnSXyyOrknkxT5xi9EQz2LkjnzKvzFuQmUJNdg146nY++QBQhzh8MR3XiWSBsJb4n058a0oF8zvFHaYtJUyRrg29SMQfFrJXpZAfeKB65wJORqKosUghaD2W9ZGiTFny5EB7TTOxjZUkYID8NbuEwBvbfnZLdOOdbUZT7s1MvePJIyxr0MSBzIQyvDaecyaJbKyoJTK7Pm8ZetJXDaXufOBaF6QMuni0oCzBYizTh1k3xOuHEBQFqgPv1FeGarPeAWuPbWfXgaprk8CnIV88ETRWTkf3osNT/065axmJVkCKVA8D9P7I4tSYXctjvxI6mPmQGAI9PI4nS4I+tUhnFaXdEKER4zjlIsPheBGWRh2KrlI5NfhgSJoU2wjpBM4tHKOne3taoY4CKAYFzi2GyJ9rMLi5q4U3B9KF7oFP62XZkm7MBSmd619Q2NXIU9sVWewrJCcPWpy1XOdY8790bFUzifRLdrX3l4QpxPMXefP3qTno+MBHcxUjpI27UulLk2jNOmXZfXIEFVqkRRShwtwd3RUFwpUUa6UqEiKItWXFcuoYzan3kbO0xu0YMKzOzOgIdAR32zQECTXOe8UX2EL6Fyq3jgJvmm2NcscK+2138BDc8ZqL+xO6GoT5/ZVrne5vWROaqVo/ipWTBZFo3Jc/V6UesIauPoNlbWVQgVBMf/E+/Ni17FXVsjrBvl8ge90l4JODqFdcOGcx5FfOOg7CDMWexTLXNCd7sHotE62U79ha/eOPhxZS5hJPxBb2d+J9ZWau1PCb2M/b+FnWzuOQoLhSxwRES4gpGnz5i6gDz0T7x7Yvo42T4SgTo9nJwYeeBpP6l0+Z2iXxtbwz4wOzOdKbC1R0+7dCFr7DMF6t8IYwfDOA1oOTjWoepjwIpAWpwrm49KDhZcFeYXxgtGzhgnDgRb1rYYMebrKOUPJk5VGDTVyeO0DB+vEMrm+8tlkBZQnD/ZzrdxuPn+wkipHEJZqLSVt+UFErn9hPtQfRxiO/8xEwrr4MkOJHLi1ziXs7cfK/64vQNbL/+9Ar/AOlBeYhtcgW1xe103I+vd9X4byUtXkPlRx2tS+Eom6Cx7lnlefLFAxZ6Edx3FYxtT+Dz2H9anyPlsmcBjG98R/F6e/TG2hKJ4dXeRQvxh11ZVG14pUtFRlKY2a0xKjjPcHHGa6Jw3gNM6TpT2ethFlKIo5klK30L4yQ7wC5uAMQW8ZNLBzUkuNoHVsAq0H4ChcnvWpRFzdC/M0Iwb5x38BdwOakQ== - - - - - - - - - \RuntimeException - CurlException - \RetailCrm\Exception\CurlException - - - - - - - - No summary was found for this file - No summary for class "" - - eJyzsS/IKODiykvMTS0uSExOVQhKLUnMzHEuyo1xrUhOLSjJzM+z5uJKzkksLlZwLi3KgYsqpFaUpOalFCvEBJXmlWTmpsJluKq5agF9TCAz - - - - - - - - - \DomainException - InvalidJsonException - \RetailCrm\Exception\InvalidJsonException - - - - - - - - No summary was found for this file - No summary for class "" - - eJyzsS/IKODiykvMTS0uSExOVQhKLUnMzHEuyo1xrUhOLSjJzM+z5uJKzkksLlbwzCtLzMlM8SrOz4NLKqRWlKTmpRQrxLjk5yZmIiS4qrlqAUhQInI= - - - - - - - - \RetailCrm\Exception\CurlException - \RetailCrm\Response\ApiResponse - - - Client - \RetailCrm\Http\Client - - HTTP client - - - - - METHOD_GET - \RetailCrm\Http\Client::METHOD_GET - 'GET' - - - - - - - METHOD_POST - \RetailCrm\Http\Client::METHOD_POST - 'POST' - - - - - - - $url - \RetailCrm\Http\Client::url - - - - - - - - $defaultParameters - \RetailCrm\Http\Client::defaultParameters - - - - - - - - __construct - \RetailCrm\Http\Client::__construct() - - - - - - $url - - - - - $defaultParameters - array() - array - - - - makeRequest - \RetailCrm\Http\Client::makeRequest() - - Make HTTP request - - - string - - - string - - - array - - - \RetailCrm\Response\ApiResponse - - - - $path - - string - - - $method - - string - - - $parameters - array() - array - - - $timeout - 30 - - - - - - No summary was found for this file - Argument $url is missing from the Docblock of __construct - Argument $defaultParameters is missing from the Docblock of __construct - No summary for method "" - Argument $path is missing from the Docblock of makeRequest - Argument $timeout is missing from the Docblock of makeRequest - No summary for property $url - No summary for property $defaultParameters - - eJydVm1v2zYQ/u5fcSvSSgq0eMO+xc06z5EXA45lyMqGAgEEhqJiYpKoktTSbNh/71FvlmSnKUoYkMS7e+7tOdLvPxT7YjLJScZUQSiDgGnC04XM7m+0LmaTSan6m95nygrNRX6/KGXafc1GagGiiVyx+3nB23fEmp6fT+AcbsJwCzTlLNf4OZ3QlCgFi3rjvwngomih4dYLb/zr6A8vhCuw8GHNjqVbf1eJzRPllUIhhWZUsxjOMMzZeC9mCSlTvSUS89ZMqtasfEg5haTMqckKoqjyJEuqbQPkApGSPJ8AwAAqke04FVKdhVk8ATshKZbn6uoKEIwXQjVo1h5rrC6nU8txeiZm6b0UT5CzJ7hf5f+QlMdz+VhmWKGu6LY1365A0T3LCEj2qeSSqaq4uypZQUVqObMO9v9J93qm91z9+CsGgYEfStQTncrwVN16wFV3zTqHW/I3q9ts4mJKN4JW/lthIKAqR/7YOC6I3n9VAX3uRQx2E8ZlTQlnbFP3qAPtEjjYDVplLCXTpcyhx9ZGND3JiwzTC+rE7Cpstw2uY0hxghqopXnGRKlx75efxkw5I2kqnlh8WyEd7BRLk8vLwyy4MNgxvO912fDtB55HtW0X1gj8u/imCmyGTuyBoVlWjQpv3qo3wBXkQkOFcQHz2i1kTVJEMnirLPcIo430SMCzIhUxsy2cl+M8BurOC2w/bkaUMfnI7JfI7vZtnNkASu/NKBwG6KLeHHZg3LNq+FsCv3sHiv/LRGL3vYw7Uru6wJPtg4VOzFERPZQ8jSMknny2hxGeSpuaSCnGGPGca7unVW0qpkWBBKZI38VdsPa3YYQPt/b8LdrL+Wrtb7wg8AMXlvP1zutZTadfMfTXa/+vtb+Yhyt/48LPzszoV73FIyPGk4xq9XoAgRfeBZswmG92Sy/ocJpxRrIKIMhEyclDyl6HC1e3nn+HA2ajqdNNaw1qPhSY4SUJFh0HWH1TrrvdOvrTC1bLj1vPxFhdBn1OHfGlvtEOhBkz40VXxtAFvK9Yrw+vWixX3vp6N6b8KULJ5nD8XcTPLbXYZ0YNZs/kTGmiS7XAqW21HpnmeSIOzlebpR+ZGyJa+NfeYMSYlLno4M3HGB83hexpCDnSqAQ0FYo1gkGxaw8vn4CDvzZ27c1t4jpdmYZwxrh3h9i9QrjD6jntzYm/L1gtwjI= - - - - - - - - \RetailCrm\Exception\InvalidJsonException - - - \ArrayAccess - ApiResponse - \RetailCrm\Response\ApiResponse - - Response from retailCRM API - - - - - $statusCode - \RetailCrm\Response\ApiResponse::statusCode - - - - - - - - $response - \RetailCrm\Response\ApiResponse::response - - - - - - - - __construct - \RetailCrm\Response\ApiResponse::__construct() - - - - - - $statusCode - - - - - $responseBody - null - - - - - getStatusCode - \RetailCrm\Response\ApiResponse::getStatusCode() - - Return HTTP response status code - - - integer - - - - - isSuccessful - \RetailCrm\Response\ApiResponse::isSuccessful() - - HTTP request was successful - - - boolean - - - - - __call - \RetailCrm\Response\ApiResponse::__call() - - Allow to access for the property throw class method - - - string - - - mixed - - - - $name - - string - - - $arguments - - - - - - __get - \RetailCrm\Response\ApiResponse::__get() - - Allow to access for the property throw object property - - - string - - - mixed - - - - $name - - string - - - - offsetSet - \RetailCrm\Response\ApiResponse::offsetSet() - - - - - - $offset - - - - - $value - - - - - - offsetUnset - \RetailCrm\Response\ApiResponse::offsetUnset() - - - - - - $offset - - - - - - offsetExists - \RetailCrm\Response\ApiResponse::offsetExists() - - - - - - $offset - - - - - - offsetGet - \RetailCrm\Response\ApiResponse::offsetGet() - - - - - - $offset - - - - - - - No summary was found for this file - Argument $statusCode is missing from the Docblock of __construct - Argument $responseBody is missing from the Docblock of __construct - No summary for method "" - Argument $name is missing from the Docblock of __call - Argument $arguments is missing from the Docblock of __call - Argument $name is missing from the Docblock of __get - Argument $offset is missing from the Docblock of offsetSet - Argument $value is missing from the Docblock of offsetSet - No summary for method "" - Argument $offset is missing from the Docblock of offsetUnset - No summary for method "" - Argument $offset is missing from the Docblock of offsetExists - No summary for method "" - Argument $offset is missing from the Docblock of offsetGet - No summary for method "" - No summary for property $statusCode - No summary for property $response - - eJy1VF1P2zAUfc+vuOsqSFBHmcYbsK2gagOJglr2tKLKTdzWKLEz2wGqif++a+ezadMxqvkpse/HOfeee0+/xIvYcTiJqIqJT2FINWHhhYzGQ7wRXNETx0lU9aH/7NNYM8HHl/yRhCy4UoIXl2jePThw4ADyADCTIgKZ+g+voXd7ic9dxw+JUtCLWWHIojikEeVawbgnJVn2fJ8q5fx2AE+3C9/v7m4xUmauNNGJAl8E1BrEUmjqaxpAO326wBfEkzkXfphW+EBMgrqfLEnbl2QaMh9mCfcNN5hMfHzVMvG1W8nRKR3PRbCEM+BJGHo2RIrdnLZeMPXhc+mGdi7j2tsA1xw2A/cdjWK9dFfCe14lqA1cMDuDB+zFJKCmJqteHUDY1KvEL3KU/nt7cDW6GUz6w+HNcDK4GfTh3RmibFMphczDY9/0xN643hoYc/RCiifg9Ak2KcRdszenlZlaAMA4BqFGKmXbpsjiEPoWieEH71NYrc7GgOnj2hNWoPr7slqPrEeVglYkUfpUPK3YzTGC14nkfxEpFOZfZWqPEsiuuhtFN6d6VOjDrasqC7ImrpMGkBm6XwlVGp6IApXYIZslYQO+qRDhVoBMjYoYr8YHp3B8dNSEsheGqCAtgNjAMMOeG0HgqMZU6mUmsXSFRFQvRFBHHxNJIsD6S8bn0DYrrs4sYs802EoNB56EoWu9ccqJnCd2P9VZ4nrBzfCI0Gy7RERvC6QCVOW/XAc5lwHGRqEhUC2QNZWuSqb4l2f91IGPOGaHsHp97NV3BVOK4l5alfDPlTz3a/Nazmq+znsZyXJgW9e2wjBu2dzjFnChsScJD1pedS4aut6AZcfmi+kDbu3i9j/1f25KapzrLd9Wcv72Uhe62b3YfK3IdXpiNkP8I0Mh/USNI7BkjWwF+jkJUjlc4GSUwPfvMDt2TLNHhugNZmL6SIN97xUYfnBVonhrdjOr/5y5/8yUVk2p8x29uc+pz/1r0nxrprdNSXmGnbWUBtpBTRmSnOrLH9NZDJM= - - - - - - - - - - From ca2b480a264be4a1033aa693419a86470a6fa5f0 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 16:39:55 +0300 Subject: [PATCH 10/10] Added reference and statistic methods --- lib/RetailCrm/ApiClient.php | 260 ++++++++++++++++++ tests/RetailCrm/Tests/ApiClientOrdersTest.php | 4 + .../Tests/ApiClientReferenceTest.php | 98 +++++++ tests/RetailCrm/Tests/ApiClientTest.php | 11 + 4 files changed, 373 insertions(+) create mode 100644 tests/RetailCrm/Tests/ApiClientReferenceTest.php diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index 3671e2f..6316363 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -289,6 +289,266 @@ class ApiClient )); } + /** + * Returns deliveryServices list + * + * @return ApiResponse + */ + public function deliveryServicesList() + { + return $this->client->makeRequest('/reference/delivery-services', Client::METHOD_GET); + } + + /** + * Returns deliveryTypes list + * + * @return ApiResponse + */ + public function deliveryTypesList() + { + return $this->client->makeRequest('/reference/delivery-types', Client::METHOD_GET); + } + + /** + * Returns orderMethods list + * + * @return ApiResponse + */ + public function orderMethodsList() + { + return $this->client->makeRequest('/reference/order-methods', Client::METHOD_GET); + } + + /** + * Returns orderTypes list + * + * @return ApiResponse + */ + public function orderTypesList() + { + return $this->client->makeRequest('/reference/order-types', Client::METHOD_GET); + } + + /** + * Returns paymentStatuses list + * + * @return ApiResponse + */ + public function paymentStatusesList() + { + return $this->client->makeRequest('/reference/payment-statuses', Client::METHOD_GET); + } + + /** + * Returns paymentTypes list + * + * @return ApiResponse + */ + public function paymentTypesList() + { + return $this->client->makeRequest('/reference/payment-types', Client::METHOD_GET); + } + + /** + * Returns productStatuses list + * + * @return ApiResponse + */ + public function productStatusesList() + { + return $this->client->makeRequest('/reference/product-statuses', Client::METHOD_GET); + } + + /** + * Returns statusGroups list + * + * @return ApiResponse + */ + public function statusGroupsList() + { + return $this->client->makeRequest('/reference/status-groups', Client::METHOD_GET); + } + + /** + * Returns statuses list + * + * @return ApiResponse + */ + public function statusesList() + { + return $this->client->makeRequest('/reference/statuses', Client::METHOD_GET); + } + + /** + * Edit deliveryService + * + * @return ApiResponse + */ + public function deliveryServicesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/delivery-services/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'deliveryService' => json_encode($data) + ) + ); + } + + /** + * Edit deliveryType + * + * @return ApiResponse + */ + public function deliveryTypesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/delivery-types/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'deliveryType' => json_encode($data) + ) + ); + } + + /** + * Edit orderMethod + * + * @return ApiResponse + */ + public function orderMethodsEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/order-methods/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'orderMethod' => json_encode($data) + ) + ); + } + + /** + * Edit orderType + * + * @return ApiResponse + */ + public function orderTypesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/order-types/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'orderType' => json_encode($data) + ) + ); + } + + /** + * Edit paymentStatus + * + * @return ApiResponse + */ + public function paymentStatusesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/payment-statuses/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'paymentStatus' => json_encode($data) + ) + ); + } + + /** + * Edit paymentType + * + * @return ApiResponse + */ + public function paymentTypesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/payment-types/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'paymentType' => json_encode($data) + ) + ); + } + + /** + * Edit productStatus + * + * @return ApiResponse + */ + public function productStatusesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/product-statuses/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'productStatus' => json_encode($data) + ) + ); + } + + /** + * Edit order status + * + * @return ApiResponse + */ + public function statusesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/statuses/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'status' => json_encode($data) + ) + ); + } + + /** + * Update CRM basic statistic + * + * @return ApiResponse + */ + public function statisticUpdate() + { + return $this->client->makeRequest('/statistic/update', Client::METHOD_GET); + } + /** * Check ID parameter * diff --git a/tests/RetailCrm/Tests/ApiClientOrdersTest.php b/tests/RetailCrm/Tests/ApiClientOrdersTest.php index 2b50977..315663a 100644 --- a/tests/RetailCrm/Tests/ApiClientOrdersTest.php +++ b/tests/RetailCrm/Tests/ApiClientOrdersTest.php @@ -151,6 +151,10 @@ class ApiClientOrdersTest extends TestCase isset($response['orders']), 'API returns orders history' ); + $this->assertTrue( + isset($response['generatedAt']), + 'API returns generatedAt in orders history' + ); } /** diff --git a/tests/RetailCrm/Tests/ApiClientReferenceTest.php b/tests/RetailCrm/Tests/ApiClientReferenceTest.php new file mode 100644 index 0000000..95d0b72 --- /dev/null +++ b/tests/RetailCrm/Tests/ApiClientReferenceTest.php @@ -0,0 +1,98 @@ +$method(); + + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue($response->isSuccessful()); + $this->assertTrue(isset($response[$name])); + $this->assertTrue(is_array($response[$name])); + } + + /** + * @group integration + * @dataProvider getEditDictionaries + * @expectedException \InvalidArgumentException + */ + public function testEditingException($name) + { + $client = static::getApiClient(); + + $method = $name . 'Edit'; + $response = $client->$method(array()); + } + + /** + * @group integration + * @dataProvider getEditDictionaries + */ + public function testEditing($name) + { + $client = static::getApiClient(); + + $code = 'dict-' . strtolower($name) . '-' . time(); + $method = $name . 'Edit'; + $params = array( + 'code' => $code, + 'name' => 'Aaa', + ); + if ($name == 'statuses') { + $params['group'] = 'new'; + } + + $response = $client->$method($params); + $this->assertEquals(201, $response->getStatusCode()); + + $response = $client->$method(array( + 'code' => $code, + 'name' => 'Bbb', + )); + if ($response->getStatusCode() > 201) { + print_r($response); + } + $this->assertEquals(200, $response->getStatusCode()); + } + + public function getListDictionaries() + { + return array( + array('deliveryServices'), + array('deliveryTypes'), + array('orderMethods'), + array('orderTypes'), + array('paymentStatuses'), + array('paymentTypes'), + array('productStatuses'), + array('statusGroups'), + array('statuses'), + ); + } + + public function getEditDictionaries() + { + return array( + array('deliveryServices'), + array('deliveryTypes'), + array('orderMethods'), + array('orderTypes'), + array('paymentStatuses'), + array('paymentTypes'), + array('productStatuses'), + array('statuses'), + ); + } +} diff --git a/tests/RetailCrm/Tests/ApiClientTest.php b/tests/RetailCrm/Tests/ApiClientTest.php index fe78cc1..38b535c 100644 --- a/tests/RetailCrm/Tests/ApiClientTest.php +++ b/tests/RetailCrm/Tests/ApiClientTest.php @@ -15,4 +15,15 @@ class ApiClientTest extends TestCase $this->assertInstanceOf('RetailCrm\ApiClient', $client); } + + /** + * @group integration + */ + public function testStatisticUpdate() + { + $client = static::getApiClient(); + + $response = $client->statisticUpdate(); + $this->assertTrue($response->isSuccessful()); + } }