<commit_before><?php
/**
 * PHP version 5
 *
 * This is the Mailjet Request
 *
 * @category Mailjet_API
 * @package  Mailjet-apiv3
 * @author   <NAME> <<EMAIL>>
 * @license  MIT https://opensource.org/licenses/MIT
 * @link     dev.mailjet.com
 */

namespace Mailjet;

use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\ClientException;

/**
 * This is the Mailjet Request class
 * @category Mailjet_API
 * @package  Mailjet-apiv3
 * @author <NAME> <<EMAIL>>
 * @license MIT https://licencepath.com
 * @link http://link.com
 */
class Request extends GuzzleClient
{
    private $method;
    private $url;
    private $filters;
    private $body;
    private $auth;
    private $type;

    /**
     * Build a new Http request
     * @param array  $auth    [apikey, apisecret]
     * @param string $method  http method
     * @param string $url     call url
     * @param array  $filters Mailjet resource filters
     * @param array  $body    Mailjet resource body
     * @param string $type    Request Content-type
     */
    public function __construct($auth, $method, $url, $filters, $body, $type)
    {
        parent::__construct(['defaults' => [
            'headers' => [
                'user-agent' => Config::USER_AGENT . phpversion() . '/' . Client::WRAPPER_VERSION
            ]
        ]]);
        $this->type = $type;
        $this->auth = $auth;
        $this->method = $method;
        $this->url = $url;
        $this->filters = $filters;
        $this->body = $body;
    }

    /**
     * Trigger the actual call
     * TODO: DATA API
     * @param $call
     * @return Response the call response
     */
    public function call($call)
    {
        $payload = [
            'headers'  => ['content-type' => $this->type],
            'query' => $this->filters,
            'auth' => $this->auth,
            ($this->type === 'application/json' ? 'json' : 'body') => $this->body,
        ];

        $response = null;
        if ($call) {
            try {
                $response = call_user_func_array(
                    array($this, strtolower($this->method)), [
                    $this->url, $payload]
                );
            }
            catch (ClientException $e) {
                $response = $e->getResponse();
            }
        }
        return new Response($this, $response);
    }

    /**
     * Filters getters
     * @return array Request filters
     */
    public function getFilters()
    {
        return $this->filters;
    }

    /**
     * Http method getter
     * @return string Request method
     */
    public function getMethod()
    {
        return $this->method;
    }

    /**
     * Call Url getter
     * @return string Request Url
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * Request body getter
     * @return array request body
     */
    public function getBody()
    {
        return $this->body;
    }

    /**
     * Auth getter. to discuss
     * @return string Request auth
     */
    public function getAuth()
    {
        return $this->auth;
    }
}
<commit_msg>Fix guzzle ServerException uncaught<commit_after><?php
/**
 * PHP version 5
 *
 * This is the Mailjet Request
 *
 * @category Mailjet_API
 * @package  Mailjet-apiv3
 * @author   <NAME> <<EMAIL>>
 * @license  MIT https://opensource.org/licenses/MIT
 * @link     dev.mailjet.com
 */

namespace Mailjet;

use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;

/**
 * This is the Mailjet Request class
 * @category Mailjet_API
 * @package  Mailjet-apiv3
 * @author <NAME> <<EMAIL>>
 * @license MIT https://licencepath.com
 * @link http://link.com
 */
class Request extends GuzzleClient
{
    private $method;
    private $url;
    private $filters;
    private $body;
    private $auth;
    private $type;

    /**
     * Build a new Http request
     * @param array  $auth    [apikey, apisecret]
     * @param string $method  http method
     * @param string $url     call url
     * @param array  $filters Mailjet resource filters
     * @param array  $body    Mailjet resource body
     * @param string $type    Request Content-type
     */
    public function __construct($auth, $method, $url, $filters, $body, $type)
    {
        parent::__construct(['defaults' => [
            'headers' => [
                'user-agent' => Config::USER_AGENT . phpversion() . '/' . Client::WRAPPER_VERSION
            ]
        ]]);
        $this->type = $type;
        $this->auth = $auth;
        $this->method = $method;
        $this->url = $url;
        $this->filters = $filters;
        $this->body = $body;
    }

    /**
     * Trigger the actual call
     * TODO: DATA API
     * @param $call
     * @return Response the call response
     */
    public function call($call)
    {
        $payload = [
            'headers'  => ['content-type' => $this->type],
            'query' => $this->filters,
            'auth' => $this->auth,
            ($this->type === 'application/json' ? 'json' : 'body') => $this->body,
        ];

        $response = null;
        if ($call) {
            try {
                $response = call_user_func_array(
                    array($this, strtolower($this->method)), [
                    $this->url, $payload]
                );
            }
            catch (ClientException $e) {
                $response = $e->getResponse();
            }
            catch (ServerException $e) {
                $response = $e->getResponse();
            }
        }
        return new Response($this, $response);
    }

    /**
     * Filters getters
     * @return array Request filters
     */
    public function getFilters()
    {
        return $this->filters;
    }

    /**
     * Http method getter
     * @return string Request method
     */
    public function getMethod()
    {
        return $this->method;
    }

    /**
     * Call Url getter
     * @return string Request Url
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * Request body getter
     * @return array request body
     */
    public function getBody()
    {
        return $this->body;
    }

    /**
     * Auth getter. to discuss
     * @return string Request auth
     */
    public function getAuth()
    {
        return $this->auth;
    }
}

{'fraction_non_alphanumeric': 0.13245448838669177, 'fraction_numerical': 0.0009416195856873823, 'mean_word_length': 1.784185233726518, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 70, 'https://': 4, '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': '2608044', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1863, 'n_words': 482}