src/Client.php
/**
     * Handles a general request
     *
     * @param string $responseClass The response class
     * @param callable $requestFactory A callable which creates the request object
     *
     * @param bool $ignorePool If true and batching is enabled, the request will be executed instead of queueing to pool
     * @return mixed The mapped response object
     *
     * @throws QuotaExceededException If the maximum number of calls per second exceeded
     * @throws Exception If the response cannot be parsed
     */
Handles a general request
@param string $responseClass The response class
@param callable $requestFactory A callable which creates the request object

@param bool $ignorePool If true and batching is enabled, the request will be executed instead of queueing to pool
@return mixed The mapped response object

@throws QuotaExceededException If the maximum number of calls per second exceeded
@throws Exception If the response cannot be parsed
Handles a general request @param string $responseClass The response class @param callable $requestFactory A callable which creates the request object @param bool $ignorePool If true and batching is enabled the request will be executed instead of queueing to pool @return mixed The mapped response object @throws QuotaExceededException If the maximum number of calls per second exceeded @throws Exception If the response cannot be parsed
private function internalRequest($responseClass, callable $requestFactory, $ignorePool = false)
    {
        if ($this->useBatching === true && $ignorePool === false) {
            $req = [
                'responseClass' => $responseClass,
                'requestFactory' => $requestFactory
            ];
            $this->logger->info('Adding request for batch request to the request pool', $req);
            $this->requestPool[] = $req;
            return null;
        }
        $contents = null;
        try {
            $request = $requestFactory();
            if ($this->logRequests || $this->logger instanceof DiagnosticsLogger) {
                $this->logger->debug(sprintf('Execute request to %s', $request->getUri()), [
                    'method' => $request->getMethod(),
                    'body' => $request->getBody(),
                ]);
            }
            $res = $this->sendAsync($request, [RequestOptions::SYNCHRONOUS => true])->wait();
            $contents = $res->getBody()->getContents();
            if ($this->logRequests || $this->logger instanceof DiagnosticsLogger) {
                $this->logger->debug(sprintf('Request to %s executed successfully', $request->getUri()), [
                    'headers' => $res->getHeaders(),
                    'body' => $contents,
                ]);
            }
        } catch (ClientException $ex) {
            if ($ex->getCode() == 429) {
                $this->logger->warning('Request quota exceeded');
                throw new QuotaExceededException($ex->getMessage());
            } else {
                $this->logger->error('Error during request', (array)$ex);
                throw $ex;
            }
        }
        $data = null;
        if ($responseClass !== null) {
            try {
                if (trim($contents) != '' && trim($responseClass) != '') {
                    $data = $this->jom->map($contents, $responseClass);
                } elseif (trim($contents) != '') {
                    $data = $contents;
                }
            } catch (Exception $exception) {
                throw $exception;
            }
        } else {
            $data = [];
            $responses = $this->getResponsesFromBody($contents);
            foreach ($responses as $i => $response) {
                $responseClass = $this->requestPool[$i]['responseClass'];
                $contents = parse_response($response)->getBody()->getContents();
                try {
                    if (trim($contents) != '' && trim($responseClass) != '') {
                        $data[$i] = $this->jom->map($contents, $responseClass);
                    } elseif (trim($contents) != '') {
                        $data[$i] = $contents;
                    }
                } catch (Exception $exception) {
                    $data[$i] = $exception;
                }
            }
        }
        return $data;
    }
private function internalRequest ( $ responseClass , callable $ requestFactory , $ ignorePool = false ) { if ( $ this -> useBatching === true && $ ignorePool === false ) { $ req = [ 'responseClass' => $ responseClass , 'requestFactory' => $ requestFactory ] ; $ this -> logger -> info ( 'Adding request for batch request to the request pool' , $ req ) ; $ this -> requestPool [ ] = $ req ; return null ; } $ contents = null ; try { $ request = $ requestFactory ( ) ; if ( $ this -> logRequests || $ this -> logger instanceof DiagnosticsLogger ) { $ this -> logger -> debug ( sprintf ( 'Execute request to %s' , $ request -> getUri ( ) ) , [ 'method' => $ request -> getMethod ( ) , 'body' => $ request -> getBody ( ) , ] ) ; } $ res = $ this -> sendAsync ( $ request , [ RequestOptions :: SYNCHRONOUS => true ] ) -> wait ( ) ; $ contents = $ res -> getBody ( ) -> getContents ( ) ; if ( $ this -> logRequests || $ this -> logger instanceof DiagnosticsLogger ) { $ this -> logger -> debug ( sprintf ( 'Request to %s executed successfully' , $ request -> getUri ( ) ) , [ 'headers' => $ res -> getHeaders ( ) , 'body' => $ contents , ] ) ; } } catch ( ClientException $ ex ) { if ( $ ex -> getCode ( ) == 429 ) { $ this -> logger -> warning ( 'Request quota exceeded' ) ; throw new QuotaExceededException ( $ ex -> getMessage ( ) ) ; } else { $ this -> logger -> error ( 'Error during request' , ( array ) $ ex ) ; throw $ ex ; } } $ data = null ; if ( $ responseClass !== null ) { try { if ( trim ( $ contents ) != '' && trim ( $ responseClass ) != '' ) { $ data = $ this -> jom -> map ( $ contents , $ responseClass ) ; } elseif ( trim ( $ contents ) != '' ) { $ data = $ contents ; } } catch ( Exception $ exception ) { throw $ exception ; } } else { $ data = [ ] ; $ responses = $ this -> getResponsesFromBody ( $ contents ) ; foreach ( $ responses as $ i => $ response ) { $ responseClass = $ this -> requestPool [ $ i ] [ 'responseClass' ] ; $ contents = parse_response ( $ response ) -> getBody ( ) -> getContents ( ) ; try { if ( trim ( $ contents ) != '' && trim ( $ responseClass ) != '' ) { $ data [ $ i ] = $ this -> jom -> map ( $ contents , $ responseClass ) ; } elseif ( trim ( $ contents ) != '' ) { $ data [ $ i ] = $ contents ; } } catch ( Exception $ exception ) { $ data [ $ i ] = $ exception ; } } } return $ data ; }
Handles a general request
 @param string $responseClass The response class
 @param callable $requestFactory A callable which creates the request object
Handles a general request @param string $responseClass The response class @param callable $requestFactory A callable which creates the request object
/** @var \GuzzleHttp\Psr7\Request $request */ /** @var ResponseInterface $res */