public function sendRequest($path, $method = 'GET', array $payload = null)
    {
        $this->getLogger()->debug(sprintf('%s %s', $method, $path));

        $request = $this->messageFactory->createRequest(
            $method,
            $this->baseUri . '/' . ltrim($path, '/'),
            ['apiKey' => $this->token]
        );

        if ($payload) {
            $request = $this->buildRequestBody($request, $payload);
            $this->getLogger()->debug(
                sprintf(
                    'Sending payload with "%s" content type',
                    $request->getHeaderLine('Content-type')
                )
            );
        } else {
            try {
                $request = $request->withHeader('Content-length', '0');
            } catch (\InvalidArgumentException $e) {
                throw new \LogicException($e->getMessage(), $e->getCode(), $e);
            }
        }

        try {
            $response = $this->httpClient->sendRequest($request);
        } catch (\Exception $e) {
            throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
        }

        if ($response->getStatusCode() !== 200) {
            $message = sprintf(
                'HTTP %d: %s',
                $response->getStatusCode(),
                $response->getReasonPhrase()
            );
            $this->getLogger()->error($message);
            throw new RuntimeException($message);
        }

        $type = explode(';', $response->getHeaderLine('Content-type'));
        $type = reset($type);
        switch ($type) {
            case 'application/json':
                $this->getLogger()->debug('Response body is a JSON');

                return $this->parseJson((string) $response->getBody());
            // break not needed
            case 'application/octet-stream':
                $this->getLogger()->debug('Response body is a stream');

                return $response->getBody();
            // break not needed
        }

        throw new RuntimeException('Unexpected response content type:' . $type);
    }
public function sendRequest($path, $method = 'GET', array $payload = null)
    {
        $this->getLogger()->debug(sprintf('%s %s', $method, $path));

        $request = $this->messageFactory->createRequest(
            $method,
            $this->baseUri . '/' . ltrim($path, '/'),
            ['apiKey' => $this->token]
        );

        if ($payload) {
            $request = $this->buildRequestBody($request, $payload);
            $this->getLogger()->debug(
                sprintf(
                    'Sending payload with "%s" content type',
                    $request->getHeaderLine('Content-type')
                )
            );
        } else {
            try {
                $request = $request->withHeader('Content-length', '0');
            } catch (\InvalidArgumentException $e) {
                throw new \LogicException($e->getMessage(), $e->getCode(), $e);
            }
        }

        try {
            $response = $this->httpClient->sendRequest($request);
        } catch (\Exception $e) {
            throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
        }

        if ($response->getStatusCode() !== 200) {
            $message = sprintf(
                'HTTP %d: %s',
                $response->getStatusCode(),
                $response->getReasonPhrase()
            );
            $this->getLogger()->error($message);
            throw new RuntimeException($message);
        }

        $type = explode(';', $response->getHeaderLine('Content-type'));
        $type = reset($type);
        switch ($type) {
            case 'application/json':
                $this->getLogger()->debug('Response body is a JSON');

                return $this->parseJson((string) $response->getBody());
            // break not needed
            case 'application/octet-stream':
                $this->getLogger()->debug('Response body is a stream');

                return $response->getBody();
            // break not needed
        }

        throw new RuntimeException('Unexpected response content type:' . $type);
    }
public function sendRequest ( $ path , $ method = 'GET' , array $ payload = null ) { $ this -> getLogger ( ) -> debug ( sprintf ( '%s %s' , $ method , $ path ) ) ; $ request = $ this -> messageFactory -> createRequest ( $ method , $ this -> baseUri . '/' . ltrim ( $ path , '/' ) , [ 'apiKey' => $ this -> token ] ) ; if ( $ payload ) { $ request = $ this -> buildRequestBody ( $ request , $ payload ) ; $ this -> getLogger ( ) -> debug ( sprintf ( 'Sending payload with "%s" content type' , $ request -> getHeaderLine ( 'Content-type' ) ) ) ; } else { try { $ request = $ request -> withHeader ( 'Content-length' , '0' ) ; } catch ( \ InvalidArgumentException $ e ) { throw new \ LogicException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } } try { $ response = $ this -> httpClient -> sendRequest ( $ request ) ; } catch ( \ Exception $ e ) { throw new RuntimeException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } if ( $ response -> getStatusCode ( ) !== 200 ) { $ message = sprintf ( 'HTTP %d: %s' , $ response -> getStatusCode ( ) , $ response -> getReasonPhrase ( ) ) ; $ this -> getLogger ( ) -> error ( $ message ) ; throw new RuntimeException ( $ message ) ; } $ type = explode ( ';' , $ response -> getHeaderLine ( 'Content-type' ) ) ; $ type = reset ( $ type ) ; switch ( $ type ) { case 'application/json' : $ this -> getLogger ( ) -> debug ( 'Response body is a JSON' ) ; return $ this -> parseJson ( ( string ) $ response -> getBody ( ) ) ; // break not needed case 'application/octet-stream' : $ this -> getLogger ( ) -> debug ( 'Response body is a stream' ) ; return $ response -> getBody ( ) ; // break not needed } throw new RuntimeException ( 'Unexpected response content type:' . $ type ) ; }
Send request to Tracker and return response.

Payload should an associative array with scalar, array or
{@see Comindware\Tracker\API\Util\File\File} values.

@param string     $path    Requested URI relative to base URI (e. g. "/Api/Account/123")
@param string     $method  HTTP method (e. g. "POST")
@param array|null $payload Optional request payload. See method description for details.

@return array|string|StreamInterface

@throws \Comindware\Tracker\API\Exception\RuntimeException In case of non-API errors.
@throws \Comindware\Tracker\API\Exception\WebApiClientException Ore one of descendants.
@throws \LogicException On internal errors.

@since 0.3.1 Throws \LogicException On internal errors.
@since 0.1
Send request to Tracker and return response .