From bb78a4ffb30ece147a832ed151f43ccd5d760ac3 Mon Sep 17 00:00:00 2001 From: Opheugene Date: Thu, 2 Sep 2021 11:17:59 +0300 Subject: [PATCH] Add dialogUnassign method for the client (#15) --- composer.json | 4 +- composer.lock | 92 ++++++++++++--------- src/Bot/Client.php | 22 +++++ src/Bot/Model/Response/UnassignResponse.php | 52 ++++++++++++ tests/Bot/Tests/DialogsTest.php | 36 ++++++++ tests/Resources/dialogUnassigned.json | 1 + 6 files changed, 164 insertions(+), 43 deletions(-) create mode 100644 src/Bot/Model/Response/UnassignResponse.php create mode 100644 tests/Resources/dialogUnassigned.json diff --git a/composer.json b/composer.json index 7d8ad0a..061439e 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ "ext-json": "*", "jms/serializer": "1.14.*", "symfony/validator": "4.3.*", - "doctrine/annotations": "1.6.*", - "doctrine/cache": "1.6.*", + "doctrine/annotations": "1.12.*", + "doctrine/cache": "1.11.*", "guzzlehttp/guzzle": "6.*" }, "require-dev": { diff --git a/composer.lock b/composer.lock index d2c8d25..14850d1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,36 +4,34 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6e3c14ec41fb380210d5ef5869a9fda3", + "content-hash": "ead61109a480af51dec2cd7f77083a15", "packages": [ { "name": "doctrine/annotations", - "version": "v1.6.1", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "53120e0eb10355388d6ccbe462f1fea34ddadb24" + "reference": "b17c5014ef81d212ac539f07a1001832df1b6d3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/53120e0eb10355388d6ccbe462f1fea34ddadb24", - "reference": "53120e0eb10355388d6ccbe462f1fea34ddadb24", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/b17c5014ef81d212ac539f07a1001832df1b6d3b", + "reference": "b17c5014ef81d212ac539f07a1001832df1b6d3b", "shasum": "" }, "require": { "doctrine/lexer": "1.*", - "php": "^7.1" + "ext-tokenizer": "*", + "php": "^7.1 || ^8.0" }, "require-dev": { "doctrine/cache": "1.*", - "phpunit/phpunit": "^6.4" + "doctrine/coding-standard": "^6.0 || ^8.1", + "phpstan/phpstan": "^0.12.20", + "phpunit/phpunit": "^7.5 || ^9.1.5" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6.x-dev" - } - }, "autoload": { "psr-4": { "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" @@ -44,6 +42,10 @@ "MIT" ], "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -52,10 +54,6 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" @@ -66,45 +64,49 @@ } ], "description": "Docblock Annotations Parser", - "homepage": "http://www.doctrine-project.org", + "homepage": "https://www.doctrine-project.org/projects/annotations.html", "keywords": [ "annotations", "docblock", "parser" ], - "time": "2019-03-25T19:12:02+00:00" + "time": "2021-02-21T21:00:45+00:00" }, { "name": "doctrine/cache", - "version": "v1.6.2", + "version": "1.11.0", "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "eb152c5100571c7a45470ff2a35095ab3f3b900b" + "reference": "a9c1b59eba5a08ca2770a76eddb88922f504e8e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/eb152c5100571c7a45470ff2a35095ab3f3b900b", - "reference": "eb152c5100571c7a45470ff2a35095ab3f3b900b", + "url": "https://api.github.com/repos/doctrine/cache/zipball/a9c1b59eba5a08ca2770a76eddb88922f504e8e0", + "reference": "a9c1b59eba5a08ca2770a76eddb88922f504e8e0", "shasum": "" }, "require": { - "php": "~5.5|~7.0" + "php": "~7.1 || ^8.0" }, "conflict": { - "doctrine/common": ">2.2,<2.4" + "doctrine/common": ">2.2,<2.4", + "psr/cache": ">=3" }, "require-dev": { - "phpunit/phpunit": "~4.8|~5.0", + "alcaeus/mongo-php-adapter": "^1.1", + "cache/integration-tests": "dev-master", + "doctrine/coding-standard": "^8.0", + "mongodb/mongodb": "^1.1", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", "predis/predis": "~1.0", - "satooshi/php-coveralls": "~0.6" + "psr/cache": "^1.0 || ^2.0", + "symfony/cache": "^4.4 || ^5.2" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6.x-dev" - } - }, "autoload": { "psr-4": { "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" @@ -115,6 +117,10 @@ "MIT" ], "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -123,10 +129,6 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" @@ -136,13 +138,20 @@ "email": "schmittjoh@gmail.com" } ], - "description": "Caching library offering an object-oriented API for many cache backends", - "homepage": "http://www.doctrine-project.org", + "description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.", + "homepage": "https://www.doctrine-project.org/projects/cache.html", "keywords": [ + "abstraction", + "apcu", "cache", - "caching" + "caching", + "couchdb", + "memcached", + "php", + "redis", + "xcache" ], - "time": "2017-07-22T12:49:21+00:00" + "time": "2021-04-13T14:46:17+00:00" }, { "name": "doctrine/instantiator", @@ -2634,6 +2643,7 @@ "keywords": [ "tokenizer" ], + "abandoned": true, "time": "2018-10-30T05:52:18+00:00" }, { @@ -3962,12 +3972,12 @@ "version": "1.4.0", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", + "url": "https://github.com/webmozarts/assert.git", "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", "shasum": "" }, diff --git a/src/Bot/Client.php b/src/Bot/Client.php index 5b0cbfc..24ee1be 100644 --- a/src/Bot/Client.php +++ b/src/Bot/Client.php @@ -25,6 +25,7 @@ use RetailCrm\Mg\Bot\Model\Entity\Message\Message; use RetailCrm\Mg\Bot\Model\Entity\User; use RetailCrm\Mg\Bot\Model\Request\UploadFileByUrlRequest; use RetailCrm\Mg\Bot\Model\Response\AssignResponse; +use RetailCrm\Mg\Bot\Model\Response\UnassignResponse; use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse; use RetailCrm\Mg\Bot\Model\Response\FullFileResponse; use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse; @@ -270,6 +271,27 @@ class Client return $adapter->getResponseModel($response); } + /** + * Unassigning a dialog from a manager or a bot + * + * @param string $request Request parameters + * + * @return \RetailCrm\Mg\Bot\Model\ModelInterface + * @throws \Exception + */ + public function dialogUnassign(string $request) + { + $response = $this->client->makeRequest( + sprintf("/dialogs/%d/unassign", $request), + HttpClient::METHOD_PATCH, + null + ); + + $adapter = new ModelAdapter(UnassignResponse::class); + + return $adapter->getResponseModel($response); + } + /** * Close exact dialog * diff --git a/src/Bot/Model/Response/UnassignResponse.php b/src/Bot/Model/Response/UnassignResponse.php new file mode 100644 index 0000000..47848b4 --- /dev/null +++ b/src/Bot/Model/Response/UnassignResponse.php @@ -0,0 +1,52 @@ +previousResponsible; + } + + /** + * @param Responsible $previousResponsible + */ + public function setPreviousResponsible(Responsible $previousResponsible) + { + $this->previousResponsible = $previousResponsible; + } +} diff --git a/tests/Bot/Tests/DialogsTest.php b/tests/Bot/Tests/DialogsTest.php index e8e5312..08ee4d3 100644 --- a/tests/Bot/Tests/DialogsTest.php +++ b/tests/Bot/Tests/DialogsTest.php @@ -72,6 +72,42 @@ class DialogsTest extends TestCase self::assertTrue($response->getResponsible() instanceof Responsible); } + /** + * @group("dialogs") + * @throws \Exception + */ + public function testDialogUnassignError() + { + $this->expectException(\RuntimeException::class); + $client = self::getApiClient( + null, + null, + false, + $this->getErrorsResponse(400, "incorrect dialog_id") + ); + + $client->dialogUnassign(-1); + } + + /** + * @group("dialogs") + * @throws \Exception + */ + public function testDialogUnassign() + { + $client = self::getApiClient( + null, + null, + false, + $this->getJsonResponse('dialogUnassigned') + ); + + $response = $client->dialogUnassign(60); + + self::assertTrue($response->isSuccessful()); + self::assertTrue($response->getPreviousResponsible() instanceof Responsible); + } + /** * @group("dialogs") * @throws \Exception diff --git a/tests/Resources/dialogUnassigned.json b/tests/Resources/dialogUnassigned.json new file mode 100644 index 0000000..08d2c42 --- /dev/null +++ b/tests/Resources/dialogUnassigned.json @@ -0,0 +1 @@ +{"previous_responsible":{"type":"user","id":12,"assigned_at":"2019-06-11T12:49:34Z"}} \ No newline at end of file