1
0
mirror of synced 2024-11-28 06:06:02 +03:00

Add dialogUnassign method for the client (#15)

This commit is contained in:
Opheugene 2021-09-02 11:17:59 +03:00 committed by GitHub
parent 84ecba8714
commit bb78a4ffb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 164 additions and 43 deletions

View File

@ -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": {

92
composer.lock generated
View File

@ -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": ""
},

View File

@ -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
*

View File

@ -0,0 +1,52 @@
<?php
/**
* PHP version 7.1
*
* UnassignResponse
*
* @package RetailCrm\Mg\Bot\Model\Response
*/
namespace RetailCrm\Mg\Bot\Model\Response;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Responsible;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* UnassignResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
*/
class UnassignResponse implements ModelInterface
{
use CommonFields;
/**
* @var Responsible $previousResponsible
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Responsible")
* @Accessor(getter="getPreviousResponsible",setter="setPreviousResponsible")
* @SkipWhenEmpty()
*/
private $previousResponsible;
/**
* @return Responsible|null
*/
public function getPreviousResponsible(): ?Responsible
{
return $this->previousResponsible;
}
/**
* @param Responsible $previousResponsible
*/
public function setPreviousResponsible(Responsible $previousResponsible)
{
$this->previousResponsible = $previousResponsible;
}
}

View File

@ -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

View File

@ -0,0 +1 @@
{"previous_responsible":{"type":"user","id":12,"assigned_at":"2019-06-11T12:49:34Z"}}