From 838b850d489637bcc10b317e3105e3b3ab0c5e91 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Sun, 10 Apr 2016 00:46:08 +0300 Subject: [PATCH] telephony setting method, test & psr compability comments --- lib/RetailCrm/ApiClient.php | 85 ++++++++++++++++++- lib/RetailCrm/Exception/CurlException.php | 12 +++ .../Exception/InvalidJsonException.php | 12 +++ lib/RetailCrm/Http/Client.php | 17 +++- lib/RetailCrm/Response/ApiResponse.php | 38 +++++++-- .../Tests/ApiClientTelephonyTest.php | 42 +++++++++ 6 files changed, 193 insertions(+), 13 deletions(-) create mode 100644 tests/RetailCrm/Tests/ApiClientTelephonyTest.php diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index 1adfe30..de8ea4c 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -1,5 +1,17 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + */ + namespace RetailCrm; use RetailCrm\Http\Client; @@ -665,9 +677,9 @@ class ApiClient /** * Get purchace prices & stock balance * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) * * @throws \InvalidArgumentException * @throws \RetailCrm\Exception\CurlException @@ -1196,6 +1208,71 @@ class ApiClient ); } + /** + * Telephony settings + * + * @param string $code symbolic code + * @param string $clientId client id + * @param boolean $active telephony activity + * @param mixed $makeCallUrl service init url + * @param mixed $name service name + * @param mixed $image service logo url(svg file) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function telephonySettings( + $code, + $clientId, + $active = false, + $makeCallUrl = false, + $name = false, + $image = false + ) { + if (!isset($code)) { + throw new \InvalidArgumentException('Code must be set'); + } + + $parameters['code'] = $code; + + if (!isset($clientId)) { + throw new \InvalidArgumentException('client id must be set'); + } + + $parameters['clientId'] = $clientId; + + if (!isset($active)) { + $parameters['active'] = false; + } else { + $parameters['active'] = $active; + } + + if (!isset($name)) { + throw new \InvalidArgumentException('name must be set'); + } + + if (isset($makeCallUrl)) { + $parameters['makeCallUrl'] = $makeCallUrl; + } + + if (isset($name)) { + $parameters['name'] = $name; + } + + if (isset($image)) { + $parameters['image'] = $image; + } + + return $this->client->makeRequest( + "/telephony/setting/$code", + Client::METHOD_POST, + $parameters + ); + } + /** * Update CRM basic statistic * @@ -1350,7 +1427,7 @@ class ApiClient if (!in_array($by, $allowedForBy, false)) { throw new \InvalidArgumentException( sprintf( - 'Value "%s" for parameter "by" is not valid. Allowed values are %s.', + 'Value "%s" for "by" param is not valid. Allowed values are %s.', $by, implode(', ', $allowedForBy) ) diff --git a/lib/RetailCrm/Exception/CurlException.php b/lib/RetailCrm/Exception/CurlException.php index d3b8e1a..827db72 100644 --- a/lib/RetailCrm/Exception/CurlException.php +++ b/lib/RetailCrm/Exception/CurlException.php @@ -1,5 +1,17 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + */ + namespace RetailCrm\Exception; /** diff --git a/lib/RetailCrm/Exception/InvalidJsonException.php b/lib/RetailCrm/Exception/InvalidJsonException.php index 1a06536..166304d 100644 --- a/lib/RetailCrm/Exception/InvalidJsonException.php +++ b/lib/RetailCrm/Exception/InvalidJsonException.php @@ -1,5 +1,17 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + */ + namespace RetailCrm\Exception; /** diff --git a/lib/RetailCrm/Http/Client.php b/lib/RetailCrm/Http/Client.php index eafb079..4e16190 100644 --- a/lib/RetailCrm/Http/Client.php +++ b/lib/RetailCrm/Http/Client.php @@ -1,5 +1,17 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + */ + namespace RetailCrm\Http; use RetailCrm\Exception\CurlException; @@ -119,7 +131,10 @@ class Client curl_close($curlHandler); - if ($errno && in_array($errno, $this->curlErrors, false) && $this->retry < 3) { + if ($errno + && in_array($errno, $this->curlErrors, false) + && $this->retry < 3 + ) { $errno = null; $error = null; ++$this->retry; diff --git a/lib/RetailCrm/Response/ApiResponse.php b/lib/RetailCrm/Response/ApiResponse.php index 8d97cd7..70c145a 100644 --- a/lib/RetailCrm/Response/ApiResponse.php +++ b/lib/RetailCrm/Response/ApiResponse.php @@ -1,5 +1,17 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + */ + namespace RetailCrm\Response; use RetailCrm\Exception\InvalidJsonException; @@ -72,8 +84,8 @@ class ApiResponse implements \ArrayAccess /** * Allow to access for the property throw class method * - * @param string $name - * @param $arguments + * @param string $name method name + * @param mixed $arguments method parameters * * @throws \InvalidArgumentException * @@ -94,7 +106,7 @@ class ApiResponse implements \ArrayAccess /** * Allow to access for the property throw object property * - * @param string $name + * @param string $name property name * * @throws \InvalidArgumentException * @@ -110,10 +122,13 @@ class ApiResponse implements \ArrayAccess } /** - * @param mixed $offset - * @param mixed $value + * Offset set + * + * @param mixed $offset offset + * @param mixed $value value * * @throws \BadMethodCallException + * @return void */ public function offsetSet($offset, $value) { @@ -121,9 +136,12 @@ class ApiResponse implements \ArrayAccess } /** - * @param mixed $offset + * Offset unset + * + * @param mixed $offset offset * * @throws \BadMethodCallException + * @return void */ public function offsetUnset($offset) { @@ -131,7 +149,9 @@ class ApiResponse implements \ArrayAccess } /** - * @param mixed $offset + * Check offset + * + * @param mixed $offset offset * * @return bool */ @@ -141,7 +161,9 @@ class ApiResponse implements \ArrayAccess } /** - * @param mixed $offset + * Get offset + * + * @param mixed $offset offset * * @throws \InvalidArgumentException * diff --git a/tests/RetailCrm/Tests/ApiClientTelephonyTest.php b/tests/RetailCrm/Tests/ApiClientTelephonyTest.php new file mode 100644 index 0000000..2fc875b --- /dev/null +++ b/tests/RetailCrm/Tests/ApiClientTelephonyTest.php @@ -0,0 +1,42 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + */ +class ApiClientTelephonyTest extends TestCase +{ + /** + * Settings test + * + * @group integration + * + * @return void + */ + public function testTelephonySettings() + { + $client = static::getApiClient(); + + $code = 'telphin'; + $clientId = '1'; + $active = true; + + $response = $client->telephonySettings( + $code, + $clientId, + $active + ); + + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + } +}