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

update models, update tests, update travis

This commit is contained in:
Alex Lushpai 2019-07-16 14:01:42 +03:00
parent 9313660225
commit 6a1d128038
86 changed files with 800 additions and 1322 deletions

View file

@ -1,7 +1,3 @@
<<<<<<< HEAD
MG_BOT_URL="https://mg-test.retailcrm.pro/"
=======
MG_BOT_URL=""
>>>>>>> b8db7fa... move validator call to Request
MG_BOT_URL="https://mg-s1.retailcrm.pro/"
MG_BOT_KEY=""
MG_BOT_DBG=""

View file

@ -5,7 +5,6 @@ cache:
- $HOME/.composer/cache
php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
@ -15,3 +14,6 @@ before_script:
- composer install $flags
script: make travis
after_success:
- bash <(curl -s https://codecov.io/bash)

View file

@ -1,6 +1,6 @@
ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SRC_DIR=$(ROOT_DIR)/src
BIN_DIR=$(ROOT_DIR)/bin
BIN_DIR=$(ROOT_DIR)/vendor/bin
test:
@echo "==> Running tests"

View file

@ -1,6 +1,13 @@
<<<<<<< HEAD
[![Build Status](https://img.shields.io/travis/retailcrm/mg-bot-api-client-php/master.svg?style=flat-square)](https://travis-ci.org/retailcrm/mg-bot-api-client-php)
[![Latest stable](https://img.shields.io/packagist/v/retailcrm/mg-bot-api-client-php.svg?style=flat-square)](https://packagist.org/packages/retailcrm/mg-bot-api-client-php)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/mg-bot-retailcrm/api-client-php.svg?style=flat-square)](https://packagist.org/packages/retailcrm/mg-bot-api-client-php)
=======
[![Build Status](https://img.shields.io/travis/retailcrm/mg-bot-api-client-php /master.svg?style=flat-square)](https://travis-ci.org/retailcrm/mg-bot-api-client-php )
[![Covarage](https://img.shields.io/codecov/c/gh/retailcrm/mg-bot-api-client-php /master.svg?style=flat-square)](https://codecov.io/gh/retailcrm/mg-bot-api-client-php )
[![Latest stable](https://img.shields.io/packagist/v/retailcrm/mg-bot-api-client-php .svg?style=flat-square)](https://packagist.org/packages/retailcrm/mg-bot-api-client-php )
[![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 )
>>>>>>> af44f8a... update models, update tests, update travis
# retailCRM API PHP client
@ -9,7 +16,7 @@ This is php retailCRM MG Bot API client.
## Requirements
* PHP 7.0 and above
* PHP 7.1 and above
* PHP's cURL support
* PHP's JSON support

View file

@ -1,32 +0,0 @@
extensions:
- php
source:
- src
exclude:
- tests/
- vendor/
- bin/
- docs/
charset:
- auto
- UTF-8
- Windows-1251
title: retailCRM PHP MG Bot API client
templateTheme: bootstrap
groups: auto
accessLevels:
- public
- protected
internal: true
php: false
tree: true
deprecated: true
todo: true
destination: ../mg-bot-api-client-php.pages/
download: false

View file

@ -12,7 +12,7 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.1",
"ext-curl": "*",
"ext-json": "*",
"jms/serializer": "1.14.*",
@ -63,7 +63,7 @@
}
},
"config": {
"bin-dir": "bin",
"bin-dir": "vendor/bin",
"process-timeout": 600
}
}

12
composer.lock generated
View file

@ -171,7 +171,11 @@
"type": "library",
"extra": {
"branch-alias": {
<<<<<<< HEAD
"dev-master": "1.0.x-dev"
=======
"dev-master": "1.2.x-dev"
>>>>>>> af44f8a... update models, update tests, update travis
}
},
"autoload": {
@ -191,12 +195,20 @@
}
],
"description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
<<<<<<< HEAD
"homepage": "https://github.com/doctrine/instantiator",
=======
"homepage": "https://www.doctrine-project.org/projects/instantiator.html",
>>>>>>> af44f8a... update models, update tests, update travis
"keywords": [
"constructor",
"instantiate"
],
<<<<<<< HEAD
"time": "2015-06-14T21:17:01+00:00"
=======
"time": "2019-03-17T17:37:11+00:00"
>>>>>>> af44f8a... update models, update tests, update travis
},
{
"name": "doctrine/lexer",

View file

@ -8,10 +8,10 @@ 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';
$loader = require $autoloadFile;
AnnotationRegistry::registerLoader('class_exists');

View file

@ -1,22 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
bootstrap="./tests/bootstrap.php"
colors="true"
verbose="true"
processIsolation="false"
stopOnFailure="false">
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
backupGlobals="false"
colors="false"
bootstrap="tests/bootstrap.php"
backupStaticAttributes="false"
convertErrorsToExceptions="false"
convertNoticesToExceptions="false"
convertWarningsToExceptions="false"
processIsolation="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
>
<testsuites>
<testsuite name="RetailCrm">
<directory>tests/Bot/Tests</directory>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/Bot</directory>
<directory>src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="clover.xml"/>
<log type="junit" target="/tmp/logfile.xml"/>
</logging>
</phpunit>

View file

@ -0,0 +1,87 @@
<?php
/**
* PHP version 7.1
*
* ModelAdapter
*
* @package RetailCrm\Mg\Bot\Adapter
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Adapter;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Common\Serializer;
use RetailCrm\Mg\Bot\Model\Response;
/**
* Class ModelAdapter
*
* @package RetailCrm\Mg\Bot\Adapter
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ModelAdapter
{
/**
* @var mixed $model
*/
private $model;
/**
* @var string $classname
*/
private $classname;
/**
* ModelAdapter constructor.
*
* @param string $classname
*
*/
public function __construct(string $classname)
{
$this->model = new $classname;
$this->classname = $classname;
}
/**
* Get Response Model
*
* @param \RetailCrm\Mg\Bot\Model\Response $response
*
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
*/
public function getResponseModel(Response $response)
{
return Serializer::deserialize($response->getBody(), $this->model);
}
/**
* Get Response List
*
* @param \RetailCrm\Mg\Bot\Model\Response $response
*
* @return array
*/
public function getResponseList(Response $response)
{
$array = json_decode($response->getBody(), true);
if (json_last_error() != JSON_ERROR_NONE) {
throw new InvalidJsonException('Received invalid JSON', 1);
}
$result = [];
foreach ($array as $item) {
$result[] = Serializer::deserialize($item, $this->classname, Serializer::S_ARRAY);
}
return $result;
}
}

View file

@ -0,0 +1,61 @@
<?php
/**
* PHP version 7.1
*
* Response adapter
*
* @package RetailCrm\Mg\Bot\Adapter
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Adapter;
use Psr\Http\Message\ResponseInterface;
use RetailCrm\Mg\Bot\Model\Response;
/**
* Class ResponseAdapter
*
* @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 ResponseAdapter
{
/**
* @var \RetailCrm\Mg\Bot\Model\Response $model
*/
private $model;
/**
* @var \Psr\Http\Message\ResponseInterface $interface
*/
private $interface;
/**
* ResponseAdapter constructor.
*
* @param \Psr\Http\Message\ResponseInterface $interface
*/
public function __construct(ResponseInterface $interface)
{
$this->interface = $interface;
$this->model = new Response();
}
/**
* Build response
*
* @return \RetailCrm\Mg\Bot\Model\Response
*/
public function build(): Response
{
$this->model->setStatus($this->interface->getStatusCode());
$this->model->setBody((string) $this->interface->getBody());
return $this->model;
}
}

View file

@ -1,42 +1,47 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Client
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
* @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;
use Psr\Http\Message\ResponseInterface;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Common\Url;
use RetailCrm\Common\Serializer;
<<<<<<< HEAD
use RetailCrm\Mg\Bot\Adapter\ModelAdapter;
use RetailCrm\Mg\Bot\Model\Entity\Bot;
use RetailCrm\Mg\Bot\Model\Entity\Channel\Channel;
use RetailCrm\Mg\Bot\Model\Entity\Chat\Chat;
use RetailCrm\Mg\Bot\Model\Entity\Chat\ChatMember;
use RetailCrm\Mg\Bot\Model\Entity\Command;
use RetailCrm\Mg\Bot\Model\Entity\Customer;
use RetailCrm\Mg\Bot\Model\Entity\Dialog;
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\ErrorOnlyResponse;
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
use RetailCrm\Mg\Bot\Model\Response\ListResponse;
use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse;
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
* Class Client
*
* Client 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
* @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 Client
{
@ -45,11 +50,6 @@ class Client
*/
const VERSION = 'v1';
/**
* @internal
*/
const ERROR_ONLY_RESPONSE = 'ErrorOnlyResponse';
/**
* @var HttpClient
*/
@ -58,111 +58,15 @@ class Client
/**
* Init
*
* @param string $url MG API URL
* @param string $token MG API Key
* @param bool $debug Enable or disable debug mode - will log all requests to STDOUT (default: false)
* @param string $url MG API URL
* @param string $token MG API Key
* @param bool $debug Enable or disable debug mode - will log all requests to STDOUT (default: false)
* @param \GuzzleHttp\HandlerStack $handler GuzzleHttp::HandlerStack instance (default: null)
*/
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
}
/**
* @param string $path
* @param string $method
* @param object|null $request Request parameters
* @param string $responseType
* @param bool $arrayOfObjects
*
* @return object|null
* @throws \Exception
*/
private function submitRequest(
$path,
$method,
$request,
$responseType,
$arrayOfObjects = false
) {
$response = $this->client->makeRequest(
$path,
$method,
$request
);
$statusCode = $response->getStatusCode();
$data = json_decode((string) $response->getBody(), true);
if (json_last_error() == JSON_ERROR_NONE) {
if ($arrayOfObjects) {
return new ListResponse($responseType, $data, $statusCode);
} else {
$obj = Serializer::deserialize($data, $responseType, Serializer::S_ARRAY);
if ($statusCode >= 400
&& method_exists($obj, 'setErrors')
&& method_exists($obj, 'getErrors')
&& count(call_user_func([$obj, 'getErrors'])) == 0
) {
call_user_func_array([$obj, 'setErrors'], [['Status Code ' . $response->getStatusCode()]]);
}
if (method_exists($obj, 'setStatusCode')) {
call_user_func_array([$obj, 'setStatusCode'], [$statusCode]);
}
return $obj;
}
} else {
throw new InvalidJsonException('Received invalid JSON', 1);
}
}
/**
* @param bool $fromRoot
* @param string ...$classes
*
* @return string
*/
private static function concatClasspath($fromRoot, ...$classes)
{
$path = '';
foreach ($classes as $class) {
if (empty($path) && !$fromRoot) {
$path .= $class;
} else {
$path .= '\\' . $class;
}
}
return $path;
}
/**
* @param string ...$classes
*
* @return string
*/
private static function getEntityClass(...$classes)
{
return static::concatClasspath(true, 'RetailCrm', 'Mg', 'Bot', 'Model', 'Entity', ...$classes);
}
/**
* @param string ...$classes
*
* @return string
*/
private static function getResponseClass(...$classes)
{
return static::concatClasspath(true, 'RetailCrm', 'Mg', 'Bot', 'Model', 'Response', ...$classes);
}
/**
@ -170,55 +74,41 @@ class Client
*
* @param Model\Request\BotsRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function bots(Model\Request\BotsRequest $request)
public function bots(Model\Request\BotsRequest $request): array
{
<<<<<<< HEAD
return $this->submitRequest(
$response = $this->client->makeRequest(
'/bots',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Bot'),
true
$request
);
=======
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
$adapter = new ModelAdapter(Bot::class);
return $adapter->getResponseList($response);
}
/**
* Edit bot info
*
<<<<<<< HEAD
* @param Model\Request\InfoRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function info(Model\Request\InfoRequest $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/my/info',
HttpClient::METHOD_PATCH,
$request,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
$request
);
=======
* @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
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -226,22 +116,20 @@ class Client
*
* @param Model\Request\ChannelsRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function channels(Model\Request\ChannelsRequest $request)
public function channels(Model\Request\ChannelsRequest $request): array
{
<<<<<<< HEAD
return $this->submitRequest(
$response = $this->client->makeRequest(
'/channels',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Channel', 'Channel'),
true
$request
);
=======
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
$adapter = new ModelAdapter(Channel::class);
return $adapter->getResponseList($response);
}
/**
@ -249,22 +137,20 @@ class Client
*
* @param Model\Request\ChatsRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function chats(Model\Request\ChatsRequest $request)
public function chats(Model\Request\ChatsRequest $request): array
{
<<<<<<< HEAD
return $this->submitRequest(
$response = $this->client->makeRequest(
'/chats',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Chat', 'Chat'),
true
$request
);
=======
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
$adapter = new ModelAdapter(Chat::class);
return $adapter->getResponseList($response);
}
/**
@ -272,22 +158,20 @@ class Client
*
* @param Model\Request\CommandsRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function commands(Model\Request\CommandsRequest $request)
public function commands(Model\Request\CommandsRequest $request): array
{
<<<<<<< HEAD
return $this->submitRequest(
$response = $this->client->makeRequest(
'/my/commands',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Command'),
true
$request
);
=======
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
$adapter = new ModelAdapter(Command::class);
return $adapter->getResponseList($response);
}
/**
@ -295,17 +179,20 @@ class Client
*
* @param Model\Request\CommandEditRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function commandEdit(Model\Request\CommandEditRequest $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/my/commands/%s", $request->getName()),
HttpClient::METHOD_PUT,
$request,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
$request
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -313,21 +200,19 @@ class Client
*
* @param string $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function commandDelete(string $request)
{
<<<<<<< HEAD
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/my/commands/%s", $request),
HttpClient::METHOD_DELETE,
null,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
HttpClient::METHOD_DELETE
);
=======
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
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -335,22 +220,20 @@ class Client
*
* @param Model\Request\CustomersRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function customers(Model\Request\CustomersRequest $request)
public function customers(Model\Request\CustomersRequest $request): array
{
<<<<<<< HEAD
return $this->submitRequest(
$response = $this->client->makeRequest(
'/customers',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Customer'),
true
$request
);
=======
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
$adapter = new ModelAdapter(Customer::class);
return $adapter->getResponseList($response);
}
/**
@ -358,20 +241,11 @@ class Client
*
* @param Model\Request\DialogsRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function dialogs(Model\Request\DialogsRequest $request)
public function dialogs(Model\Request\DialogsRequest $request): array
{
<<<<<<< HEAD
return $this->submitRequest(
'/dialogs',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Dialog'),
true
);
=======
return $this->client->makeRequest('/dialogs', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
@ -411,7 +285,6 @@ class Client
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
}
/**
@ -419,17 +292,20 @@ class Client
*
* @param Model\Request\DialogAssignRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\AssignResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function dialogAssign(Model\Request\DialogAssignRequest $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/dialogs/%d/assign", $request->getDialogId()),
HttpClient::METHOD_PATCH,
$request,
static::getResponseClass('AssignResponse')
$request
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -437,17 +313,20 @@ class Client
*
* @param string $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function dialogClose(string $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/dialogs/%d/close", $request),
HttpClient::METHOD_DELETE,
null,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
null
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -455,22 +334,20 @@ class Client
*
* @param Model\Request\MembersRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function members(Model\Request\MembersRequest $request)
public function members(Model\Request\MembersRequest $request): array
{
<<<<<<< HEAD
return $this->submitRequest(
$response = $this->client->makeRequest(
'/members',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Chat', 'ChatMember'),
true
$request
);
=======
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
$adapter = new ModelAdapter(ChatMember::class);
return $adapter->getResponseList($response);
}
/**
@ -478,20 +355,11 @@ class Client
*
* @param Model\Request\MessagesRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function messages(Model\Request\MessagesRequest $request)
public function messages(Model\Request\MessagesRequest $request): array
{
<<<<<<< HEAD
return $this->submitRequest(
'/messages',
HttpClient::METHOD_GET,
$request,
self::getEntityClass('Message', 'Message'),
true
);
=======
return $this->client->makeRequest('/messages', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
@ -544,7 +412,6 @@ class Client
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
}
/**
@ -552,17 +419,20 @@ class Client
*
* @param Model\Request\MessageSendRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\MessageSendResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function messageSend(Model\Request\MessageSendRequest $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/messages',
HttpClient::METHOD_POST,
$request,
static::getResponseClass('MessageSendResponse')
$request
);
$adapter = new ModelAdapter(MessageSendResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -570,17 +440,20 @@ class Client
*
* @param Model\Request\MessageEditRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\MessageSendResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function messageEdit(Model\Request\MessageEditRequest $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/messages/%d", $request->getId()),
HttpClient::METHOD_PATCH,
$request,
static::getResponseClass('MessageSendResponse')
$request
);
$adapter = new ModelAdapter(MessageSendResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -588,17 +461,20 @@ class Client
*
* @param string $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function messageDelete(string $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/messages/%d", $request),
HttpClient::METHOD_DELETE,
null,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
null
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -606,19 +482,20 @@ class Client
*
* @param Model\Request\UsersRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function users(Model\Request\UsersRequest $request)
public function users(Model\Request\UsersRequest $request): array
{
<<<<<<< HEAD
return $this->submitRequest(
$response = $this->client->makeRequest(
'/users',
HttpClient::METHOD_GET,
$request,
self::getEntityClass('User'),
true
$request
);
$adapter = new ModelAdapter(User::class);
return $adapter->getResponseList($response);
}
/**
@ -626,7 +503,7 @@ class Client
*
* @param string $url File URL
*
* @return \RetailCrm\Mg\Bot\Model\Response\UploadFileResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function uploadFileByUrl(string $url)
@ -634,54 +511,54 @@ class Client
$request = new UploadFileByUrlRequest();
$request->setUrl($url);
return $this->submitRequest(
$response = $this->client->makeRequest(
'/files/upload_by_url',
HttpClient::METHOD_POST,
$request,
self::getResponseClass('UploadFileResponse')
$request
);
$adapter = new ModelAdapter(UploadFileResponse::class);
return $adapter->getResponseModel($response);
}
/**
* @param string $filename
* @return Model\Response\UploadFileResponse|null
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
*
* @throws \Exception
*/
public function uploadFile(string $filename)
{
$obj = new ErrorOnlyResponse();
$response = $this->client->postFile($filename);
if ($response instanceof ResponseInterface) {
$obj = Serializer::deserialize(
(string) $response->getBody(),
self::getResponseClass('UploadFileResponse')
UploadFileResponse::class
);
return $obj instanceof UploadFileResponse ? $obj : null;
}
return null;
return $obj;
}
/**
* @param string $fileId
* @return Model\Response\FullFileResponse|null
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
*
* @throws \Exception
*/
public function getFileById(string $fileId)
{
$obj = $this->submitRequest(
\sprintf('/files/%s', $fileId),
$response = $this->client->makeRequest(
sprintf('/files/%s', $fileId),
HttpClient::METHOD_GET,
null,
self::getResponseClass('FullFileResponse')
null
);
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
$adapter = new ModelAdapter(FullFileResponse::class);
return $adapter->getResponseModel($response);
}
}

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* HttpClient
*
@ -13,11 +13,18 @@
namespace RetailCrm\Mg\Bot;
use BadMethodCallException;
use ErrorException;
use Exception;
use InvalidArgumentException;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Common\Exception\LimitException;
use InvalidArgumentException;
use RetailCrm\Common\Exception\NotFoundException;
use RetailCrm\Common\Exception\UnauthorizedException;
use RetailCrm\Common\Serializer;
use RetailCrm\Common\Url;
use RetailCrm\Mg\Bot\Adapter\ResponseAdapter;
use RuntimeException;
use Symfony\Component\Validator\Validation;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
@ -26,9 +33,7 @@ use Psr\Http\Message\ResponseInterface;
use function GuzzleHttp\Psr7\stream_for;
/**
* PHP version 7.0
*
* HttpClient class
* Class HttpClient
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
@ -107,7 +112,7 @@ class HttpClient
* @param string $method Request method (default: 'GET')
* @param mixed $request Request model (default: null)
*
* @return ResponseInterface
* @return \RetailCrm\Mg\Bot\Model\Response
* @throws \Exception
*/
public function makeRequest($path, $method, $request = null)
@ -121,20 +126,20 @@ class HttpClient
}
if ($method == self::METHOD_GET && !is_null($request)) {
$getParameters = Url::buildGetParameters(Serializer::serialize($request, Serializer::S_ARRAY));
$getParameters = Url::buildGetParameters((array)Serializer::serialize($request, Serializer::S_ARRAY));
}
$requestBody = is_null($request) ? null : Serializer::serialize($request, Serializer::S_JSON);
$requestBody = is_null($request) ? '' : Serializer::serialize($request, Serializer::S_JSON);
$request = new Request(
$method,
\sprintf("%s%s%s", $this->basePath, $path, $getParameters),
sprintf("%s%s%s", $this->basePath, $path, $getParameters),
[
'Content-Type' => 'application/json',
'X-Bot-Token' => $this->token
]
);
if (in_array($method, [self::METHOD_POST, self::METHOD_PUT, self::METHOD_PATCH, self::METHOD_DELETE])) {
if (in_array($method, [self::METHOD_POST, self::METHOD_PUT, self::METHOD_PATCH, self::METHOD_DELETE]) && is_string($requestBody)) {
$request = $request->withBody(stream_for($requestBody));
}
@ -151,27 +156,14 @@ class HttpClient
]
);
} catch (GuzzleException $exception) {
throw new \Exception($exception->getMessage(), $exception->getCode(), $exception);
throw new Exception($exception->getMessage(), $exception->getCode(), $exception);
}
$statusCode = $responseObject->getStatusCode();
$response = self::parseJSON((string) $responseObject->getBody());
$errorMessage = !empty($response['errorMsg']) ? $response['errorMsg'] : '';
$errorMessage = !empty($response['errors']) ? $this->getErrors($response['errors']) : $errorMessage;
$this->validateResponse($responseObject);
/**
* responses with 400 & 460 http codes contains extended error data
* therefore they are not handled as exceptions
*/
if (in_array($statusCode, [403, 404, 500])) {
throw new \InvalidArgumentException($errorMessage);
}
$adapter = new ResponseAdapter($responseObject);
if ($statusCode == 503) {
throw new LimitException($errorMessage);
}
return $responseObject;
return $adapter->build();
}
/**
@ -183,17 +175,17 @@ class HttpClient
public function postFile(string $filename)
{
if (!file_exists($filename)) {
throw new \InvalidArgumentException("File doesn't exist");
throw new InvalidArgumentException("File doesn't exist");
}
if (filesize($filename) == 0) {
throw new \InvalidArgumentException("Empty file provided");
throw new InvalidArgumentException("Empty file provided");
}
try {
$responseData = $this->client->request(
self::METHOD_POST,
\sprintf("%s/files/upload", $this->basePath),
sprintf("%s/files/upload", $this->basePath),
[
'headers' => [
'X-Bot-Token' => $this->token
@ -202,7 +194,7 @@ class HttpClient
]
);
} catch (GuzzleException $exception) {
throw new \Exception($exception->getMessage(), $exception->getCode(), $exception);
throw new Exception($exception->getMessage(), $exception->getCode(), $exception);
}
return isset($responseData) ? $responseData : null;
@ -235,19 +227,62 @@ class HttpClient
*/
private function validateRequest($class)
{
if (!is_string($class) && method_exists($class, 'validate')) {
$errors = $class->validate();
} else {
$validator = Validation::createValidatorBuilder()
->enableAnnotationMapping()
->getValidator();
$validator = Validation::createValidatorBuilder()
->enableAnnotationMapping()
->getValidator();
$errors = $validator->validate($class);
$errors = $validator->validate($class);
if ($errors->count() > 0) {
$message = '';
foreach ($errors as $error) {
$message .= (string)$error;
}
throw new InvalidArgumentException($message);
}
}
/**
* @param \Psr\Http\Message\ResponseInterface $responseObject
*
* @throws \ErrorException
*/
private function validateResponse(ResponseInterface $responseObject)
{
$statusCode = $responseObject->getStatusCode();
$response = self::parseJSON((string)$responseObject->getBody());
$errorMessage = !empty($response['errorMsg']) ? $response['errorMsg'] : '';
$errorMessage = !empty($response['errors']) ? $this->getErrors($response['errors']) : $errorMessage;
/**
* responses with 400 & 460 http codes contains extended error data
* therefore they are not handled as exceptions
*/
if ($statusCode == 400) {
throw new RuntimeException($errorMessage);
}
if ((is_object($errors) && call_user_func([$errors, 'count']) > 0) || is_string($errors)) {
$message = (string) $errors;
throw new InvalidArgumentException($message);
if (in_array($statusCode, [401, 403])) {
throw new UnauthorizedException($errorMessage);
}
if ($statusCode == 404) {
throw new NotFoundException($errorMessage);
}
if (in_array($statusCode, [405, 501])) {
throw new BadMethodCallException($errorMessage);
}
if (in_array($statusCode, [500, 502])) {
throw new ErrorException($errorMessage);
}
if ($statusCode == 503) {
throw new LimitException($errorMessage);
}
}

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Constants
*
@ -14,8 +14,6 @@
namespace RetailCrm\Mg\Bot\Model;
/**
* PHP version 7.0
*
* Constants class
*
* @package RetailCrm\Mg\Bot\Model

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Bot entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Bot class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Bot
class Bot implements ModelInterface
{
/**
* @var string $id

View file

@ -1,33 +1,32 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Channel entity
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @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\Channel;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use DateTime;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
* Class Channel
*
* Channel class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Channel
class Channel implements ModelInterface
{
/**
* @var string $id
@ -120,7 +119,7 @@ class Channel
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
@ -128,7 +127,7 @@ class Channel
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
public function setCreatedAt(DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
@ -136,7 +135,7 @@ class Channel
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
public function getUpdatedAt(): DateTime
{
return $this->updatedAt;
}
@ -144,7 +143,7 @@ class Channel
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
public function setUpdatedAt(DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
@ -152,7 +151,7 @@ class Channel
/**
* @return \DateTime
*/
public function getActivatedAt(): \DateTime
public function getActivatedAt(): DateTime
{
return $this->activatedAt;
}
@ -160,7 +159,7 @@ class Channel
/**
* @param \DateTime $activatedAt
*/
public function setActivatedAt(\DateTime $activatedAt)
public function setActivatedAt(DateTime $activatedAt)
{
$this->activatedAt = $activatedAt;
}
@ -168,7 +167,7 @@ class Channel
/**
* @return \DateTime
*/
public function getDeactivatedAt(): \DateTime
public function getDeactivatedAt(): DateTime
{
return $this->deactivatedAt;
}
@ -176,7 +175,7 @@ class Channel
/**
* @param \DateTime $deactivatedAt
*/
public function setDeactivatedAt(\DateTime $deactivatedAt)
public function setDeactivatedAt(DateTime $deactivatedAt)
{
$this->deactivatedAt = $deactivatedAt;
}

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ChannelSettings entity
*
@ -16,18 +16,17 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChannelSettings class
* Class ChannelSettings
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelSettings
class ChannelSettings implements ModelInterface
{
/**
* @var ChannelSettingsStatus $status

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ChannelSettingsItem entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChannelSettingsItem class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelSettingsItem
class ChannelSettingsItem implements ModelInterface
{
/**
* @var string $creating

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ChannelSettingsStatus entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChannelSettingsStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelSettingsStatus
class ChannelSettingsStatus implements ModelInterface
{
/**
* @var string $delivered

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Chat entity
*
@ -18,10 +18,9 @@ use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Customer;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Chat class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
@ -29,7 +28,7 @@ use RetailCrm\Mg\Bot\Model\Entity\Customer;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Chat
class Chat implements ModelInterface
{
/**
* @var string $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ChatLastMessage entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Chat;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChatLastMessage class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChatLastMessage
class ChatLastMessage implements ModelInterface
{
/**
* @var int $creating

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ChatMember entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Chat;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChatMember class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChatMember
class ChatMember implements ModelInterface
{
/**
* @var string $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Command entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Command class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Command
class Command implements ModelInterface
{
/**
* @var string $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Cost entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Cost class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Cost
class Cost implements ModelInterface
{
/**
* @var float $value

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Customer entity
*
@ -13,23 +13,21 @@
namespace RetailCrm\Mg\Bot\Model\Entity;
use RetailCrm\Mg\Bot\Model\ModelInterface;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Customer class
* | email | string |
*
* @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 Customer
class Customer implements ModelInterface
{
/**
* @var string $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Delivery entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Delivery class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Delivery
class Delivery implements ModelInterface
{
/**
* @var string $name

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Dialog entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Dialog class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Dialog
class Dialog implements ModelInterface
{
/**
* @var string $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* FileMeta entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* FileMeta class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class FileMeta
class FileMeta implements ModelInterface
{
/**
* @var int $height

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Item entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Item class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Item
class Item implements ModelInterface
{
/**
* @var string $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Item entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Item class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Item
class Item implements ModelInterface
{
/**
* @var string $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Message entity
*
@ -18,10 +18,9 @@ use RetailCrm\Mg\Bot\Model\Entity\User;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Message class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -29,7 +28,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Message
class Message implements ModelInterface
{
/**
* @var string $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageCost entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageCost class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageCost
class MessageCost implements ModelInterface
{
/**
* @var float $value

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageDelivery entity
*
@ -16,11 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageCost;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageDelivery class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -28,7 +26,7 @@ use RetailCrm\Mg\Bot\Model\Entity\Message\MessageCost;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageDelivery
class MessageDelivery implements ModelInterface
{
/**
* @var string $name

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageOrder entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageOrder class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageOrder
class MessageOrder implements ModelInterface
{
/**
* @var string $number

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0.
* PHP version 7.1
*
* MessageOrderItem entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0.
*
* MessageOrderItem class
*
* @author retailCRM <integration@retailcrm.ru>
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
*
* @see http://help.retailcrm.pro/docs/Developers
*/
class MessageOrderItem
class MessageOrderItem implements ModelInterface
{
/**
* @var string

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageOrderPaymentStatus entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageOrderPaymentStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageOrderPaymentStatus
class MessageOrderPaymentStatus implements ModelInterface
{
/**
* @var string $name

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessagePayment entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessagePayment class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessagePayment
class MessagePayment implements ModelInterface
{
/**
* @var string $name

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageProduct entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageProduct class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageProduct
class MessageProduct implements ModelInterface
{
/**
* @var int $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageQuantity entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageQuantity class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageQuantity
class MessageQuantity implements ModelInterface
{
/**
* @var float $value

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageStatus entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageStatus
class MessageStatus implements ModelInterface
{
/**
* @var string $code

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Order entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Order class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Order
class Order implements ModelInterface
{
/**
* @var string $number

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Order item entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* OrderItem class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class OrderItem
class OrderItem implements ModelInterface
{
/**
* @var string $name

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Payment entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Payment class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Payment
class Payment implements ModelInterface
{
/**
* @var string $name

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Payment status entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* PaymentStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class PaymentStatus
class PaymentStatus implements ModelInterface
{
/**
* @var string $name

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Product entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Product class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Product
class Product implements ModelInterface
{
/**
* @var int $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Quantity entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Quantity class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Quantity
class Quantity implements ModelInterface
{
/**
* @var float $value

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Responsible entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Responsible class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Responsible
class Responsible implements ModelInterface
{
/**
* @var string $assignedAt

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Status entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Status class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Status
class Status implements ModelInterface
{
/**
* @var string $code

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* User entity
*
@ -13,14 +13,13 @@
namespace RetailCrm\Mg\Bot\Model\Entity;
use RetailCrm\Mg\Bot\Model\ModelInterface;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* User class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -28,7 +27,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class User
class User implements ModelInterface
{
/**
* @var string $id

View file

@ -0,0 +1,18 @@
<?php
/**
* PHP version 7.1
*
* ModelInterface
*
* @package RetailCrm\Mg\Bot\Model
* @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;
interface ModelInterface
{
}

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Bots Request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* BotsRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class BotsRequest
class BotsRequest implements ModelInterface
{
use CommonFields;

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Channels list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChannelsRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelsRequest
class ChannelsRequest implements ModelInterface
{
use CommonFields;

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Chats list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChatsRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChatsRequest
class ChatsRequest implements ModelInterface
{
use CommonFields;

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Edit Command Request
*
@ -13,15 +13,12 @@
namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* CommandEditRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -29,7 +26,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class CommandEditRequest
class CommandEditRequest implements ModelInterface
{
/**
* @var int $botId

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Commands list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* CommandsRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class CommandsRequest
class CommandsRequest implements ModelInterface
{
use CommonFields;

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Common fields
*
@ -18,8 +18,6 @@ use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* CommonFields trait
*
* @package RetailCrm\Mg\Bot\Model\Request

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Customers list request
*
@ -16,11 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Request\CommonFields;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* CustomersRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -28,7 +26,7 @@ use RetailCrm\Mg\Bot\Model\Request\CommonFields;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class CustomersRequest
class CustomersRequest implements ModelInterface
{
use CommonFields;

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Dialog assign request
*
@ -17,10 +17,9 @@ use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* DialogAssignRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -28,7 +27,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class DialogAssignRequest
class DialogAssignRequest implements ModelInterface
{
/**
* @var int $dialogId

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Dialogs list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* DialogsRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class DialogsRequest
class DialogsRequest implements ModelInterface
{
use CommonFields;

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Bot info request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* InfoRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class InfoRequest
class InfoRequest implements ModelInterface
{
/**
* @var string $name

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Members list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MembersRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MembersRequest
class MembersRequest implements ModelInterface
{
/**
* @var int $chatId

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Messages edit request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageEditRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageEditRequest
class MessageEditRequest implements ModelInterface
{
/**
* @var int $id

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Messages send request
*
@ -18,13 +18,10 @@ use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageOrder;
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageProduct;
use RetailCrm\Mg\Bot\Model\ModelInterface;
use Symfony\Component\Validator\Constraints as Assert;
use RetailCrm\Mg\Bot\Model\Entity\Order;
use RetailCrm\Mg\Bot\Model\Entity\Product;
/**
* PHP version 7.0
*
* MessageSendRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -32,7 +29,7 @@ use RetailCrm\Mg\Bot\Model\Entity\Product;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageSendRequest
class MessageSendRequest implements ModelInterface
{
/**
* @var string $type

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Messages list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessagesRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessagesRequest
class MessagesRequest implements ModelInterface
{
use CommonFields;

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Upload file by url request
*
@ -15,11 +15,10 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* PHP version 7.0
*
* UploadFileByUrlRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class UploadFileByUrlRequest
class UploadFileByUrlRequest implements ModelInterface
{
/**
* @var string $url

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Users list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* UsersRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class UsersRequest
class UsersRequest implements ModelInterface
{
use CommonFields;

View file

@ -0,0 +1,57 @@
<?php
/**
* PHP version 7.1
*
* ModelInterface
*
* @package RetailCrm\Mg\Bot\Model
* @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;
/**
* Class Response
*
* @package RetailCrm\Mg\Bot\Model
*/
class Response
{
private $status;
private $body;
/**
* @return mixed
*/
public function getStatus()
{
return $this->status;
}
/**
* @param mixed $status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* @return mixed
*/
public function getBody()
{
return $this->body;
}
/**
* @param mixed $body
*/
public function setBody($body)
{
$this->body = $body;
}
}

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* AssignResponse
*
@ -17,10 +17,9 @@ 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;
/**
* PHP version 7.0
*
* AssignResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -28,7 +27,7 @@ use RetailCrm\Mg\Bot\Model\Entity\Responsible;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class AssignResponse
class AssignResponse implements ModelInterface
{
use CommonFields;

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ErrorTrait
*
@ -19,8 +19,6 @@ use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* CommonFields trait
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -50,7 +48,7 @@ trait CommonFields
*/
public function getErrors(): array
{
return is_null($this->errors) ? [] : $this->errors;
return empty($this->errors) ? [] : $this->errors;
}
/**

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ErrorOnlyResponse
*
@ -13,9 +13,9 @@
namespace RetailCrm\Mg\Bot\Model\Response;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ErrorOnlyResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -23,7 +23,7 @@ namespace RetailCrm\Mg\Bot\Model\Response;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ErrorOnlyResponse
class ErrorOnlyResponse implements ModelInterface
{
use CommonFields;
}

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* FullFileResponse
*
@ -16,10 +16,9 @@ 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\ModelInterface;
/**
* PHP version 7.0
*
* FullFileResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class FullFileResponse
class FullFileResponse implements ModelInterface
{
use CommonFields;

View file

@ -1,202 +0,0 @@
<?php
/**
* PHP version 7.0
*
* ListResponse
*
* @package RetailCrm\Mg\Bot\Model\Response
* @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\Response;
use RetailCrm\Common\Serializer;
/**
* PHP version 7.0
*
* ListResponse class. Used to store multiple objects at once.
* Implements `Iterator`, `ArrayAccess` and `Countable`.
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ListResponse implements \Iterator, \ArrayAccess, \Countable
{
use CommonFields;
/**
* @var array
*/
private $items = [];
/**
* @var int
*/
private $position = 0;
/**
* ListResponse constructor.
*
* @param string $responseType
* @param array $data
* @param int $statusCode
*/
public function __construct($responseType, $data, $statusCode)
{
$this->setStatusCode($statusCode);
if (isset($data['errors'])) {
$this->setErrors($data['errors']);
} else {
foreach ($data as $item) {
$this->items[] =
Serializer::deserialize($item, $responseType, Serializer::S_ARRAY);
}
}
}
/**
* @return bool
*/
public function isSuccessful()
{
return empty($this->errors);
}
/**
* \Countable implementation
*
* @return int
*/
public function count(): int
{
return count($this->items ?: []);
}
/**
* Set offset
*
* @param mixed $offset offset value
* @param mixed $value value
*
* @return void
* @internal
*/
public function offsetSet($offset, $value)
{
throw new \BadMethodCallException(
"This call not allowed: offsetSet [$offset] [$value]"
);
}
/**
* Unset offset
*
* @param mixed $offset offset value
*
* @return void
* @internal
*/
public function offsetUnset($offset)
{
throw new \BadMethodCallException(
"This call not allowed: offsetSet [$offset]"
);
}
/**
* Check offset
*
* @param mixed $offset offset value
*
* @return bool
* @internal
*/
public function offsetExists($offset)
{
return isset($this->items[$offset]);
}
/**
* Get offset
*
* @param mixed $offset offset value
*
* @return mixed
* @internal
*/
public function offsetGet($offset)
{
if (!isset($this->items[$offset])) {
throw new \InvalidArgumentException("Item \"$offset\" not found");
}
return $this->items[$offset];
}
/**
* @param mixed $name
*
* @return mixed
* @internal
*/
public function __get($name)
{
return $this->items[$name];
}
/**
* Implements rewind() for Iterable
* @internal
*/
public function rewind()
{
$this->position = 0;
}
/**
* Implements current() for Iterable
*
* @internal
* @return mixed
*/
public function current()
{
return $this->items[$this->position];
}
/**
* Implements key() for Iterable
*
* @internal
* @return int|mixed
*/
public function key()
{
return $this->position;
}
/**
* Implements next() for Iterable
* @internal
*/
public function next()
{
++$this->position;
}
/**
* Implements valid() for Iterable
*
* @internal
* @return bool
*/
public function valid()
{
return isset($this->items[$this->position]);
}
}

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageSendResponse
*
@ -16,10 +16,9 @@ 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\ModelInterface;
/**
* PHP version 7.0
*
* MessageSendResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageSendResponse
class MessageSendResponse implements ModelInterface
{
use CommonFields;

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* UploadFileResponse
*
@ -17,10 +17,9 @@ use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\FileMeta;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* UploadFileResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -28,7 +27,7 @@ use RetailCrm\Mg\Bot\Model\Entity\FileMeta;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class UploadFileResponse
class UploadFileResponse implements ModelInterface
{
use CommonFields;

View file

@ -1,205 +0,0 @@
<?php
/**
* PHP version 7.0
*
* Request
*
* @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;
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;
/**
* PHP version 7.0
*
* Request 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 Request
{
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
const METHOD_PATCH = 'PATCH';
const METHOD_DELETE = 'DELETE';
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 bool|resource $stdout default output for debug
*/
public function __construct($url, $token, $debug, $stdout = STDOUT)
{
if (false === stripos($url, 'https://')) {
throw new InvalidArgumentException('API schema requires HTTPS protocol');
}
$this->url = $url;
$this->token = $token;
$this->debug = $debug;
$this->stdout = $stdout;
$this->allowedMethods = [
self::METHOD_GET,
self::METHOD_POST,
self::METHOD_PUT,
self::METHOD_PATCH,
self::METHOD_DELETE
];
}
/**
* Make HTTP request
*
* @param string $path request url
* @param string $method (default: 'GET')
* @param mixed $request (default: null)
* @param int $serializeTo
*
* @return Response
* @throws \Exception
*/
public function makeRequest($path, $method, $request = null, $serializeTo = Serializer::S_JSON)
{
$this->validateMethod($method);
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);
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlHandler, CURLOPT_FAILONERROR, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curlHandler, CURLOPT_TIMEOUT, 60);
curl_setopt($curlHandler, CURLOPT_CONNECTTIMEOUT, 60);
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_PATCH, self::METHOD_DELETE])) {
curl_setopt($curlHandler, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $parameters);
}
$responseBody = curl_exec($curlHandler);
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
$response = Response::parseJSON($responseBody);
$errorMessage = !empty($response['errorMsg']) ? $response['errorMsg'] : '';
$errorMessage = !empty($response['errors']) ? $this->getErrors($response['errors']) : $errorMessage;
/**
* responses with 400 & 460 http codes contains extended error data
* therefore they are not handled as exceptions
*/
if (in_array($statusCode, [403, 404, 500])) {
throw new Exception($errorMessage);
}
if ($statusCode == 503) {
throw new LimitException($errorMessage);
}
$errno = curl_errno($curlHandler);
$error = curl_error($curlHandler);
curl_close($curlHandler);
if ($errno) {
throw new CurlException($error, $errno);
}
return new Response($statusCode, $responseBody);
}
/**
* Validate HTTP method
*
* @param string $method
*/
private function validateMethod($method)
{
if (!in_array($method, $this->allowedMethods, false)) {
throw new InvalidArgumentException(
sprintf(
'Method "%s" is not valid. Allowed methods are %s',
$method,
implode(', ', $this->allowedMethods)
)
);
}
}
/**
* Validate given class
*
* @param string $class
*
* @return void
*/
private function validateRequest($class)
{
$validator = Validation::createValidatorBuilder()
->enableAnnotationMapping()
->getValidator();
$errors = $validator->validate($class);
if ($errors->count() > 0) {
$message = (string) $errors;
throw new InvalidArgumentException($message);
}
}
private function getErrors(array $errors)
{
$errorString = '';
foreach ($errors as $error) {
$errorString .= $error . " ";
}
return $errorString;
}
}

View file

@ -1,229 +0,0 @@
<?php
/**
* PHP version 7.0
*
* Request
*
* @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;
use ArrayAccess;
use BadMethodCallException;
use InvalidArgumentException;
use RetailCrm\Common\Exception\InvalidJsonException;
/**
* PHP version 7.0
*
* Request 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 Response implements ArrayAccess
{
// HTTP response status code
protected $statusCode;
// response assoc array
protected $response;
// response body
protected $raw;
/**
* ApiResponse constructor.
*
* @param int $statusCode HTTP status code
* @param mixed $responseBody HTTP body
*
* @throws InvalidJsonException
*/
public function __construct($statusCode, $responseBody = null)
{
$this->statusCode = $statusCode;
$this->raw = $responseBody;
$this->response = self::parseJSON($responseBody);
}
/**
* Return raw HTTP response
*
* @return string|null
*/
public function getRawResponse()
{
return $this->raw;
}
/**
* Return HTTP response
*
* @return array
*/
public function getResponse()
{
return $this->response;
}
/**
* Return HTTP response status code
*
* @return int
*/
public function getStatusCode()
{
return $this->statusCode;
}
/**
* HTTP request was successful
*
* @return bool
*/
public function isSuccessful()
{
return $this->statusCode < 400;
}
/**
* Allow to access for the property throw class method
*
* @param string $name method name
* @param mixed $arguments method parameters
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function __call($name, $arguments)
{
// convert getSomeProperty to someProperty
$propertyName = strtolower(substr($name, 3, 1)) . substr($name, 4);
if (!isset($this->response[$propertyName])) {
throw new InvalidArgumentException("Method \"$name\" not found");
}
return $this->response[$propertyName];
}
/**
* Allow to access for the property throw object property
*
* @param string $name property name
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function __get($name)
{
if (!isset($this->response[$name])) {
throw new InvalidArgumentException("Property \"$name\" not found");
}
return $this->response[$name];
}
/**
* Allow to check if the property exists through object property
*
* @param string $name property name
*
* @return bool
*/
public function __isset($name)
{
return isset($this->response[$name]);
}
/**
* Offset set
*
* @param mixed $offset offset
* @param mixed $value value
*
* @throws BadMethodCallException
* @return void
*/
public function offsetSet($offset, $value)
{
$message = sprintf("This call not allowed. Offset given: %s. Value given: %s", $offset, $value);
throw new BadMethodCallException($message);
}
/**
* Offset unset
*
* @param mixed $offset offset
*
* @throws BadMethodCallException
* @return void
*/
public function offsetUnset($offset)
{
$message = sprintf("This call not allowed. Offset given: %s", $offset);
throw new BadMethodCallException($message);
}
/**
* Check offset
*
* @param mixed $offset offset
*
* @return bool
*/
public function offsetExists($offset)
{
return isset($this->response[$offset]);
}
/**
* Get offset
*
* @param mixed $offset offset
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function offsetGet($offset)
{
if (!isset($this->response[$offset])) {
throw new InvalidArgumentException("Property \"$offset\" not found");
}
return $this->response[$offset];
}
/**
* @param string $responseBody
*
* @return array
*/
public static function parseJSON($responseBody): array
{
$result = [];
if (!empty($responseBody)) {
$response = json_decode($responseBody, true);
if (!$response && JSON_ERROR_NONE !== ($error = json_last_error())) {
throw new InvalidJsonException("Invalid JSON in the API response body. Error code #$error", $error);
}
$result = $response;
}
return $result;
}
}

View file

@ -1,30 +1,29 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* CurlException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common\Exception;
use RuntimeException;
use Throwable;
/**
* PHP version 7.0
*
* Class CurlException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class CurlException extends RuntimeException
class CurlException extends RuntimeException implements Throwable
{
}

View file

@ -1,9 +1,9 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* CurlException
* InvalidJsonException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
@ -14,10 +14,9 @@
namespace RetailCrm\Common\Exception;
use DomainException;
use Throwable;
/**
* PHP version 7.0
*
* Class InvalidJsonException
*
* @package RetailCrm\Common\Exception
@ -25,6 +24,6 @@ use DomainException;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class InvalidJsonException extends DomainException
class InvalidJsonException extends DomainException implements Throwable
{
}

View file

@ -1,9 +1,9 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* CurlException
* LimitException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
@ -14,6 +14,7 @@
namespace RetailCrm\Common\Exception;
use DomainException;
use Throwable;
/**
* PHP version 7.0
@ -25,6 +26,6 @@ use DomainException;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class LimitException extends DomainException
class LimitException extends DomainException implements Throwable
{
}

View file

@ -0,0 +1,28 @@
<?php
/**
* PHP version 7.1
*
* NotFoundException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common\Exception;
use DomainException;
use Throwable;
/**
* Class NotFoundException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class NotFoundException extends DomainException implements Throwable
{
}

View file

@ -0,0 +1,20 @@
<?php
/**
* PHP version 7.1
*
* UnauthorizedException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common\Exception;
use DomainException;
use Throwable;
class UnauthorizedException extends DomainException implements Throwable
{
}

View file

@ -1,9 +1,9 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Register Helper
* Register
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
@ -19,9 +19,7 @@ use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;
/**
* PHP version 7.0
*
* RequestHelper class
* Class Register
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
@ -328,6 +326,7 @@ class Register
* Get configuration as JSON
*
* @return array|string
* @todo make exact type
*/
public function getJsonConfiguration()
{
@ -338,6 +337,7 @@ class Register
* Get configuration as array
*
* @return array|string
* @todo make exact type
*/
public function getArrayConfiguration()
{

View file

@ -1,14 +1,14 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Serializer
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common;
@ -16,16 +16,16 @@ namespace RetailCrm\Common;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerBuilder;
use RetailCrm\Mg\Bot\Model\ModelInterface;
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
/**
* PHP version 7.0
* Class Serializer
*
* Serializer class
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Serializer
{
@ -62,11 +62,11 @@ class Serializer
/**
* Deserialize given array or JSON to object
*
* @param mixed $data
* @param mixed $data
* @param string $entityType
* @param string $from
*
* @return object|null
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
*/
public static function deserialize($data, $entityType, $from = self::S_JSON)
{
@ -76,16 +76,16 @@ class Serializer
switch ($from) {
case self::S_ARRAY:
$deserialized =
$serializer->fromArray(array_filter($data), self::normalizeNamespace($entityType), $context);
$deserialized = $serializer
->fromArray(array_filter($data), self::normalizeNamespace($entityType), $context);
break;
case self::S_JSON:
$deserialized =
$serializer->deserialize($data, self::normalizeNamespace($entityType), $from, $context);
$deserialized = $serializer
->deserialize($data, self::normalizeNamespace($entityType), $from, $context);
break;
}
return is_object($deserialized) ? $deserialized : null;
return $deserialized instanceof ModelInterface ? $deserialized : new ErrorOnlyResponse();
}
/**

View file

@ -1,9 +1,9 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Url handler
* Url
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
@ -14,9 +14,7 @@
namespace RetailCrm\Common;
/**
* PHP version 7.0
*
* Url class
* Class Url
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
@ -26,6 +24,7 @@ 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.
@ -33,6 +32,8 @@ class Url
private function __construct() {}
/**
=======
>>>>>>> af44f8a... update models, update tests, update travis
* Check trailing slash into url
*
* @param string $url

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 5.4
* PHP version 7.1
*
* Test case class
*
@ -19,7 +19,6 @@ use RetailCrm\Mg\Bot\Client;
/**
* Class TestCase
*
* @category RetailCrm
* @package Test
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Client Test
*