<commit_before><?php
/**
 * @package gooddata-php-client
 * @copyright Keboola
 * @author <NAME> <<EMAIL>>
 */
namespace Keboola\GoodData;

use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;

class Client
{
    /**
     * Number of retries for one API call
     */
    const RETRIES_COUNT = 5;
    /**
     * Back off time before retrying API call
     */
    const BACKOFF_INTERVAL = 1;
    /**
     * Back off time before polling of async tasks
     */
    const WAIT_INTERVAL = 10;

    const API_URL = 'https://secure.gooddata.com';

    const DEFAULT_CLIENT_SETTINGS = [
        'timeout' => 600,
        'headers' => [
            'accept' => 'application/json',
            'content-type' => 'application/json; charset=utf-8'
        ]
    ];

    /** @var  \GuzzleHttp\Client */
    protected $guzzle;
    protected $guzzleOptions;
    /** @var  LoggerInterface */
    protected $logger;
    /** @var null MessageFormatter */
    protected $loggerFormatter;
    /** @var  array */
    protected $logData = [];

    protected $username;
    protected $password;

    /** @var  Datasets */
    protected $datasets;
    /** @var  DateDimensions */
    protected $dateDimensions;
    /** @var  Filters */
    protected $filters;
    /** @var  ProjectModel */
    protected $projectModel;
    /** @var  Projects */
    protected $projects;
    /** @var  Reports */
    protected $reports;
    /** @var  Users */
    protected $users;

    public function __construct($url = null, $logger = null, $loggerFormatter = null, array $options = [])
    {
        $options['base_uri'] = $url ?: self::API_URL;
        $this->guzzleOptions = $options;
        if ($logger) {
            $this->logger = $logger;
        }
        $this->loggerFormatter = $loggerFormatter ?: new MessageFormatter("{hostname} {req_header_User-Agent} - [{ts}] "
            . "\"{method} {resource} {protocol}/{version}\" {code} {res_header_Content-Length}");
        $this->initClient();
    }

    protected function initClient()
    {
        $handlerStack = HandlerStack::create();

        /** @noinspection PhpUnusedParameterInspection */
        $handlerStack->push(Middleware::retry(
            function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) {
                return $response && $response->getStatusCode() == 503;
            },
            function ($retries) {
                return rand(60, 600) * 1000;
            }
        ));
        /** @noinspection PhpUnusedParameterInspection */
        $handlerStack->push(Middleware::retry(
            function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) {
                if ($retries >= self::RETRIES_COUNT) {
                    return false;
                } elseif ($response && $response->getStatusCode() > 499) {
                    return true;
                } elseif ($error) {
                    return true;
                } else {
                    return false;
                }
            },
            function ($retries) {
                return (int) pow(2, $retries - 1) * 1000;
            }
        ));

        $handlerStack->push(Middleware::cookies());
        if ($this->logger) {
            $handlerStack->push(Middleware::log($this->logger, $this->loggerFormatter));
        }
        $this->guzzle = new \GuzzleHttp\Client(array_merge([
            'handler' => $handlerStack,
            'cookies' => true
        ], $this->guzzleOptions));
    }

    public function getUsername()
    {
        return $this->username;
    }

    public function getPassword()
    {
        return <PASSWORD>;
    }

    public function setLogData($data)
    {
        $this->logData = $data;
    }

    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    public function setApiUrl($url)
    {<commit_msg>feat: allow skipping ssl verification on demand<commit_after><?php
/**
 * @package gooddata-php-client
 * @copyright Keboola
 * @author <NAME> <<EMAIL>>
 */
namespace Keboola\GoodData;

use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;

class Client
{
    /**
     * Number of retries for one API call
     */
    const RETRIES_COUNT = 5;
    /**
     * Back off time before retrying API call
     */
    const BACKOFF_INTERVAL = 1;
    /**
     * Back off time before polling of async tasks
     */
    const WAIT_INTERVAL = 10;

    const API_URL = 'https://secure.gooddata.com';

    const DEFAULT_CLIENT_SETTINGS = [
        'timeout' => 600,
        'headers' => [
            'accept' => 'application/json',
            'content-type' => 'application/json; charset=utf-8'
        ]
    ];

    /** @var  \GuzzleHttp\Client */
    protected $guzzle;
    protected $guzzleOptions;
    /** @var  LoggerInterface */
    protected $logger;
    /** @var null MessageFormatter */
    protected $loggerFormatter;
    /** @var  array */
    protected $logData = [];

    protected $username;
    protected $password;

    /** @var  Datasets */
    protected $datasets;
    /** @var  DateDimensions */
    protected $dateDimensions;
    /** @var  Filters */
    protected $filters;
    /** @var  ProjectModel */
    protected $projectModel;
    /** @var  Projects */
    protected $projects;
    /** @var  Reports */
    protected $reports;
    /** @var  Users */
    protected $users;

    public function __construct($url = null, $logger = null, $loggerFormatter = null, array $options = [])
    {
        $options['base_uri'] = $url ?: self::API_URL;
        $this->guzzleOptions = $options;
        if ($logger) {
            $this->logger = $logger;
        }
        $this->loggerFormatter = $loggerFormatter ?: new MessageFormatter("{hostname} {req_header_User-Agent} - [{ts}] "
            . "\"{method} {resource} {protocol}/{version}\" {code} {res_header_Content-Length}");
        $this->initClient();
    }

    protected function initClient()
    {
        $handlerStack = HandlerStack::create();

        /** @noinspection PhpUnusedParameterInspection */
        $handlerStack->push(Middleware::retry(
            function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) {
                return $response && $response->getStatusCode() == 503;
            },
            function ($retries) {
                return rand(60, 600) * 1000;
            }
        ));
        /** @noinspection PhpUnusedParameterInspection */
        $handlerStack->push(Middleware::retry(
            function ($retries, RequestInterface $request, ResponseInterface $response = null, $error = null) {
                if ($retries >= self::RETRIES_COUNT) {
                    return false;
                } elseif ($response && $response->getStatusCode() > 499) {
                    return true;
                } elseif ($error) {
                    return true;
                } else {
                    return false;
                }
            },
            function ($retries) {
                return (int) pow(2, $retries - 1) * 1000;
            }
        ));

        $handlerStack->push(Middleware::cookies());
        if ($this->logger) {
            $handlerStack->push(Middleware::log($this->logger, $this->loggerFormatter));
        }
        $this->guzzle = new \GuzzleHttp\Client(array_merge([
            'handler' => $handlerStack,
            'cookies' => true
        ], $this->guzzleOptions));
    }

    public function getUsername()
    {
        return $this->username;
    }

    public function getPassword()
    {
        return $this->password;
    }

    public function setLogData($data)
    {
        $this->logData = $data;
    }

    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    public function setApiUrl($url, $verify = true)
    {
        if (!$verify) {
            $this->guzzleOptions['verify'] = false;
        }
{'fraction_non_alphanumeric': 0.13266378605628867, 'fraction_numerical': 0.007006890108606796, 'mean_word_length': 2.1381458409673875, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 64, 'https://': 2, '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': '102762', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2403, 'n_words': 532}