1
0
mirror of synced 2024-11-25 06:46:07 +03:00

Method customersUpload added

This commit is contained in:
Kruglov Kirill 2013-07-26 16:24:49 +04:00
parent a492d61eaa
commit a647993272

View File

@ -6,7 +6,8 @@ class RestApi
protected $apiUrl; protected $apiUrl;
protected $apiKey; protected $apiKey;
protected $apiVersion = '1'; protected $apiVersion = '1';
protected $lastError;
protected $response;
protected $statusCode; protected $statusCode;
protected $parameters; protected $parameters;
@ -30,16 +31,23 @@ class RestApi
/* Получение кода статуса и сообщения об ошибке */ /* Получение кода статуса и сообщения об ошибке */
public function getLastError() public function getLastError()
{ {
if (!is_null($this->lastError)) if (isset($this->response['errorMsg']) && isset($this->response['errors']))
return $this->statusCode . ' ' . $this->lastError; {
$result = $this->statusCode . ' ' . $this->response['errorMsg'];
foreach ($this->response['errors'] as $error)
$result .= ' ' . $error;
}
elseif (isset($this->response['errorMsg']))
$result = $this->statusCode . ' ' . $this->response['errorMsg'];
else else
return null; $result = null;
return $result;
} }
/* Псообщения об ошибке */ /* Псообщения об ошибке */
public function getLastErrorMessage() public function getLastErrorMessage()
{ {
return $this->lastError; return $this->response['errorMsg'];
} }
@ -94,7 +102,7 @@ class RestApi
} }
/** /**
* Загрузка нескольких заказов * Пакетная загрузка заказов
* *
* @param array $orders - массив заказов * @param array $orders - массив заказов
* @return array * @return array
@ -106,6 +114,8 @@ class RestApi
$url = $this->apiUrl.'orders/upload'; $url = $this->apiUrl.'orders/upload';
$result = $this->curlRequest($url, 'POST'); $result = $this->curlRequest($url, 'POST');
if (is_null($result) && isset($result['uploadedOrders']))
return $result['uploadedOrders'];
return $result; return $result;
} }
@ -213,6 +223,26 @@ class RestApi
return $result; return $result;
} }
/**
* Пакетная загрузка клиентов
*
* @param array $customers - массив клиентов
* @return array
*/
public function customerUpload($customers)
{
$dataJson = json_encode($customers);
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
$dataJson);
$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;
}
/** /**
* Удаление клиента * Удаление клиента
* *
@ -442,19 +472,16 @@ class RestApi
if (curl_errno($ch)) if (curl_errno($ch))
{ {
$this->lastError = 'Curl error: ' . curl_error($ch); $this->response = array('errorMsg' => 'Curl error: ' . curl_error($ch));
return null; return null;
} }
curl_close($ch); curl_close($ch);
$result = (array)json_decode($response, true); $result = (array)json_decode($response, true);
$this->response = $result;
if ($result['success'] == false) if ($result['success'] == false)
{
$this->lastError = $result['errorMsg'];
return null; return null;
}
$this->lastError = null;
unset($result['success']); unset($result['success']);
if (count($result) == 0) if (count($result) == 0)
return true; return true;