<commit_before><?php
/*
 * This file is part of the BolOpenApi PHP SDK.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace BolOpenApi;

use BolOpenApi\Exception as BolException;
use BolOpenApi\Factory\ResponseFactory;
use BolOpenApi\Response\ListResultsResponse;
use BolOpenApi\Response\ProductResponse;
use BolOpenApi\Response\SearchResultsResponse;
use Buzz\Browser;

class Client
{
    private $browser;
    private $accessKey;
    private $secretAccessKey;
    private $sessionId;

    /**
     * Constructor: inject settings and dependencies
     * @param $accessKey
     * @param $secretAccessKey
     * @param \Buzz\Browser $browser
     */
    public function __construct($accessKey, $secretAccessKey, Browser $browser)
    {
        $this->accessKey = $accessKey;
        $this->secretAccessKey = $secretAccessKey;
        $this->browser = $browser;
    }

    /**
     * @param string $sessionId
     */
    public function setSessionId($sessionId)
    {
        $this->sessionId = $sessionId;
    }

    /**
     * @return string
     */
    public function getSessionId()
    {
        return $this->sessionId;
    }

    /**
     * Ping service and return api response
     * @return \Buzz\Message\Response
     */
    public function ping()
    {
        $path = '/openapi/services/rest/utils/v3/ping';
        $response = $this->call($path);
        return $response;
    }

    /**
     * @param $term
     * @param array|null $options
     * @return Response\SearchResultsResponse
     */
    public function searchResults($term, array $options = null)
    {
        $path = '/openapi/services/rest/catalog/v3/searchresults';
        $defaulOptions = array(
            'categoryIdAndRefinements'  => null,
            'offset'                    => 0,
            'nrProducts'                => 10,
            'sortingMethod'             => 'price',
            'sortingAscending'          => true,
            'includeProducts'           => true,
            'includeCategories'         => true,
            'includeRefinements'        => true
        );
        $query_parameters = array_merge($this->mergeOptions($defaulOptions, $options), array(
            'term' => $term
        ));
        $uri = $path . '?' . http_build_query($query_parameters);

        $obj = new ResponseFactory();
        return $obj->createSearchResultsResponse($this->getXmlElement($this->call($uri)));
    }

    /**
     * @param string $type
     * @param string $categoryIdAndRefinements
     * @param array|null $options<commit_msg>Fixed invalid parameter in Client::searchResults<commit_after><?php
/*
 * This file is part of the BolOpenApi PHP SDK.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace BolOpenApi;

use BolOpenApi\Exception as BolException;
use BolOpenApi\Factory\ResponseFactory;
use BolOpenApi\Response\ListResultsResponse;
use BolOpenApi\Response\ProductResponse;
use BolOpenApi\Response\SearchResultsResponse;
use Buzz\Browser;

class Client
{
    private $browser;
    private $accessKey;
    private $secretAccessKey;
    private $sessionId;

    /**
     * Constructor: inject settings and dependencies
     * @param $accessKey
     * @param $secretAccessKey
     * @param \Buzz\Browser $browser
     */
    public function __construct($accessKey, $secretAccessKey, Browser $browser)
    {
        $this->accessKey = $accessKey;
        $this->secretAccessKey = $secretAccessKey;
        $this->browser = $browser;
    }

    /**
     * @param string $sessionId
     */
    public function setSessionId($sessionId)
    {
        $this->sessionId = $sessionId;
    }

    /**
     * @return string
     */
    public function getSessionId()
    {
        return $this->sessionId;
    }

    /**
     * Ping service and return api response
     * @return \Buzz\Message\Response
     */
    public function ping()
    {
        $path = '/openapi/services/rest/utils/v3/ping';
        $response = $this->call($path);
        return $response;
    }

    /**
     * @param $term
     * @param array|null $options
     * @return Response\SearchResultsResponse
     */
    public function searchResults($term, array $options = null)
    {
        $path = '/openapi/services/rest/catalog/v3/searchresults';
        $defaulOptions = array(
            'categoryId'  => null,
            'offset'                    => 0,
            'nrProducts'                => 10,
            'sortingMethod'             => 'price',
            'sortingAscending'          => true,
            'includeProducts'           => true,
            'includeCategories'         => true,
            'includeRefinements'        => true
        );
        $query_parameters = array_merge($this->mergeOptions($defaulOptions, $options), array(
            'term' => $term
        ));
        $uri = $path . '?' . http_build_query($query_parameters);

        $obj = new ResponseFactory();
        return $obj->createSearchResultsResponse($this->getXmlElement($this->call($uri)));
    }

    /**
     * @param string $type
     * @param string $categoryIdAndRefinements
     * @param array|null $options
{'fraction_non_alphanumeric': 0.11764705882352941, 'fraction_numerical': 0.0018793459875963165, 'mean_word_length': 2.227410551849606, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, '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': '5417235', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1461, 'n_words': 341}