public function execute(AbstractMethod $method): \Generator
    {
        switch ($method->getHttpMethod()) {
            case $method::HTTP_GET:
                $response = yield from $this->get('/'.$method->getMethodName(), $method->getParams());
                break;
            case $method::HTTP_POST:
                if ($method instanceof \JsonSerializable) {
                    $body = json_encode($method);

                    $bodyStream = new MemoryStream(0, $body);
                    yield from $bodyStream->end();
                    $contentLength = mb_strlen($body);
                } else {
                    $bodyStream = null;
                    $contentLength = 0;
                }

                $headers = [
                    'Content-Type' => 'application/json',
                    'Content-Length' => $contentLength
                ];
                $response = yield from $this->post('/'.$method->getMethodName(), $method->getParams(), $headers, $bodyStream);
                break;
        }

        $body = yield from $this->getResponseBody($response);
        $body = json_decode($body, true);

        if ($body['ok'] === false) {
            $exception = new TelegramBotApiException($body['description'], $body['error_code']);

            if (isset($body['parameters'])) {
                $parameters = new Type\ResponseParameters($body['parameters']);
                $exception->setParameters($parameters);
            }

            throw $exception;
        }

        return $method->buildResult($body['result']);
    }
public function execute(AbstractMethod $method): \Generator
    {
        switch ($method->getHttpMethod()) {
            case $method::HTTP_GET:
                $response = yield from $this->get('/'.$method->getMethodName(), $method->getParams());
                break;
            case $method::HTTP_POST:
                if ($method instanceof \JsonSerializable) {
                    $body = json_encode($method);

                    $bodyStream = new MemoryStream(0, $body);
                    yield from $bodyStream->end();
                    $contentLength = mb_strlen($body);
                } else {
                    $bodyStream = null;
                    $contentLength = 0;
                }

                $headers = [
                    'Content-Type' => 'application/json',
                    'Content-Length' => $contentLength
                ];
                $response = yield from $this->post('/'.$method->getMethodName(), $method->getParams(), $headers, $bodyStream);
                break;
        }

        $body = yield from $this->getResponseBody($response);
        $body = json_decode($body, true);

        if ($body['ok'] === false) {
            $exception = new TelegramBotApiException($body['description'], $body['error_code']);

            if (isset($body['parameters'])) {
                $parameters = new Type\ResponseParameters($body['parameters']);
                $exception->setParameters($parameters);
            }

            throw $exception;
        }

        return $method->buildResult($body['result']);
    }
public function execute ( AbstractMethod $ method ) : \ Generator { switch ( $ method -> getHttpMethod ( ) ) { case $ method :: HTTP_GET : $ response = yield from $ this -> get ( '/' . $ method -> getMethodName ( ) , $ method -> getParams ( ) ) ; break ; case $ method :: HTTP_POST : if ( $ method instanceof \ JsonSerializable ) { $ body = json_encode ( $ method ) ; $ bodyStream = new MemoryStream ( 0 , $ body ) ; yield from $ bodyStream -> end ( ) ; $ contentLength = mb_strlen ( $ body ) ; } else { $ bodyStream = null ; $ contentLength = 0 ; } $ headers = [ 'Content-Type' => 'application/json' , 'Content-Length' => $ contentLength ] ; $ response = yield from $ this -> post ( '/' . $ method -> getMethodName ( ) , $ method -> getParams ( ) , $ headers , $ bodyStream ) ; break ; } $ body = yield from $ this -> getResponseBody ( $ response ) ; $ body = json_decode ( $ body , true ) ; if ( $ body [ 'ok' ] === false ) { $ exception = new TelegramBotApiException ( $ body [ 'description' ] , $ body [ 'error_code' ] ) ; if ( isset ( $ body [ 'parameters' ] ) ) { $ parameters = new Type \ ResponseParameters ( $ body [ 'parameters' ] ) ; $ exception -> setParameters ( $ parameters ) ; } throw $ exception ; } return $ method -> buildResult ( $ body [ 'result' ] ) ; }
Execute an API method.

@param AbstractMethod $method

@return \Generator
@throws TelegramBotApiException
@resolve object
Execute an API method .