<commit_before><?php

namespace waylaidwanderer\Steamlytics\CSGO;


use waylaidwanderer\Steamlytics\SteamlyticsException;

class CSGO
{
    const BASE_API_URL = "http://csgo.steamlytics.xyz/api/v1/";
    private $apiKey;

    public function __construct($apiKey)
    {
        $this->apiKey = $apiKey;
    }

    /**
     * @param null $from
     * @return Pricelist
     * @throws SteamlyticsException
     */
    public function getPricelist($from = null)
    {
        try {
            $url = self::BASE_API_URL . 'pricelist?key=' . $this->apiKey;
            if ($from) {
                $url .= '&from=' . $from;
            }
            $json = json_decode(file_get_contents($url), true);
            if (!isset($json['success'])) {
                throw new SteamlyticsException('Failed to retrieve v1/pricelist: could not get a response from the API.');
            }
            if ($json['success'] === false) {
                throw new SteamlyticsException('Failed to retrieve v1/pricelist: ' . $json['message']);
            }
            return new Pricelist($json);
        } catch (\Exception $ex) {
            throw new SteamlyticsException('Failed to retrieve v1/pricelist: ' . $ex->getMessage());
        }
    }

    /**
     * @param $marketHashName
     * @param $source
     * @param $from
     * @param $to
     * @return PricesItem
     * @throws SteamlyticsException
     */
    public function getPrice($marketHashName, $source = null, $from = null, $to = null)
    {
        try {
            $url = self::BASE_API_URL . 'prices/' . str_replace('%2F', '%252F', rawurlencode($marketHashName)) . '?key=' . $this->apiKey;
            if ($source) {
                $url .= '&source=' . $source;
            }
            if ($from) {
                $url .= '&from=' . $from;
            }
            if ($to) {
                $url .= '&to=' . $to;
            }
            $json = json_decode(file_get_contents($url), true);
            if (!isset($json['success'])) {
                throw new SteamlyticsException("Failed to retrieve v1/prices for {$marketHashName} (source: {$source}, from: {$from}, to: {$to}): could not get a response from the API.");
            }
            if ($json['success'] === false) {
                throw new SteamlyticsException("Failed to retrieve v1/prices for {$marketHashName} (source: {$source}, from: {$from}, to: {$to}): {$json['message']}");
            }
            return new PricesItem($marketHashName, $json);
        } catch (\Exception $ex) {
            throw new SteamlyticsException("Failed to retrieve v1/prices for {$marketHashName} (source: {$source}, from: {$from}, to: {$to}): " . $ex->getMessage());
        }<commit_msg>Update API url and add new parameters to v1/prices and v1/pricelist<commit_after><?php

namespace waylaidwanderer\Steamlytics\CSGO;


use waylaidwanderer\Steamlytics\SteamlyticsException;

class CSGO
{
    const BASE_API_URL = "http://api.csgo.steamlytics.xyz/v1/";
    private $apiKey;

    public function __construct($apiKey)
    {
        $this->apiKey = $apiKey;
    }

    /**
     * @param null $from
     * @param null $currency
     * @return Pricelist
     * @throws SteamlyticsException
     */
    public function getPricelist($from = null, $currency = null)
    {
        try {
            $url = self::BASE_API_URL . 'pricelist?key=' . $this->apiKey;
            if ($from) {
                $url .= '&from=' . $from;
            }
            if ($currency) {
                $url .= '&currency=' . $currency;
            }
            $json = json_decode(file_get_contents($url), true);
            if (!isset($json['success'])) {
                throw new SteamlyticsException('Failed to retrieve v1/pricelist: could not get a response from the API.');
            }
            if ($json['success'] === false) {
                throw new SteamlyticsException('Failed to retrieve v1/pricelist: ' . $json['message']);
            }
            return new Pricelist($json);
        } catch (\Exception $ex) {
            throw new SteamlyticsException('Failed to retrieve v1/pricelist: ' . $ex->getMessage());
        }
    }

    /**
     * @param $marketHashName
     * @param $source
     * @param $from
     * @param $to
     * @param null $currency
     * @return PricesItem
     * @throws SteamlyticsException
     */
    public function getPrice($marketHashName, $source = null, $from = null, $to = null, $currency = null)
    {
        try {
            $url = self::BASE_API_URL . 'prices/' . str_replace('%2F', '%252F', rawurlencode($marketHashName)) . '?key=' . $this->apiKey;
            if ($source) {
                $url .= '&source=' . $source;
            }
            if ($from) {
                $url .= '&from=' . $from;
            }
            if ($to) {
                $url .= '&to=' . $to;
            }
            if ($currency) {
                $url .= '&currency=' . $currency;
            }
            $json = json_decode(file_get_contents($url), true);
            if (!isset($json['success'])) {
                throw new SteamlyticsException("Failed to retrieve v1/prices for {$marketHashName} (source: {$source}, from: {$from}, to: {$to}): could not get a response from the API.");
            }
            if ($json['success'] === false) {
                throw new SteamlyticsException("Failed to retrieve v1/prices for {$marketHashName} (source: {$source}, from: {$from}, to: {$to}): {$json['message']}");
            }
            return new PricesItem($marketHashName, $json);
        } catch (\Exception $ex) {
            throw new SteamlyticsException("Failed to retrieve v1/prices for {$marketHashName} (source: {$source}, from: {$from}, to: {$to}): " . $ex->getMessage());
        }
{'fraction_non_alphanumeric': 0.15109412990621743, 'fraction_numerical': 0.004168113928447377, 'mean_word_length': 1.9823925427239772, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '5779490', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1681, 'n_words': 414}