1
0
Fork 0
mirror of synced 2025-04-10 04:21:01 +00:00

add request model (except ws and files), move serializer & url handling into separate namespace

This commit is contained in:
Alex Lushpai 2019-04-08 01:17:20 +03:00
parent 3e4e08d2cc
commit 9e9e2c40fa
18 changed files with 1986 additions and 263 deletions

553
composer.lock generated
View file

@ -2156,6 +2156,200 @@
}
],
"packages-dev": [
{
"name": "composer/semver",
"version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/composer/semver.git",
"reference": "46d9139568ccb8d9e7cdd4539cab7347568a5e2e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/semver/zipball/46d9139568ccb8d9e7cdd4539cab7347568a5e2e",
"reference": "46d9139568ccb8d9e7cdd4539cab7347568a5e2e",
"shasum": ""
},
"require": {
"php": "^5.3.2 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.5 || ^5.0.5",
"phpunit/phpunit-mock-objects": "2.3.0 || ^3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Composer\\Semver\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nils Adermann",
"email": "naderman@naderman.de",
"homepage": "http://www.naderman.de"
},
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
},
{
"name": "Rob Bast",
"email": "rob.bast@gmail.com",
"homepage": "http://robbast.nl"
}
],
"description": "Semver library that offers utilities, version constraint parsing and validation.",
"keywords": [
"semantic",
"semver",
"validation",
"versioning"
],
"time": "2019-03-19T17:25:45+00:00"
},
{
"name": "composer/xdebug-handler",
"version": "1.3.2",
"source": {
"type": "git",
"url": "https://github.com/composer/xdebug-handler.git",
"reference": "d17708133b6c276d6e42ef887a877866b909d892"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/xdebug-handler/zipball/d17708133b6c276d6e42ef887a877866b909d892",
"reference": "d17708133b6c276d6e42ef887a877866b909d892",
"shasum": ""
},
"require": {
"php": "^5.3.2 || ^7.0",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5"
},
"type": "library",
"autoload": {
"psr-4": {
"Composer\\XdebugHandler\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "John Stevenson",
"email": "john-stevenson@blueyonder.co.uk"
}
],
"description": "Restarts a process without xdebug.",
"keywords": [
"Xdebug",
"performance"
],
"time": "2019-01-28T20:25:53+00:00"
},
{
"name": "friendsofphp/php-cs-fixer",
"version": "v2.14.2",
"source": {
"type": "git",
"url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git",
"reference": "ff401e58261ffc5934a58f795b3f95b355e276cb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/ff401e58261ffc5934a58f795b3f95b355e276cb",
"reference": "ff401e58261ffc5934a58f795b3f95b355e276cb",
"shasum": ""
},
"require": {
"composer/semver": "^1.4",
"composer/xdebug-handler": "^1.2",
"doctrine/annotations": "^1.2",
"ext-json": "*",
"ext-tokenizer": "*",
"php": "^5.6 || ^7.0",
"php-cs-fixer/diff": "^1.3",
"symfony/console": "^3.4.17 || ^4.1.6",
"symfony/event-dispatcher": "^3.0 || ^4.0",
"symfony/filesystem": "^3.0 || ^4.0",
"symfony/finder": "^3.0 || ^4.0",
"symfony/options-resolver": "^3.0 || ^4.0",
"symfony/polyfill-php70": "^1.0",
"symfony/polyfill-php72": "^1.4",
"symfony/process": "^3.0 || ^4.0",
"symfony/stopwatch": "^3.0 || ^4.0"
},
"require-dev": {
"johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0",
"justinrainbow/json-schema": "^5.0",
"keradus/cli-executor": "^1.2",
"mikey179/vfsstream": "^1.6",
"php-coveralls/php-coveralls": "^2.1",
"php-cs-fixer/accessible-object": "^1.0",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.0.1",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.0.1",
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1",
"phpunitgoodpractices/traits": "^1.5.1",
"symfony/phpunit-bridge": "^4.0"
},
"suggest": {
"ext-mbstring": "For handling non-UTF8 characters in cache signature.",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "For IsIdenticalString constraint.",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "For XmlMatchesXsd constraint.",
"symfony/polyfill-mbstring": "When enabling `ext-mbstring` is not possible."
},
"bin": [
"php-cs-fixer"
],
"type": "application",
"autoload": {
"psr-4": {
"PhpCsFixer\\": "src/"
},
"classmap": [
"tests/Test/AbstractFixerTestCase.php",
"tests/Test/AbstractIntegrationCaseFactory.php",
"tests/Test/AbstractIntegrationTestCase.php",
"tests/Test/Assert/AssertTokensTrait.php",
"tests/Test/IntegrationCase.php",
"tests/Test/IntegrationCaseFactory.php",
"tests/Test/IntegrationCaseFactoryInterface.php",
"tests/Test/InternalIntegrationCaseFactory.php",
"tests/TestCase.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Dariusz Rumiński",
"email": "dariusz.ruminski@gmail.com"
},
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"description": "A tool to automatically fix PHP code style",
"time": "2019-02-17T17:44:13+00:00"
},
{
"name": "jean85/pretty-package-versions",
"version": "1.2",
@ -2920,6 +3114,51 @@
],
"time": "2018-07-02T15:55:56+00:00"
},
{
"name": "paragonie/random_compat",
"version": "v9.99.99",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95",
"reference": "84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95",
"shasum": ""
},
"require": {
"php": "^7"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*",
"vimeo/psalm": "^1"
},
"suggest": {
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
"keywords": [
"csprng",
"polyfill",
"pseudorandom",
"random"
],
"time": "2018-07-02T15:55:56+00:00"
},
{
"name": "pdepend/pdepend",
"version": "2.5.2",
@ -3942,6 +4181,53 @@
],
"time": "2018-11-20T15:27:04+00:00"
},
{
"name": "psr/log",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"time": "2018-11-20T15:27:04+00:00"
},
{
"name": "sebastian/code-unit-reverse-lookup",
"version": "1.0.1",
@ -5124,6 +5410,273 @@
"homepage": "https://symfony.com",
"time": "2019-01-16T09:39:14+00:00"
},
{
"name": "symfony/options-resolver",
"version": "v4.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/options-resolver.git",
"reference": "3896e5a7d06fd15fa4947694c8dcdd371ff147d1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/3896e5a7d06fd15fa4947694c8dcdd371ff147d1",
"reference": "3896e5a7d06fd15fa4947694c8dcdd371ff147d1",
"shasum": ""
},
"require": {
"php": "^7.1.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\OptionsResolver\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony OptionsResolver Component",
"homepage": "https://symfony.com",
"keywords": [
"config",
"configuration",
"options"
],
"time": "2019-02-23T15:17:42+00:00"
},
{
"name": "symfony/polyfill-php70",
"version": "v1.11.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php70.git",
"reference": "bc4858fb611bda58719124ca079baff854149c89"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/bc4858fb611bda58719124ca079baff854149c89",
"reference": "bc4858fb611bda58719124ca079baff854149c89",
"shasum": ""
},
"require": {
"paragonie/random_compat": "~1.0|~2.0|~9.99",
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.11-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Php70\\": ""
},
"files": [
"bootstrap.php"
],
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"time": "2019-02-06T07:57:58+00:00"
},
{
"name": "symfony/polyfill-php72",
"version": "v1.11.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php72.git",
"reference": "ab50dcf166d5f577978419edd37aa2bb8eabce0c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/ab50dcf166d5f577978419edd37aa2bb8eabce0c",
"reference": "ab50dcf166d5f577978419edd37aa2bb8eabce0c",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.11-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Php72\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"time": "2019-02-06T07:57:58+00:00"
},
{
"name": "symfony/process",
"version": "v4.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "1e6cbb41dadcaf29e0db034d6ad0d039a9df06e6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/1e6cbb41dadcaf29e0db034d6ad0d039a9df06e6",
"reference": "1e6cbb41dadcaf29e0db034d6ad0d039a9df06e6",
"shasum": ""
},
"require": {
"php": "^7.1.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Process\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
"time": "2019-03-10T20:07:02+00:00"
},
{
"name": "symfony/stopwatch",
"version": "v4.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/stopwatch.git",
"reference": "b1a5f646d56a3290230dbc8edf2a0d62cda23f67"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/b1a5f646d56a3290230dbc8edf2a0d62cda23f67",
"reference": "b1a5f646d56a3290230dbc8edf2a0d62cda23f67",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"symfony/contracts": "^1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Stopwatch\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Stopwatch Component",
"homepage": "https://symfony.com",
"time": "2019-01-16T20:31:39+00:00"
},
{
"name": "theseer/tokenizer",
"version": "1.1.3",

View file

@ -17,10 +17,16 @@ use Psr\Http\Message\ResponseInterface;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Common\Url;
use RetailCrm\Common\Serializer;
<<<<<<< HEAD
use RetailCrm\Mg\Bot\Model\Request\UploadFileByUrlRequest;
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
use RetailCrm\Mg\Bot\Model\Response\ListResponse;
use RetailCrm\Mg\Bot\Model\Response\UploadFileResponse;
=======
use RetailCrm\Mg\Bot\Model;
use Exception;
use InvalidArgumentException;
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
/**
* PHP version 7.0
@ -60,7 +66,11 @@ class Client
public function __construct($url, $token, $debug = false, $handler = null)
{
$url = sprintf("%sapi/bot/%s", Url::normalizeUrl($url), self::VERSION);
<<<<<<< HEAD
$this->client = new HttpClient($url, $token, $debug ? STDOUT : null, $handler);
=======
$this->client = new Request($url, $token, $debug);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
@ -165,6 +175,7 @@ class Client
*/
public function bots(Model\Request\BotsRequest $request)
{
<<<<<<< HEAD
return $this->submitRequest(
'/bots',
HttpClient::METHOD_GET,
@ -172,11 +183,15 @@ class Client
static::getEntityClass('Bot'),
true
);
=======
return $this->client->makeRequest('/bots', Request::METHOD_GET, $request, Serializer::S_ARRAY);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
* Edit bot info
*
<<<<<<< HEAD
* @param Model\Request\InfoRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
@ -190,6 +205,20 @@ class Client
$request,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
);
=======
* @param Model\Request\InfoRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws CurlException
* @throws Exception
*
* @return Response
*/
public function info(Model\Request\InfoRequest $request)
{
return $this->client->makeRequest('/my/info', Request::METHOD_PATCH, $request);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
@ -202,6 +231,7 @@ class Client
*/
public function channels(Model\Request\ChannelsRequest $request)
{
<<<<<<< HEAD
return $this->submitRequest(
'/channels',
HttpClient::METHOD_GET,
@ -209,6 +239,9 @@ class Client
static::getEntityClass('Channel', 'Channel'),
true
);
=======
return $this->client->makeRequest('/channels', Request::METHOD_GET, $request, Serializer::S_ARRAY);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
@ -221,6 +254,7 @@ class Client
*/
public function chats(Model\Request\ChatsRequest $request)
{
<<<<<<< HEAD
return $this->submitRequest(
'/chats',
HttpClient::METHOD_GET,
@ -228,6 +262,9 @@ class Client
static::getEntityClass('Chat', 'Chat'),
true
);
=======
return $this->client->makeRequest('/chats', Request::METHOD_GET, $request, Serializer::S_ARRAY);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
@ -240,6 +277,7 @@ class Client
*/
public function commands(Model\Request\CommandsRequest $request)
{
<<<<<<< HEAD
return $this->submitRequest(
'/my/commands',
HttpClient::METHOD_GET,
@ -247,6 +285,9 @@ class Client
static::getEntityClass('Command'),
true
);
=======
return $this->client->makeRequest('/my/commands', Request::METHOD_GET, $request, Serializer::S_ARRAY);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
@ -277,12 +318,16 @@ class Client
*/
public function commandDelete(string $request)
{
<<<<<<< HEAD
return $this->submitRequest(
sprintf("/my/commands/%s", $request),
HttpClient::METHOD_DELETE,
null,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
);
=======
return $this->client->makeRequest(sprintf("/my/commands/%s", $request), Request::METHOD_DELETE);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
@ -295,6 +340,7 @@ class Client
*/
public function customers(Model\Request\CustomersRequest $request)
{
<<<<<<< HEAD
return $this->submitRequest(
'/customers',
HttpClient::METHOD_GET,
@ -302,6 +348,9 @@ class Client
static::getEntityClass('Customer'),
true
);
=======
return $this->client->makeRequest('/customers', Request::METHOD_GET, $request, Serializer::S_ARRAY);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
@ -314,6 +363,7 @@ class Client
*/
public function dialogs(Model\Request\DialogsRequest $request)
{
<<<<<<< HEAD
return $this->submitRequest(
'/dialogs',
HttpClient::METHOD_GET,
@ -321,6 +371,47 @@ class Client
static::getEntityClass('Dialog'),
true
);
=======
return $this->client->makeRequest('/dialogs', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
/**
* Assign dialog to exact user
*
* @param Model\Request\DialogAssignRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function dialogAssign(Model\Request\DialogAssignRequest $request)
{
return $this->client->makeRequest(
sprintf("/dialogs/%d/assign", $request->getDialogId()),
Request::METHOD_PATCH,
$request
);
}
/**
* Close exact dialog
*
* @param string $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function dialogClose(string $request)
{
return $this->client->makeRequest(sprintf("/dialogs/%d/close", $request), Request::METHOD_DELETE);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
@ -369,6 +460,7 @@ class Client
*/
public function members(Model\Request\MembersRequest $request)
{
<<<<<<< HEAD
return $this->submitRequest(
'/members',
HttpClient::METHOD_GET,
@ -376,6 +468,9 @@ class Client
static::getEntityClass('Chat', 'ChatMember'),
true
);
=======
return $this->client->makeRequest('/members', Request::METHOD_GET, $request, Serializer::S_ARRAY);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
@ -388,6 +483,7 @@ class Client
*/
public function messages(Model\Request\MessagesRequest $request)
{
<<<<<<< HEAD
return $this->submitRequest(
'/messages',
HttpClient::METHOD_GET,
@ -395,6 +491,60 @@ class Client
self::getEntityClass('Message', 'Message'),
true
);
=======
return $this->client->makeRequest('/messages', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
/**
* Send a message
*
* @param Model\Request\MessageSendRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function messageSend(Model\Request\MessageSendRequest $request)
{
return $this->client->makeRequest('/messages', Request::METHOD_POST, $request);
}
/**
* Edit a message
*
* @param Model\Request\MessageEditRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function messageEdit(Model\Request\MessageEditRequest $request)
{
return $this->client->makeRequest('/messages/%d', Request::METHOD_PATCH, $request->getId());
}
/**
* Delete a message
*
* @param string $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function messageDelete(string $request)
{
return $this->client->makeRequest(sprintf("/messages/%d", $request), Request::METHOD_DELETE);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
/**
@ -461,6 +611,7 @@ class Client
*/
public function users(Model\Request\UsersRequest $request)
{
<<<<<<< HEAD
return $this->submitRequest(
'/users',
HttpClient::METHOD_GET,
@ -529,5 +680,8 @@ class Client
);
return ($obj instanceof FullFileResponse) ? $obj : null;
=======
return $this->client->makeRequest('/users', Request::METHOD_GET, $request, Serializer::S_ARRAY);
>>>>>>> 0e28925... add request model (except ws and files), move serializer & url handling into separate namespace
}
}

View file

@ -1,55 +0,0 @@
<?php
/**
* PHP version 7.0
*
* Request Helper
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot;
/**
* PHP version 7.0
*
* RequestHelper class
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class IntegrationHelper
{
/**
* Prepare module data
*
* @param array $config
* @param string $clientId
*
* @return array
*/
public static function moduleRequest(array $config, string $clientId)
{
$config['host'] = str_replace("https://", '', $config['host']);
$moduleConfiguration = [
'code' => $config['code'],
'integrationCode' => $config['code'],
'active' => true,
'name' => $config['name'],
'clientId' => $clientId,
'logo' => sprintf("https://%s%s", $config['host'], $config['logo']),
'baseUrl' => sprintf("https://%s", $config['host']),
'accountURL' => sprintf("https://%s/settings/%s", $config['host'], $clientId),
'actions' => ['activity' => '/actions/activity'],
'integrations' => ['mgBot' => []]
];
return $moduleConfiguration;
}
}

View file

@ -0,0 +1,82 @@
<?php
/**
* PHP version 7.0
*
* Cost entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Cost class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Cost
{
/**
* @var float $value
*
* @Type("float")
* @Accessor(getter="getValue",setter="setValue")
* @SkipWhenEmpty()
*/
private $value;
/**
* @var string $currency
*
* @Type("string")
* @Accessor(getter="getCurrency",setter="setCurrency")
*
* @Assert\Currency
*/
private $currency;
/**
* @return float
*/
public function getValue()
{
return $this->value;
}
/**
* @param float $value
*/
public function setValue(float $value)
{
$this->value = $value;
}
/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* @param string $currency
*/
public function setCurrency(string $currency)
{
$this->currency = $currency;
}
}

View file

@ -0,0 +1,133 @@
<?php
/**
* PHP version 7.0
*
* Delivery entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Delivery class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Delivery
{
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
*
* @Assert\NotBlank
*/
private $name;
/**
* @var \RetailCrm\Mg\Bot\Model\Entity\Cost $price
*
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Cost")
* @Accessor(getter="getPrice",setter="setPrice")
*
* @Assert\Currency
*/
private $price;
/**
* @var string $address
*
* @Type("string")
* @Accessor(getter="getAddress",setter="setAddress")
* @SkipWhenEmpty()
*/
private $address;
/**
* @var string $comment
*
* @Type("string")
* @Accessor(getter="getComment",setter="setComment")
* @SkipWhenEmpty()
*/
private $comment;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return \RetailCrm\Mg\Bot\Model\Entity\Cost
*/
public function getPrice()
{
return $this->price;
}
/**
* @param \RetailCrm\Mg\Bot\Model\Entity\Cost $price
*/
public function setPrice(Cost $price)
{
$this->price = $price;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @param string $address
*/
public function setAddress(string $address)
{
$this->address = $address;
}
/**
* @return string
*/
public function getComment()
{
return $this->comment;
}
/**
* @param string $comment
*/
public function setComment(string $comment)
{
$this->comment = $comment;
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.0
*
* Item entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Item class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Item
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty()
*/
private $id;
/**
* @var string $caption
*
* @Type("string")
* @Accessor(getter="getCaption",setter="setCaption")
* @SkipWhenEmpty()
*/
private $caption;
/**
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getCaption()
{
return $this->caption;
}
/**
* @param string $caption
*/
public function setCaption(string $caption)
{
$this->caption = $caption;
}
}

View file

@ -0,0 +1,232 @@
<?php
/**
* PHP version 7.0
*
* Order entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Order class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Order
{
/**
* @var string $number
*
* @Type("string")
* @Accessor(getter="getNumber",setter="setNumber")
*
* @Assert\NotBlank
*/
private $number;
/**
* @var string $url
*
* @Type("string")
* @Accessor(getter="getUrl",setter="setUrl")
* @SkipWhenEmpty()
*/
private $url;
/**
* @var string $date
*
* @Type("string")
* @Accessor(getter="getDate",setter="setDate")
* @SkipWhenEmpty()
*/
private $date;
/**
* @var \RetailCrm\Mg\Bot\Model\Entity\Cost $cost
*
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Cost")
* @Accessor(getter="getCost",setter="setCost")
* @SkipWhenEmpty()
*/
private $cost;
/**
* @var \RetailCrm\Mg\Bot\Model\Entity\Status $status
*
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Status")
* @Accessor(getter="getStatus",setter="setStatus")
* @SkipWhenEmpty()
*/
private $status;
/**
* @var \RetailCrm\Mg\Bot\Model\Entity\Delivery $delivery
*
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Delivery")
* @Accessor(getter="getDelivery",setter="setDelivery")
* @SkipWhenEmpty()
*/
private $delivery;
/**
* @var array $items
*
* @Type("array")
* @Accessor(getter="getItems",setter="setItems")
* @SkipWhenEmpty()
*/
private $items;
/**
* @var array $payments
*
* @Type("array")
* @Accessor(getter="getPayments",setter="setPayments")
* @SkipWhenEmpty()
*/
private $payments;
/**
* @return string
*/
public function getNumber()
{
return $this->number;
}
/**
* @param string $number
*/
public function setNumber(string $number)
{
$this->number = $number;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url)
{
$this->url = $url;
}
/**
* @return string
*/
public function getDate()
{
return $this->date;
}
/**
* @param string $date
*/
public function setDate(string $date)
{
$this->date = $date;
}
/**
* @return \RetailCrm\Mg\Bot\Model\Entity\Cost
*/
public function getCost()
{
return $this->cost;
}
/**
* @param \RetailCrm\Mg\Bot\Model\Entity\Cost $cost
*/
public function setCost(Cost $cost)
{
$this->cost = $cost;
}
/**
* @return \RetailCrm\Mg\Bot\Model\Entity\Status
*/
public function getStatus()
{
return $this->status;
}
/**
* @param \RetailCrm\Mg\Bot\Model\Entity\Status $status
*/
public function setStatus(Status $status)
{
$this->status = $status;
}
/**
* @return \RetailCrm\Mg\Bot\Model\Entity\Delivery
*/
public function getDelivery()
{
return $this->delivery;
}
/**
* @param \RetailCrm\Mg\Bot\Model\Entity\Delivery $delivery
*/
public function setDelivery(Delivery $delivery)
{
$this->delivery = $delivery;
}
/**
* @return array
*/
public function getItems()
{
return $this->items;
}
/**
* @param array $items
*/
public function setItems(array $items)
{
$this->items = $items;
}
/**
* @return array
*/
public function getPayments()
{
return $this->payments;
}
/**
* @param array $payments
*/
public function setPayments(array $payments)
{
$this->payments = $payments;
}
}

View file

@ -0,0 +1,156 @@
<?php
/**
* PHP version 7.0
*
* Order item entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* OrderItem class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class OrderItem
{
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @var string $url
*
* @Type("string")
* @Accessor(getter="getUrl",setter="setUrl")
* @SkipWhenEmpty()
*/
private $url;
/**
* @var string $img
*
* @Type("string")
* @Accessor(getter="getImg",setter="setImg")
* @SkipWhenEmpty()
*/
private $img;
/**
* @var \RetailCrm\Mg\Bot\Model\Entity\Cost $price
*
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Cost")
* @Accessor(getter="getPrice",setter="setPrice")
* @SkipWhenEmpty()
*/
private $price;
/**
* @var \RetailCrm\Mg\Bot\Model\Entity\Quantity $quantity
*
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Quantity")
* @Accessor(getter="getQuantity",setter="setQuantity)
* @SkipWhenEmpty()
*/
private $quantity;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url)
{
$this->url = $url;
}
/**
* @return string
*/
public function getImg()
{
return $this->img;
}
/**
* @param string $img
*/
public function setImg(string $img)
{
$this->img = $img;
}
/**
* @return \RetailCrm\Mg\Bot\Model\Entity\Cost
*/
public function getPrice()
{
return $this->price;
}
/**
* @param \RetailCrm\Mg\Bot\Model\Entity\Cost $price
*/
public function setPrice(Cost $price)
{
$this->price = $price;
}
/**
* @return \RetailCrm\Mg\Bot\Model\Entity\Quantity
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* @param \RetailCrm\Mg\Bot\Model\Entity\Quantity $quantity
*/
public function setQuantity(Quantity $quantity)
{
$this->quantity = $quantity;
}
}

View file

@ -0,0 +1,106 @@
<?php
/**
* PHP version 7.0
*
* Payment entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Payment class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Payment
{
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @var \RetailCrm\Mg\Bot\Model\Entity\PaymentStatus $status
*
* @Type("\RetailCrm\Mg\Bot\Model\Entity\PaymentStatus")
* @Accessor(getter="getStatus",setter="setStatus")
* @SkipWhenEmpty()
*/
private $status;
/**
* @var \RetailCrm\Mg\Bot\Model\Entity\Cost $amount
*
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Cost")
* @Accessor(getter="getAmount",setter="setAmount")
* @SkipWhenEmpty()
*/
private $amount;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return \RetailCrm\Mg\Bot\Model\Entity\PaymentStatus
*/
public function getStatus()
{
return $this->status;
}
/**
* @param \RetailCrm\Mg\Bot\Model\Entity\PaymentStatus $status
*/
public function setStatus(PaymentStatus $status)
{
$this->status = $status;
}
/**
* @return \RetailCrm\Mg\Bot\Model\Entity\Cost
*/
public function getAmount()
{
return $this->amount;
}
/**
* @param \RetailCrm\Mg\Bot\Model\Entity\Cost $amount
*/
public function setAmount(Cost $amount)
{
$this->amount = $amount;
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.0
*
* Payment status entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* PaymentStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class PaymentStatus
{
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @var bool $payed
*
* @Type("bool")
* @Accessor(getter="getPayed",setter="setPayed")
* @SkipWhenEmpty()
*/
private $payed;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return bool
*/
public function isPayed()
{
return $this->payed;
}
/**
* @param bool $payed
*/
public function setPayed(bool $payed)
{
$this->payed = $payed;
}
}

View file

@ -0,0 +1,208 @@
<?php
/**
* PHP version 7.0
*
* Product entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Product class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Product
{
/**
* @var int $id
*
* @Type("int")
* @Accessor(getter="getId",setter="setId")
*
* @Assert\NotBlank
*/
private $id;
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
*
* @Assert\NotBlank
*/
private $name;
/**
* @var string $article
*
* @Type("string")
* @Accessor(getter="getArticle",setter="setArticle")
* @SkipWhenEmpty()
*/
private $article;
/**
* @var string $url
*
* @Type("string")
* @Accessor(getter="getUrl",setter="setUrl")
* @SkipWhenEmpty()
*/
private $url;
/**
* @var string $img
*
* @Type("string")
* @Accessor(getter="getImg",setter="setImg")
* @SkipWhenEmpty()
*/
private $img;
/**
* @var \RetailCrm\Mg\Bot\Model\Entity\Cost $cost
*
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Cost")
* @Accessor(getter="getCost",setter="setCost")
* @SkipWhenEmpty()
*/
private $cost;
/**
* @var \RetailCrm\Mg\Bot\Model\Entity\Quantity $quantity
*
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Quantity")
* @Accessor(getter="getQuantity",setter="setQuantity)
* @SkipWhenEmpty()
*/
private $quantity;
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getArticle()
{
return $this->article;
}
/**
* @param string $article
*/
public function setArticle(string $article)
{
$this->article = $article;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url)
{
$this->url = $url;
}
/**
* @return string
*/
public function getImg()
{
return $this->img;
}
/**
* @param string $img
*/
public function setImg(string $img)
{
$this->img = $img;
}
/**
* @return \RetailCrm\Mg\Bot\Model\Entity\Cost
*/
public function getCost()
{
return $this->cost;
}
/**
* @param \RetailCrm\Mg\Bot\Model\Entity\Cost $cost
*/
public function setCost(Cost $cost)
{
$this->cost = $cost;
}
/**
* @return \RetailCrm\Mg\Bot\Model\Entity\Quantity
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* @param \RetailCrm\Mg\Bot\Model\Entity\Quantity $quantity
*/
public function setQuantity(Quantity $quantity)
{
$this->quantity = $quantity;
}
}

View file

@ -0,0 +1,82 @@
<?php
/**
* PHP version 7.0
*
* Quantity entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Quantity class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Quantity
{
/**
* @var float $value
*
* @Type("float")
* @Accessor(getter="getValue",setter="setValue")
* @SkipWhenEmpty()
*/
private $value;
/**
* @var string $unit
*
* @Type("string")
* @Accessor(getter="getUnit",setter="setUnit")
*
* @Assert\Currency
*/
private $unit;
/**
* @return float
*/
public function getValue()
{
return $this->value;
}
/**
* @param float $value
*/
public function setValue(float $value)
{
$this->value = $value;
}
/**
* @return string
*/
public function getUnit()
{
return $this->unit;
}
/**
* @param string $unit
*/
public function setUnit(string $unit)
{
$this->unit = $unit;
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.0
*
* Status entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Status class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Status
{
/**
* @var string $code
*
* @Type("string")
* @Accessor(getter="getCode",setter="setCode")
* @SkipWhenEmpty()
*/
private $code;
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*/
public function setCode(string $code)
{
$this->code = $code;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
}

View file

@ -13,11 +13,12 @@
namespace RetailCrm\Mg\Bot;
use JMS\Serializer\SerializerBuilder;
use RetailCrm\Common\Exception\CurlException;
use RetailCrm\Common\Exception\LimitException;
use Exception;
use InvalidArgumentException;
use RetailCrm\Common\Serializer;
use RetailCrm\Common\Url;
use Symfony\Component\Validator\Validation;
/**
@ -35,24 +36,24 @@ class Request
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
const METHOD_PATCH = 'PATCH';
const METHOD_DELETE = 'DELETE';
const S_ARRAY = 0;
const S_JSON = 1;
protected $url;
protected $token;
private $debug;
private $allowedMethods;
private $stdout;
/**
* Client constructor.
*
* @param string $url api url
* @param string $token api token
* @param bool $debug make request verbose
* @param string $url api url
* @param string $token api token
* @param bool $debug make request verbose
* @param bool|resource $stdout default output for debug
*/
public function __construct($url, $token, $debug)
public function __construct($url, $token, $debug, $stdout = STDOUT)
{
if (false === stripos($url, 'https://')) {
throw new InvalidArgumentException('API schema requires HTTPS protocol');
@ -61,7 +62,14 @@ class Request
$this->url = $url;
$this->token = $token;
$this->debug = $debug;
$this->allowedMethods = [self::METHOD_GET, self::METHOD_POST, self::METHOD_PUT, self::METHOD_DELETE];
$this->stdout = $stdout;
$this->allowedMethods = [
self::METHOD_GET,
self::METHOD_POST,
self::METHOD_PUT,
self::METHOD_PATCH,
self::METHOD_DELETE
];
}
/**
@ -75,13 +83,21 @@ class Request
* @return Response
* @throws \Exception
*/
public function makeRequest($path, $method, $request = null, $serializeTo = self::S_JSON)
public function makeRequest($path, $method, $request = null, $serializeTo = Serializer::S_JSON)
{
$this->validateMethod($method);
$this->validateRequest($request);
$parameters = $this->serialize($request, $serializeTo);
$url = $this->buildUrl($path, $method, $parameters);
if (!is_null($request)) {
$this->validateRequest($request);
}
$urlBuilder = new Url();
$parameters = is_null($request) ? null : Serializer::serialize($request, $serializeTo);
$url = $method == self::METHOD_GET
? $this->url . $urlBuilder->buildUrl($path, $parameters, Url::RFC_CUSTOM)
: $this->url . $path
;
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, $url);
@ -92,14 +108,15 @@ class Request
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curlHandler, CURLOPT_TIMEOUT, 60);
curl_setopt($curlHandler, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($curlHandler, CURLOPT_VERBOSE, (int)$this->debug);
curl_setopt($curlHandler, CURLOPT_VERBOSE, $this->debug);
curl_setopt($curlHandler, CURLOPT_STDERR, $this->stdout);
curl_setopt($curlHandler, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
sprintf("X-Bot-Token: %s", $this->token)
]);
if (in_array($method, [self::METHOD_POST, self::METHOD_PUT, self::METHOD_DELETE])) {
if (in_array($method, [self::METHOD_POST, self::METHOD_PUT, self::METHOD_PATCH, self::METHOD_DELETE])) {
curl_setopt($curlHandler, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $parameters);
}
@ -135,22 +152,6 @@ class Request
return new Response($statusCode, $responseBody);
}
/**
* Check trailing slash into url
*
* @param string $url
*
* @return string
*/
public static function normalizeUrl($url)
{
if ('/' !== $url[strlen($url) - 1]) {
$url .= '/';
}
return $url;
}
/**
* Validate HTTP method
*
@ -189,50 +190,4 @@ class Request
throw new InvalidArgumentException($message);
}
}
/**
* Serialize given object to JSON or Array
*
* @param object $request
* @param int $serialize
*
* @return array|string
*/
private function serialize($request, $serialize)
{
$serialized = null;
switch ($serialize) {
case self::S_ARRAY:
$serializer = SerializerBuilder::create()->build();
$serialized = $serializer->toArray($request);
break;
case self::S_JSON:
$serializer = SerializerBuilder::create()->build();
$serialized = $serializer->serialize($request, 'json');
}
return $serialized;
}
/**
* Build request url
*
* @param string $path
* @param string $method
* @param array $parameters
*
* @return string
*/
private function buildUrl($path, $method, $parameters)
{
$url = $this->url . $path;
if (self::METHOD_GET === $method && count($parameters)) {
$queryString = http_build_query($parameters, '', '&');
$url = sprintf("%s?%s", $url, $queryString);
}
return $url;
}
}

View file

@ -28,22 +28,22 @@ use RetailCrm\Mg\Bot\Client;
class TestCase extends BaseCase
{
/**
* Return ApiClient object
* Return bot api client object
*
* @param string $url (default: null)
* @param string $key (default: null)
* @param bool $debug (default: false)
*
* @return Client
* @return \RetailCrm\Mg\Bot\Client
*/
public static function getApiClient(
$url = null,
$key = null,
$debug = false
) {
$configUrl = getenv('MG_BOT_URL') ?: $_SERVER['MG_BOT_URL'];
$configKey = getenv('MG_BOT_KEY') ?: $_SERVER['MG_BOT_KEY'];
$configDbg = getenv('MG_BOT_DBG') ?: $_SERVER['MG_BOT_DBG'];
$configUrl = getenv('MG_BOT_URL');
$configKey = getenv('MG_BOT_KEY');
$configDbg = getenv('MG_BOT_DBG');
return new Client(
$url ?: $configUrl,

View file

@ -1,126 +0,0 @@
<?php
/**
* PHP version 7.0
*
* Client Test
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Tests;
use InvalidArgumentException;
use RetailCrm\Mg\Bot\Model\Constants;
use RetailCrm\Mg\Bot\Model\Request\BotsRequest;
use RetailCrm\Mg\Bot\Model\Request\ChannelsRequest;
use RetailCrm\Mg\Bot\Model\Request\CommandEditRequest;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class ClientTest
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ClientTest extends TestCase
{
/**
* @group("list")
* @throws \Exception
*/
public function testChannels()
{
$client = self::getApiClient();
$request = new ChannelsRequest();
$request->setActive(true);
$request->setTypes([Constants::CHANNEL_TYPE_FACEBOOK]);
$channels = $client->channels($request);
self::assertTrue($channels->isSuccessful() == true);
}
public function testChats()
{
self::assertTrue(1 == 1);
}
public function testMembers()
{
self::assertTrue(1 == 1);
}
public function testMessages()
{
self::assertTrue(1 == 1);
}
public function testCommands()
{
self::assertTrue(1 == 1);
}
/**
* @throws \Exception
*/
public function testCommandEditException()
{
self::expectException(InvalidArgumentException::class);
$client = self::getApiClient();
$command = new CommandEditRequest();
$command->setDescription("qwerty");
$client->commandEdit($command);
}
/**
* @throws \Exception
*/
public function testCommandDeleteException()
{
self::expectException(\Exception::class);
$client = self::getApiClient();
$command = "qwerty";
$client->commandDelete($command);
}
/**
* @throws \Exception
*/
public function testBots()
{
$client = self::getApiClient();
$request = new BotsRequest();
$request->setActive(1);
$request->setRoles([Constants::BOT_ROLE_RESPONSIBLE]);
$bots = $client->bots($request);
self::assertTrue($bots->isSuccessful() == true);
}
public function testUsers()
{
self::assertTrue(1 == 1);
}
public function testDialogs()
{
self::assertTrue(1 == 1);
}
public function testCustomers()
{
self::assertTrue(1 == 1);
}
}