<commit_before><?php

namespace Fabs\SteamLibrary\Game;

use Fabs\SteamLibrary\Model\SteamInventoryModel;
use Fabs\SteamLibrary\Model\SteamItemModel;
use GuzzleHttp\Client;

class InventoryBase
{
    /**
     * @param $partner_id string|int
     * @param $game_id string
     * @param $game_context string
     * @return SteamItemModel[]
     */
    protected static function getSteamItemsFromPartnerID($partner_id, $game_id, $game_context)
    {
        $inventory = self::getSteamInventoryFromPartnerID($partner_id, $game_id, $game_context);
        return self::getSteamItemsFromInventory($inventory);
    }

    /**
     * @param $partner_id string|int
     * @param $game_id string
     * @param $game_context string
     * @return SteamInventoryModel
     */
    private static function getSteamInventoryFromPartnerID($partner_id, $game_id, $game_context)
    {
        $steam_id = self::getSteamIDFromPartnerID($partner_id);
        return self::getSteamInventoryFromSteamID($steam_id, $game_id, $game_context);
    }

    /**
     * @param $partner_id string|int
     * @return string
     */
    public static function getSteamIDFromPartnerID($partner_id)
    {
        return '765' . (intval($partner_id) + 61197960265728);
    }

    /**
     * @param $steam_id string
     * @param $game_id string
     * @param $game_context string
     * @return SteamItemModel[]
     */
    protected static function getSteamItemsFromSteamID($steam_id, $game_id, $game_context)
    {
        $inventory = self::getSteamInventoryFromSteamID($steam_id, $game_id, $game_context);
        return self::getSteamItemsFromInventory($inventory);
    }

    /**
     * @param $steam_id string
     * @param $game_id string
     * @param $game_context string
     * @return SteamInventoryModel
     */
    private static function getSteamInventoryFromSteamID($steam_id, $game_id, $game_context)
    {
        $url = sprintf('https://steamcommunity.com/inventory/%s/%s/%s',
            $steam_id, (string)$game_id, (string)$game_context);
        $client = new Client();
        $json_content = $client->get($url)->getBody()->getContents();
        $content = json_decode($json_content, true);
        /** @var SteamInventoryModel $object */
        $object = SteamInventoryModel::deserialize($content);
        return $object;
    }

    /**
     * @param $inventory SteamInventoryModel
     * @return SteamItemModel[]
     */
    private static function getSteamItemsFromInventory($inventory)
    {
        $steam_items = [];
        foreach ($inventory->assets as $asset)
        {
            $steam_item = new SteamItemModel();
            $steam_item->assetid = $asset->assetid;
            foreach ($inventory->descriptions as $description)
            {
                if ($asset->classid === $description->classid && $asset->instanceid === $description->instanceid)
                {
                    $steam_item->description = $description;
                    break;
                }
            }
            $steam_items[] = $steam_item;
        }
        return $steam_items;
    }
}<commit_msg>ADD image base url for icon and icon_large<commit_after><?php

namespace Fabs\SteamLibrary\Game;

use Fabs\SteamLibrary\Model\SteamInventoryModel;
use Fabs\SteamLibrary\Model\SteamItemModel;
use GuzzleHttp\Client;

class InventoryBase
{
    const BASE_IMAGE_URL = 'http://cdn.steamcommunity.com/economy/image/';

    /**
     * @param $partner_id string|int
     * @param $game_id string
     * @param $game_context string
     * @return SteamItemModel[]
     */
    protected static function getSteamItemsFromPartnerID($partner_id, $game_id, $game_context)
    {
        $inventory = self::getSteamInventoryFromPartnerID($partner_id, $game_id, $game_context);
        return self::getSteamItemsFromInventory($inventory);
    }

    /**
     * @param $partner_id string|int
     * @param $game_id string
     * @param $game_context string
     * @return SteamInventoryModel
     */
    private static function getSteamInventoryFromPartnerID($partner_id, $game_id, $game_context)
    {
        $steam_id = self::getSteamIDFromPartnerID($partner_id);
        return self::getSteamInventoryFromSteamID($steam_id, $game_id, $game_context);
    }

    /**
     * @param $partner_id string|int
     * @return string
     */
    public static function getSteamIDFromPartnerID($partner_id)
    {
        return '765' . (intval($partner_id) + 61197960265728);
    }

    /**
     * @param $steam_id string
     * @param $game_id string
     * @param $game_context string
     * @return SteamItemModel[]
     */
    protected static function getSteamItemsFromSteamID($steam_id, $game_id, $game_context)
    {
        $inventory = self::getSteamInventoryFromSteamID($steam_id, $game_id, $game_context);
        return self::getSteamItemsFromInventory($inventory);
    }

    /**
     * @param $steam_id string
     * @param $game_id string
     * @param $game_context string
     * @return SteamInventoryModel
     */
    private static function getSteamInventoryFromSteamID($steam_id, $game_id, $game_context)
    {
        $url = sprintf('https://steamcommunity.com/inventory/%s/%s/%s',
            $steam_id, (string)$game_id, (string)$game_context);
        $client = new Client();
        $json_content = $client->get($url)->getBody()->getContents();
        $content = json_decode($json_content, true);
        /** @var SteamInventoryModel $object */
        $object = SteamInventoryModel::deserialize($content);
        return $object;
    }

    /**
     * @param $inventory SteamInventoryModel
     * @return SteamItemModel[]
     */
    private static function getSteamItemsFromInventory($inventory)
    {
        $steam_items = [];
        foreach ($inventory->assets as $asset)
        {
            $steam_item = new SteamItemModel();
            $steam_item->assetid = $asset->assetid;
            foreach ($inventory->descriptions as $description)
            {
                if ($asset->classid === $description->classid && $asset->instanceid === $description->instanceid)
                {
                    $steam_item->description = $description;
                    break;
                }
            }
            if ($steam_item->description != null)
            {
                if ($steam_item->description->icon_url != null)
                {
                    $steam_item->description->icon_url = self::BASE_IMAGE_URL
                        . $steam_item->description->icon_url;
                }

                if ($steam_item->description->icon_url_large != null)
                {
                    $steam_item->description->icon_url_large = self::BASE_IMAGE_URL
                        . $steam_item->description->icon_url_large;
                }
            }
            $steam_items[] = $steam_item;
        }

        return $steam_items;
    }
}
{'fraction_non_alphanumeric': 0.11808278867102397, 'fraction_numerical': 0.0049382716049382715, 'mean_word_length': 2.504325699745547, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, 'https://': 2, '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': '4115348', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2080, 'n_words': 355}