1
0
mirror of synced 2024-11-28 16:26:06 +03:00

Merge pull request #13 from gwinn/master

telephony setting method, test & psr compability comments
This commit is contained in:
Alex Lushpai 2016-04-10 01:47:19 +04:00
commit 4606062af8
6 changed files with 193 additions and 13 deletions

View File

@ -1,5 +1,17 @@
<?php
/**
* PHP version 5.3
*
* API client class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @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)
)

View File

@ -1,5 +1,17 @@
<?php
/**
* PHP version 5.3
*
* Class CurlException
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/
namespace RetailCrm\Exception;
/**

View File

@ -1,5 +1,17 @@
<?php
/**
* PHP version 5.3
*
* Class InvalidJsonException
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/
namespace RetailCrm\Exception;
/**

View File

@ -1,5 +1,17 @@
<?php
/**
* PHP version 5.3
*
* HTTP client
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @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;

View File

@ -1,5 +1,17 @@
<?php
/**
* PHP version 5.3
*
* Response from retailCRM API
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @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
*

View File

@ -0,0 +1,42 @@
<?php
namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientTelephonyTest
* @category RetailCrm
* @package RetailCrm\Tests
* @author RetailCrm <integration@retailcrm.ru>
* @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);
}
}