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

rebase & merge

This commit is contained in:
Alex Lushpai 2019-07-16 14:58:03 +03:00
parent 52fc9655b9
commit 91f25084f5
11 changed files with 645 additions and 2428 deletions

View file

@ -11,7 +11,7 @@ test:
stan:
@echo "==> Running analysis"
@php $(BIN_DIR)/phpstan analyse -a $(ROOT_DIR)/extra/autoloader.php -l 4 src
@php $(BIN_DIR)/phpstan analyse
@echo "==> Analysis complete"
travis: test stan

View file

@ -4,7 +4,6 @@
[![PHP from Packagist](https://img.shields.io/packagist/php-v/retailcrm/mg-bot-api-client-php.svg?style=flat-square)](https://packagist.org/packages/retailcrm/mg-bot-api-client-php)
# retailCRM API PHP client
This is php retailCRM MG Bot API client.

View file

@ -16,36 +16,17 @@
"ext-curl": "*",
"ext-json": "*",
"jms/serializer": "1.14.*",
"symfony/validator": "3.*",
"doctrine/annotations": "1.4.*",
"symfony/validator": "4.3.*",
"doctrine/annotations": "1.6.*",
"doctrine/cache": "1.6.*",
"guzzlehttp/guzzle": "6.*",
"doctrine/instantiator": "1.0.*",
"symfony/translation": "3.*",
"symfony/dependency-injection": "3.*",
"symfony/config": "3.*",
"symfony/finder": "3.4.*",
"symfony/filesystem": "3.*"
"guzzlehttp/guzzle": "6.*"
},
"require-dev": {
"phpmd/phpmd": "2.*",
"squizlabs/php_codesniffer": "3.4.*",
"symfony/dotenv": "3.*",
"friendsofphp/php-cs-fixer": "2.*",
"phpunit/phpunit": "6.*",
"nette/bootstrap": "2.*",
"nette/neon": "2.*",
"nette/php-generator": "3.0.*",
"phpstan/phpstan": "0.9.*",
"ocramius/package-versions": "1.2.*",
"nette/finder": "2.4.*",
"symfony/console": "3.*",
"symfony/debug": "3.*",
"symfony/event-dispatcher": "3.*",
"symfony/options-resolver": "3.4.*",
"symfony/process": "3.4.*",
"symfony/stopwatch": "3.4.*",
"myclabs/deep-copy": "1.6.*"
"symfony/dotenv": "4.3.*",
"phpunit/phpunit": "7.*",
"phpstan/phpstan": "0.11.*"
},
"support": {
"email": "support@retailcrm.ru"

2804
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,7 @@ use Composer\Autoload\ClassLoader;
* @var ClassLoader $loader
*/
$autoloadFile = file_exists(__DIR__ . '/../vendor/autoload.php')
$autoloadFile = file_exists(__DIR__ . '/../vendor/autoload.php')
? __DIR__ . '/../vendor/autoload.php'
: __DIR__ . '/../../../autoload.php';

View file

@ -1,6 +1,6 @@
parameters:
autoload_files:
- %currentWorkingDirectory%/vendor/autoload.php
level: 4
level: 7
paths:
- %currentWorkingDirectory%/src

View file

@ -31,9 +31,6 @@ use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse;
use RetailCrm\Mg\Bot\Model\Response\UploadFileResponse;
use RetailCrm\Mg\Bot\Model;
use Exception;
use InvalidArgumentException;
/**
* Class Client
@ -246,45 +243,15 @@ class Client
*/
public function dialogs(Model\Request\DialogsRequest $request): array
{
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,
$response = $this->client->makeRequest(
'/dialogs',
HttpClient::METHOD_GET,
$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);
$adapter = new ModelAdapter(Dialog::class);
return $adapter->getResponseList($response);
}
/**
@ -360,58 +327,15 @@ class Client
*/
public function messages(Model\Request\MessagesRequest $request): array
{
return $this->client->makeRequest('/messages', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
$response = $this->client->makeRequest(
'/messages',
HttpClient::METHOD_GET,
$request
);
/**
* 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);
}
$adapter = new ModelAdapter(Message::class);
/**
* 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);
return $adapter->getResponseList($response);
}
/**

View file

@ -17,9 +17,7 @@ use DomainException;
use Throwable;
/**
* PHP version 7.0
*
* Class CurlException
* Class LimitException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>

View file

@ -24,16 +24,6 @@ namespace RetailCrm\Common;
class Url
{
/**
<<<<<<< HEAD
* This class is used to store normalizeUrl method
* which is used in Client and HttpClient to check
* trailing slash.
*/
private function __construct() {}
/**
=======
>>>>>>> af44f8a... update models, update tests, update travis
* Check trailing slash into url
*
* @param string $url

View file

@ -14,6 +14,9 @@
namespace RetailCrm\Mg\Bot\Test;
use PHPUnit\Framework\TestCase as BaseCase;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use RetailCrm\Mg\Bot\Client;
/**
@ -29,25 +32,118 @@ class TestCase extends BaseCase
/**
* Return bot api client object
*
* @param string $url (default: null)
* @param string $key (default: null)
* @param bool $debug (default: false)
* @param string $url (default: null)
* @param string $key (default: null)
* @param bool $debug (default: false)
* @param array ...$response (default: null)
*
* @return \RetailCrm\Mg\Bot\Client
* @return Client
*/
public static function getApiClient(
$url = null,
$key = null,
$debug = false
$debug = false,
...$response
) {
$configUrl = getenv('MG_BOT_URL');
$configKey = getenv('MG_BOT_KEY');
$configDbg = getenv('MG_BOT_DBG');
$mock = new MockHandler($response ?: []);
return new Client(
$url ?: $configUrl,
$key ?: $configKey,
$debug ?: $configDbg
$debug ?: $configDbg,
empty($response) ? null : HandlerStack::create($mock)
);
}
/**
* Returns mocked GuzzleHttp response
*
* @param string|null $body HTTP Body
* @param int $statusCode HTTP status code
*
* @return Response
*/
public function getResponse(string $body = null, int $statusCode = 200)
{
return new Response(
$statusCode,
array_filter(
[
'Server' => 'openresty/1.13.6.2',
'Date' => gmdate("D, d M Y H:m:s \G\M\T"),
'Content-Type' => 'application/json; charset=utf-8',
'Content-Length' => is_null($body) ? null : strlen($body),
'Connection' => 'keep-alive',
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Allow-Headers' => 'X-Requested-With, Content-Type, X-Api-Key, X-Client-Token',
'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS'
]
),
$body
);
}
/**
* Generate and return mocked response.
* Response data should be stored in Resources directory as json file.
* Only file name (without extension or any other data) should be provided,
* e.g. `getJsonResponse('bots', 200)`
*
* @param string $jsonFile mocked body
* @param int $statusCode mocked status code
*
* @return Response|null
*/
public function getJsonResponse(string $jsonFile, int $statusCode = 200)
{
$fileName = realpath(
join(
DIRECTORY_SEPARATOR,
[__DIR__, '..', '..', 'Resources', \sprintf('%s.json', $jsonFile)]
)
);
if (file_exists($fileName)) {
$json = file_get_contents($fileName);
json_decode($json, true);
if (json_last_error() == JSON_ERROR_NONE) {
return $this->getResponse($json, $statusCode);
}
} else {
return null;
}
}
/**
* @param int $statusCode response code
* @param array ...$errors response errors
*
* @return Response
*/
public function getErrorsResponse(int $statusCode = 400, ...$errors)
{
$json = ['errors' => []];
foreach ($errors as $error) {
$json['errors'][] = is_string($error) ? $error : null;
}
return $this->getResponse(json_encode(array_filter($json)), $statusCode);
}
/**
* Generate and return empty response
*
* @param int $statusCode HTTP status code
*
* @return Response|null
*/
public function getEmptyResponse(int $statusCode = 200)
{
return $this->getResponse(null, $statusCode);
}
}

View file

@ -6,6 +6,7 @@
* Dialogs Test
*
* @package RetailCrm\Mg\Bot\Tests
* @category Test
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
@ -25,9 +26,9 @@ use RetailCrm\Mg\Bot\Test\TestCase;
* Class DialogsTest
*
* @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
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class DialogsTest extends TestCase
{