<commit_before><?php

namespace Mapado\RestClientSdk;

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\TransferException;
use Mapado\RestClientSdk\Exception\RestClientException;
use Mapado\RestClientSdk\Exception\RestException;
use Psr\Http\Message\ResponseInterface;

/**
 * Class RestClient
 * @author <NAME> <<EMAIL>>
 */
class RestClient
{
    /**
     * httpClient
     *
     * @var ClientInterface
     * @access private
     */
    private $httpClient;

    /**
     * baseUrl
     *
     * @var string
     * @access private
     */
    private $baseUrl;

    /**
     * logHistory
     *
     * @var boolean
     * @access private
     */
    private $logHistory;

    /**
     * requestHistory
     *
     * @var array
     * @access private
     */
    private $requestHistory;

    /**
     * @param ClientInterface $httpClient
     * @param string|null     $baseUrl
     */
    public function __construct(ClientInterface $httpClient, $baseUrl = null)
    {
        $this->httpClient     = $httpClient;
        $this->baseUrl        = substr($baseUrl, -1) === '/' ? substr($baseUrl, 0, -1) : $baseUrl;
        $this->logHistory     = false;
        $this->requestHistory = [];
    }

    /**
     * @return bool
     */
    public function isHistoryLogged()
    {
        return $this->logHistory;
    }

    /**
     * setLogHistory
     *
     * @param boolean $logHistory
     * @access public
     * @return RestClient
     */
    public function setLogHistory($logHistory)
    {
        $this->logHistory = $logHistory;

        return $this;
    }

    /**
     * @return array
     */
    public function getRequestHistory()
    {
        return $this->requestHistory;
    }

    /**
     * get a path
     *
     * @param string $path
     * @param array  $parameters
     * @return array|ResponseInterface|null
     * @throws RestException
     */
    public function get($path, $parameters = [])
    {
        $requestUrl = $this->baseUrl . $path;
        try {
            return $this->executeRequest('GET', $requestUrl, $parameters);
        } catch (ClientException $e) {
            if ($e->getResponse()->getStatusCode() === 404) {
                return null;
            }
            throw new RestException('Error while getting resource', $path, [], 7, $e);
        } catch (TransferException $e) {
            throw new RestException('Error while getting resource', $path, [], 1, $e);
        }
    }

    /**
     * delete
     *
     * @param string $path
     * @access public
     * @return void
     * @throws RestException
     */
    public function delete($path)
    {
        try {
            $this->executeRequest('DELETE', $this->baseUrl . $path);
        } catch (ClientException $e) {
            return;
        } catch (TransferException $e) {
            throw new RestException('Error while deleting resource', $path, [], 2, $e);
        }
    }

    /**
     * @param string $path<commit_msg>use RestClientException instead of RestException<commit_after><?php

namespace Mapado\RestClientSdk;

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\TransferException;
use Mapado\RestClientSdk\Exception\RestClientException;
use Mapado\RestClientSdk\Exception\RestException;
use Psr\Http\Message\ResponseInterface;

/**
 * Class RestClient
 * @author <NAME> <<EMAIL>>
 */
class RestClient
{
    /**
     * httpClient
     *
     * @var ClientInterface
     * @access private
     */
    private $httpClient;

    /**
     * baseUrl
     *
     * @var string
     * @access private
     */
    private $baseUrl;

    /**
     * logHistory
     *
     * @var boolean
     * @access private
     */
    private $logHistory;

    /**
     * requestHistory
     *
     * @var array
     * @access private
     */
    private $requestHistory;

    /**
     * @param ClientInterface $httpClient
     * @param string|null     $baseUrl
     */
    public function __construct(ClientInterface $httpClient, $baseUrl = null)
    {
        $this->httpClient     = $httpClient;
        $this->baseUrl        = substr($baseUrl, -1) === '/' ? substr($baseUrl, 0, -1) : $baseUrl;
        $this->logHistory     = false;
        $this->requestHistory = [];
    }

    /**
     * @return bool
     */
    public function isHistoryLogged()
    {
        return $this->logHistory;
    }

    /**
     * setLogHistory
     *
     * @param boolean $logHistory
     * @access public
     * @return RestClient
     */
    public function setLogHistory($logHistory)
    {
        $this->logHistory = $logHistory;

        return $this;
    }

    /**
     * @return array
     */
    public function getRequestHistory()
    {
        return $this->requestHistory;
    }

    /**
     * get a path
     *
     * @param string $path
     * @param array  $parameters
     * @return array|ResponseInterface|null
     * @throws RestException
     */
    public function get($path, $parameters = [])
    {
        $requestUrl = $this->baseUrl . $path;
        try {
            return $this->executeRequest('GET', $requestUrl, $parameters);
        } catch (ClientException $e) {
            if ($e->getResponse()->getStatusCode() === 404) {
                return null;
            }
            throw new RestClientException('Error while getting resource', $path, [], 7, $e);
        } catch (TransferException $e) {
            throw new RestException('Error while getting resource', $path, [], 1, $e);
        }
    }

    /**
     * delete
     *
     * @param string $path
     * @access public
     * @return void
     * @throws RestException
     */
    public function delete($path)
    {
        try {
            $this->executeRequest('DELETE', $this->baseUrl . $path);
        } catch (ClientException $e) {
            return;
        } catch (TransferException $e) {
            throw new RestException('Error while deleting resource', $path, [], 2, $e);
        }
    }

    /**
     * @param string $path
{'fraction_non_alphanumeric': 0.1275890637945319, 'fraction_numerical': 0.002982601491300746, 'mean_word_length': 1.9660933660933662, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '873501', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1722, 'n_words': 389}