<commit_before><?php namespace BulkSmsCenter;

use BulkSmsCenter\Exceptions\HttpClientException;
use GuzzleHttp\Psr7\Response;

class HttpClient
{
    /**
     * @var Auth
     */
    protected $auth;

    /**
     * @var array
     */
    protected $hosts = ['api.ek-media.nl',];

    /**
     * @var int
     */
    protected $port = 443;

    /**
     * @var string
     */
    protected $protocol;

    /**
     * @var string
     */
    protected $rawResponse;

    /**
     * @var Response
     */
    protected $response;

    /**
     * @var array
     */
    protected $apiResponse;

    /**
     * @var string
     */
    protected $userAgent;

    /**
     * @var int
     */
    protected $version = 1;

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

    /**
     * @return array
     */
    protected function defaultPostParams()
    {
        return [
            'password' => $<PASSWORD>(),
            'username' => $this->auth()->getUsername(),
            'version' => $this->version(),
        ];
    }

    /**
     * @return array
     */
    protected function hosts()
    {
        return $this->hosts;
    }

    /**
     * @param string|null $rawResponse
     *
     * @return array
     */
    protected function parseRawResponse($rawResponse = null)
    {
        $response = [];
        foreach (explode("\n",$rawResponse !== null ? $rawResponse : $this->getRawResponse()) as $line) {
            list($name,$value) = explode('=',$line);
            switch ($name = trim($name)) {
                case 'APIsmsID':
                    break;
                default:
                    $value = (is_numeric($value = trim($value)) ? $value += 0 : $value);
                    break;
            }
            $response[$name] = $value;
        }
        return $response;
    }

    /**
     * @return int
     */
    protected function port()
    {
        return $this->port === null ? $this->port = 443 : $this->port;
    }

    protected function protocol()
    {
        return $this->protocol === null ? $this->protocol = 'http'.($this->ssl() ? 's' : '') : $this->protocol;
    }

    protected function ssl()
    {
        return $this->port() === 443;
    }

    protected function version()
    {
        return $this->version;
    }

    protected function setRawResponse($rawResponse)
    {
        $this->rawResponse = $rawResponse;
    }

    protected function setResponse(Response $response)
    {
        $this->response = $response;
        return $this;
    }

    public function __construct(Auth $auth = null)
    {
        if ($auth !== null) {
            $this->setAuth($auth);
        }
    }

    /**
     * @param Auth $auth
     *
     * @return $this
     */
    public function setAuth(Auth $auth)
    {
        $this->auth = $auth;
        return $this;
    }

    /**
     * @param string|array $userAgent
     *
     * @return $this
     */
    public function setUserAgent($userAgent)
    {
        if (is_array($userAgent)) {
            $userAgent = implode(' ',$userAgent);
        }
        $this->userAgent = $userAgent;
        return $this;
    }

    public function runCommand($command,$data = [])
    {
        $data = array_merge($this->defaultPostParams(),[
            'command' => $command,
        ],$data);
        foreach ($this->hosts() as $host) {
            $response = $this->setResponse((new \GuzzleHttp\Client())->request('GET',"{$this->protocol()}://{$host}",[
                'query' => $data,
                'verify' => __DIR__.DIRECTORY_SEPARATOR.'cacert.pem',
            ]))->getResponse();
            if ($response->getStatusCode() !== 200) {
                throw new HttpClientException("Did not receive '200 OK' from {$host}");
            }
            $this->setRawResponse($response->getBody()->getContents());
            return true;
        }
        return false;
    }

    public function getResponse()
    {
        return $this->response;
    }

    public function getRawResponse()
    {
        return $this->rawResponse;
    }

    public function getApiResponse()
    {
        return $this->apiResponse ?: $this->apiResponse = $this->parseRawResponse();
    }
}
<commit_msg>Don't verify SSL<commit_after><?php namespace BulkSmsCenter;

use BulkSmsCenter\Exceptions\HttpClientException;
use GuzzleHttp\Psr7\Response;

class HttpClient
{
    /**
     * @var Auth
     */
    protected $auth;

    /**
     * @var array
     */
    protected $hosts = ['api.ek-media.nl',];

    /**
     * @var int
     */
    protected $port = 443;

    /**
     * @var string
     */
    protected $protocol;

    /**
     * @var string
     */
    protected $rawResponse;

    /**
     * @var Response
     */
    protected $response;

    /**
     * @var array
     */
    protected $apiResponse;

    /**
     * @var string
     */
    protected $userAgent;

    /**
     * @var int
     */
    protected $version = 1;

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

    /**
     * @return array
     */
    protected function defaultPostParams()
    {
        return [
            'password' => $<PASSWORD>(),
            'username' => $this->auth()->getUsername(),
            'version' => $this->version(),
        ];
    }

    /**
     * @return array
     */
    protected function hosts()
    {
        return $this->hosts;
    }

    /**
     * @param string|null $rawResponse
     *
     * @return array
     */
    protected function parseRawResponse($rawResponse = null)
    {
        $response = [];
        foreach (explode("\n",$rawResponse !== null ? $rawResponse : $this->getRawResponse()) as $line) {
            list($name,$value) = explode('=',$line);
            switch ($name = trim($name)) {
                case 'APIsmsID':
                    break;
                default:
                    $value = (is_numeric($value = trim($value)) ? $value += 0 : $value);
                    break;
            }
            $response[$name] = $value;
        }
        return $response;
    }

    /**
     * @return int
     */
    protected function port()
    {
        return $this->port === null ? $this->port = 443 : $this->port;
    }

    protected function protocol()
    {
        return $this->protocol === null ? $this->protocol = 'http'.($this->ssl() ? 's' : '') : $this->protocol;
    }

    protected function ssl()
    {
        return $this->port() === 443;
    }

    protected function version()
    {
        return $this->version;
    }

    protected function setRawResponse($rawResponse)
    {
        $this->rawResponse = $rawResponse;
    }

    protected function setResponse(Response $response)
    {
        $this->response = $response;
        return $this;
    }

    public function __construct(Auth $auth = null)
    {
        if ($auth !== null) {
            $this->setAuth($auth);
        }
    }

    /**
     * @param Auth $auth
     *
     * @return $this
     */
    public function setAuth(Auth $auth)
    {
        $this->auth = $auth;
        return $this;
    }

    /**
     * @param string|array $userAgent
     *
     * @return $this
     */
    public function setUserAgent($userAgent)
    {
        if (is_array($userAgent)) {
            $userAgent = implode(' ',$userAgent);
        }
        $this->userAgent = $userAgent;
        return $this;
    }

    public function runCommand($command,$data = [])
    {
        $data = array_merge($this->defaultPostParams(),[
            'command' => $command,
        ],$data);
        foreach ($this->hosts() as $host) {
            $response = $this->setResponse((new \GuzzleHttp\Client())->request('GET',"{$this->protocol()}://{$host}",[
                'query' => $data,
                'verify' => false,
            ]))->getResponse();
            if ($response->getStatusCode() !== 200) {
                throw new HttpClientException("Did not receive '200 OK' from {$host}");
            }
            $this->setRawResponse($response->getBody()->getContents());
            return true;
        }
        return false;
    }

    public function getResponse()
    {
        return $this->response;
    }

    public function getRawResponse()
    {
        return $this->rawResponse;
    }

    public function getApiResponse()
    {
        return $this->apiResponse ?: $this->apiResponse = $this->parseRawResponse();
    }
}

{'fraction_non_alphanumeric': 0.1543416030534351, 'fraction_numerical': 0.004293893129770993, 'mean_word_length': 1.6789137380191694, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 87, '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': '4357950', 'n_tokens_mistral': 2510, 'n_tokens_neox': 2406, 'n_words': 496}