<commit_before><?php

namespace DuckDuckGo;

use DuckDuckGo\Misc;
use GuzzleHttp\Client as Http;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;

Class Api
{
    /**
     * Api endpoint url.
     * 
     * @var string
     */
    protected $endpoint;

    /**
     * DuckDuckGo Api constructor.
     */
    public function __construct()
    {
        $this->endpoint = "api.duckduckgo.com/";
    }

    /**
     * Perform a query against the DuckDuckGo API.
     * 
     * @param  string $query
     * @throws Exception
     * @return Json
     */
    public function zeroClickQuery(string $query)
    {
        $url = $this->buildUrl($query);
        $http = new Http();
        try {
            $response = $http->request("GET", $url);
            return $response->getBody();
        } catch (ClientException $e) {
            throw new Exception($e->getResponse()->getBody(), $e->getResponse()->getStatusCode());
        } catch (ServerException $e) {
            throw new Exception("Could not retrieve API result.", 503);
        }
    }

    /**
     * Build a url with config parameters and query.
     * 
     * @param string $query
     * @return string $url
     */
    public function BuildUrl(string $query)
    {
        $misc = new Misc();

        $parameters = [
            "q" => urlencode($query),
            "format" => $misc->getConfig("format"),
            "no_html" => $misc->getConfig("html"),
            "no_redirect" => 1,
            "skip_disambig" => $misc->getConfig("disambiguations"),
        ];

        $url = ($misc->getConfig("https")) 
            ? "https://".$this->endpoint."?"
            : "https://".$this->endpoint."?";

        $url .= http_build_query($parameters);
        return $url;
    }<commit_msg>Returning now a valid json<commit_after><?php

namespace DuckDuckGo;

use DuckDuckGo\Misc;
use GuzzleHttp\Client as Http;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;

Class Api
{
    /**
     * Api endpoint url.
     * 
     * @var string
     */
    protected $endpoint;

    /**
     * DuckDuckGo Api constructor.
     */
    public function __construct()
    {
        $this->endpoint = "api.duckduckgo.com/";
    }

    /**
     * Perform a query against the DuckDuckGo API.
     * 
     * @param  string $query
     * @throws Exception
     * @return Json
     */
    public function zeroClickQuery(string $query)
    {
        $url = $this->buildUrl($query);
        $http = new Http();
        try {
            $response = $http->request("GET", $url);
            return $response->getBody()->getContents();
        } catch (ClientException $e) {
            throw new Exception($e->getResponse()->getBody()->getContents(), $e->getResponse()->getStatusCode());
        } catch (ServerException $e) {
            throw new Exception("Could not retrieve API result.", 503);
        }
    }

    /**
     * Build a url with config parameters and query.
     * 
     * @param string $query
     * @return string $url
     */
    public function BuildUrl(string $query)
    {
        $misc = new Misc();

        $parameters = [
            "q" => urlencode($query),
            "format" => $misc->getConfig("format"),
            "no_html" => $misc->getConfig("html"),
            "no_redirect" => 1,
            "skip_disambig" => $misc->getConfig("disambiguations"),
        ];

        $url = ($misc->getConfig("https")) 
            ? "https://".$this->endpoint."?"
            : "https://".$this->endpoint."?";

        $url .= http_build_query($parameters);
        return $url;
    }
{'fraction_non_alphanumeric': 0.15117241379310345, 'fraction_numerical': 0.002206896551724138, 'mean_word_length': 1.989282769991756, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '3270289', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1054, 'n_words': 238}