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

added availlableVersions() and credentials()

This commit is contained in:
Alexander Kulinich 2017-09-27 16:59:56 +03:00
parent 95c24bed4a
commit ada3de8770
3 changed files with 91 additions and 2 deletions

32
lib/RetailCrm/Client/AbstractLoader.php Normal file → Executable file
View File

@ -31,6 +31,7 @@ abstract class AbstractLoader
{
protected $siteCode;
protected $client;
protected $crmUrl;
/**
* Init version based client
@ -45,6 +46,7 @@ abstract class AbstractLoader
if ('/' !== $url[strlen($url) - 1]) {
$url .= '/';
}
$this->crmUrl = $url;
if (empty($version) || !in_array($version, ['v3', 'v4', 'v5'])) {
throw new \InvalidArgumentException(
@ -128,5 +130,33 @@ abstract class AbstractLoader
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
View File

@ -63,6 +63,7 @@ class Client
* @param string $path request url
* @param string $method (default: 'GET')
* @param array $parameters (default: array())
* @param bool $fullPath (default: false)
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
@ -75,7 +76,8 @@ class Client
public function makeRequest(
$path,
$method,
array $parameters = []
array $parameters = [],
$fullPath = false
) {
$allowedMethods = [self::METHOD_GET, self::METHOD_POST];
@ -91,7 +93,7 @@ class Client
$parameters = array_merge($this->defaultParameters, $parameters);
$url = $this->url . $path;
$url = $fullPath ? $path : $this->url . $path;
if (self::METHOD_GET === $method && count($parameters)) {
$url .= '?' . http_build_query($parameters, '', '&');

View 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()));
}
}