From ada3de8770e21f7d624d22f30ca9c076ba4183bf Mon Sep 17 00:00:00 2001 From: Alexander Kulinich Date: Wed, 27 Sep 2017 16:59:56 +0300 Subject: [PATCH] added availlableVersions() and credentials() --- lib/RetailCrm/Client/AbstractLoader.php | 30 ++++++++++ lib/RetailCrm/Http/Client.php | 6 +- .../Tests/Methods/CommonMethodsTest.php | 57 +++++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) mode change 100644 => 100755 lib/RetailCrm/Client/AbstractLoader.php mode change 100644 => 100755 lib/RetailCrm/Http/Client.php create mode 100755 tests/RetailCrm/Tests/Methods/CommonMethodsTest.php diff --git a/lib/RetailCrm/Client/AbstractLoader.php b/lib/RetailCrm/Client/AbstractLoader.php old mode 100644 new mode 100755 index 08613cd..98592b8 --- a/lib/RetailCrm/Client/AbstractLoader.php +++ b/lib/RetailCrm/Client/AbstractLoader.php @@ -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 + ); + } } diff --git a/lib/RetailCrm/Http/Client.php b/lib/RetailCrm/Http/Client.php old mode 100644 new mode 100755 index 13cf46e..5939c51 --- a/lib/RetailCrm/Http/Client.php +++ b/lib/RetailCrm/Http/Client.php @@ -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, '', '&'); diff --git a/tests/RetailCrm/Tests/Methods/CommonMethodsTest.php b/tests/RetailCrm/Tests/Methods/CommonMethodsTest.php new file mode 100755 index 0000000..4248cbc --- /dev/null +++ b/tests/RetailCrm/Tests/Methods/CommonMethodsTest.php @@ -0,0 +1,57 @@ + + * @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 + * @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())); + } +}