<commit_before><?php
/**
 * Created by PhpStorm.
 * User: Ondra
 * Date: 22.2.14
 * Time: 11:11
 */

namespace ondrs\Vehico\Api;


use Hampel\Json\Json;
use Hampel\Json\JsonException as HampelJsonException;


class BaseApi
{

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

    /** @var \Curl */
    protected $curl;

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

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

    /** @var string */
    const API_URL = 'https://www.vehico.cz/api';



    /**
     * @param string $tempDir
     * @param string|null $url
     */
    public function __construct($tempDir, $apiKey, $url = NULL)
    {
        $this->tempDir = $tempDir;
        $this->apiKey = $apiKey;

        $this->curl = new \Curl;


        $this->curl->options['SSL_VERIFYHOST'] = FALSE;
        $this->curl->options['ssl_verifyPeer'] = FALSE;
        $this->curl->options['FOLLOWLOCATION'] = TRUE;
        $this->curl->options['MAXREDIRS'] = 3;
        $this->curl->headers['Accept'] = 'application/json';
        $this->curl->headers['X-VEHICO-API-KEY'] = $apiKey;

        $this->url = $url ? $url : self::API_URL;
    }



    /**
     * @param string $method
     * @param string $url
     * @param array|null $args
     * @return \CurlResponse
     * @throws CurlException
     */
    protected function request($method, $url, $args = NULL)
    {
        try {
            $method = strtoupper($method);

            /** @var \CurlResponse $response */
            $response = $this->curl->$method($url, $args);


            if($response->headers['Status-Code'] >= 300) {
                throw new CurlException($response->headers['Status'], $response->headers['Status-Code']);
            }

            return $response;
        } catch(\CurlException $e) {
            throw new CurlException($e->getMessage(), $e->getCode());
        }
    }



    /**
     * @param \CurlResponse $response
     * @return \stdClass
     * @throws JsonException
     */
    protected function getResponseBody(\CurlResponse $response)
    {
        try {
            return Json::decode($response->body);
        } catch(HampelJsonException $e) {
            throw new JsonException($e->getMessage(), $e->getCode());
        }
    }


} <commit_msg>error status code<commit_after><?php
/**
 * Created by PhpStorm.
 * User: Ondra
 * Date: 22.2.14
 * Time: 11:11
 */

namespace ondrs\Vehico\Api;


use Hampel\Json\Json;
use Hampel\Json\JsonException as HampelJsonException;


class BaseApi
{

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

    /** @var \Curl */
    protected $curl;

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

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

    /** @var string */
    const API_URL = 'https://www.vehico.cz/api';



    /**
     * @param string $tempDir
     * @param string|null $url
     */
    public function __construct($tempDir, $apiKey, $url = NULL)
    {
        $this->tempDir = $tempDir;
        $this->apiKey = $apiKey;

        $this->curl = new \Curl;


        $this->curl->options['SSL_VERIFYHOST'] = FALSE;
        $this->curl->options['ssl_verifyPeer'] = FALSE;
        $this->curl->options['FOLLOWLOCATION'] = TRUE;
        $this->curl->options['MAXREDIRS'] = 3;
        $this->curl->headers['Accept'] = 'application/json';
        $this->curl->headers['X-VEHICO-API-KEY'] = $apiKey;

        $this->url = $url ? $url : self::API_URL;
    }



    /**
     * @param string $method
     * @param string $url
     * @param array|null $args
     * @return \CurlResponse
     * @throws CurlException
     */
    protected function request($method, $url, $args = NULL)
    {
        try {
            $method = strtoupper($method);

            /** @var \CurlResponse $response */
            $response = $this->curl->$method($url, $args);


            if($response->headers['Status-Code'] >= 400) {
                throw new CurlException($response->headers['Status'], $response->headers['Status-Code']);
            }

            return $response;
        } catch(\CurlException $e) {
            throw new CurlException($e->getMessage(), $e->getCode());
        }
    }



    /**
     * @param \CurlResponse $response
     * @return \stdClass
     * @throws JsonException
     */
    protected function getResponseBody(\CurlResponse $response)
    {
        try {
            return Json::decode($response->body);
        } catch(HampelJsonException $e) {
            throw new JsonException($e->getMessage(), $e->getCode());
        }
    }


} 
{'fraction_non_alphanumeric': 0.16421895861148197, 'fraction_numerical': 0.005785491766800178, 'mean_word_length': 2.110726643598616, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '105109', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1389, 'n_words': 278}