added availlableVersions() and credentials()
This commit is contained in:
parent
95c24bed4a
commit
ada3de8770
30
lib/RetailCrm/Client/AbstractLoader.php
Normal file → Executable file
30
lib/RetailCrm/Client/AbstractLoader.php
Normal file → Executable file
@ -31,6 +31,7 @@ abstract class AbstractLoader
|
|||||||
{
|
{
|
||||||
protected $siteCode;
|
protected $siteCode;
|
||||||
protected $client;
|
protected $client;
|
||||||
|
protected $crmUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init version based client
|
* Init version based client
|
||||||
@ -45,6 +46,7 @@ abstract class AbstractLoader
|
|||||||
if ('/' !== $url[strlen($url) - 1]) {
|
if ('/' !== $url[strlen($url) - 1]) {
|
||||||
$url .= '/';
|
$url .= '/';
|
||||||
}
|
}
|
||||||
|
$this->crmUrl = $url;
|
||||||
|
|
||||||
if (empty($version) || !in_array($version, ['v3', 'v4', 'v5'])) {
|
if (empty($version) || !in_array($version, ['v3', 'v4', 'v5'])) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
@ -128,5 +130,33 @@ abstract class AbstractLoader
|
|||||||
return $this->siteCode;
|
return $this->siteCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting the list of available api versions
|
||||||
|
*
|
||||||
|
* @return \RetailCrm\Response\ApiResponse
|
||||||
|
*/
|
||||||
|
public function availableVersions()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
$this->crmUrl . 'api/api-versions',
|
||||||
|
"GET",
|
||||||
|
[],
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting the list of available api methods and stores for current key
|
||||||
|
*
|
||||||
|
* @return \RetailCrm\Response\ApiResponse
|
||||||
|
*/
|
||||||
|
public function credentials()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
$this->crmUrl . 'api/credentials',
|
||||||
|
"GET",
|
||||||
|
[],
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
6
lib/RetailCrm/Http/Client.php
Normal file → Executable file
6
lib/RetailCrm/Http/Client.php
Normal file → Executable file
@ -63,6 +63,7 @@ class Client
|
|||||||
* @param string $path request url
|
* @param string $path request url
|
||||||
* @param string $method (default: 'GET')
|
* @param string $method (default: 'GET')
|
||||||
* @param array $parameters (default: array())
|
* @param array $parameters (default: array())
|
||||||
|
* @param bool $fullPath (default: false)
|
||||||
*
|
*
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||||
*
|
*
|
||||||
@ -75,7 +76,8 @@ class Client
|
|||||||
public function makeRequest(
|
public function makeRequest(
|
||||||
$path,
|
$path,
|
||||||
$method,
|
$method,
|
||||||
array $parameters = []
|
array $parameters = [],
|
||||||
|
$fullPath = false
|
||||||
) {
|
) {
|
||||||
$allowedMethods = [self::METHOD_GET, self::METHOD_POST];
|
$allowedMethods = [self::METHOD_GET, self::METHOD_POST];
|
||||||
|
|
||||||
@ -91,7 +93,7 @@ class Client
|
|||||||
|
|
||||||
$parameters = array_merge($this->defaultParameters, $parameters);
|
$parameters = array_merge($this->defaultParameters, $parameters);
|
||||||
|
|
||||||
$url = $this->url . $path;
|
$url = $fullPath ? $path : $this->url . $path;
|
||||||
|
|
||||||
if (self::METHOD_GET === $method && count($parameters)) {
|
if (self::METHOD_GET === $method && count($parameters)) {
|
||||||
$url .= '?' . http_build_query($parameters, '', '&');
|
$url .= '?' . http_build_query($parameters, '', '&');
|
||||||
|
57
tests/RetailCrm/Tests/Methods/CommonMethodsTest.php
Executable file
57
tests/RetailCrm/Tests/Methods/CommonMethodsTest.php
Executable file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 5.4
|
||||||
|
*
|
||||||
|
* API client customers test 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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests\Methods;
|
||||||
|
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CommonMethodsTest
|
||||||
|
*
|
||||||
|
* @category RetailCrm
|
||||||
|
* @package RetailCrm
|
||||||
|
* @author RetailCrm <integration@retailcrm.ru>
|
||||||
|
* @license https://opensource.org/licenses/MIT MIT License
|
||||||
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||||
|
*/
|
||||||
|
class CommonMethodsTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @group api_methods
|
||||||
|
*/
|
||||||
|
public function testAvailableVersions()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->request->availableVersions();
|
||||||
|
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->getSuccess());
|
||||||
|
static::assertGreaterThan(0, count($response->getVersions()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group api_methods
|
||||||
|
*/
|
||||||
|
public function testCredentials()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->request->credentials();
|
||||||
|
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->getSuccess());
|
||||||
|
static::assertGreaterThan(0, count($response->getCredentials()));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user