/** * Returns a singleton instance of an internal <var>WebApi</var> object * * @return WebApi The internal <var>WebApi</var> instance */ private static function instance() { if (self::$instance == null) { self::$instance = new WebApi(); self::$instance->setLogger(\SteamCondenser\getLogger(get_class())); } return self::$instance; }
/** * Loads the global unlock percentages of all achievements for the given * game * * @param int $appId The unique Steam Application ID of the game (e.g. * <var>440</var> for Team Fortress 2). See * http://developer.valvesoftware.com/wiki/Steam_Application_IDs for * all application IDs * @return array The symbolic achievement names with the corresponding * global unlock percentages * @throws \SteamCondenser\Exceptions\WebApiException if a request to * Steam's Web API fails */ public static function getGlobalPercentages($appId) { $params = ['gameid' => $appId]; $data = WebApi::getJSONObject('ISteamUserStats', 'GetGlobalAchievementPercentagesForApp', 2, $params); $percentages = []; foreach ($data->achievementpercentages->achievements as $achievementData) { $percentages[$achievementData->name] = (double) $achievementData->percent; } return $percentages; }
/** * Returns all Golden Wrenches * * @return array All Golden Wrenches * @throws \SteamCondenser\Exceptions\SteamCondenserException If an error * occurs querying the Web API or the Steam Community */ public static function getGoldenWrenches() { if (self::$goldenWrenches == null) { self::$goldenWrenches = []; $data = json_decode(WebApi::getJSON('ITFItems_440', 'GetGoldenWrenches', 2)); foreach ($data->results->wrenches as $wrenchData) { self::$goldenWrenches[] = new TF2GoldenWrench($wrenchData); } } return self::$goldenWrenches; }
/** * Creates a <var>GameStats</var> object and fetches data from the Steam * Community for the given user and game * * @param string $userId The custom URL or the 64bit Steam ID of the user * @param string $appId The app ID or friendly name of the game * @throws SteamCondenserException if the stats cannot be fetched */ protected function __construct($userId, $appId) { $this->schema = GameStatsSchema::create($appId); $this->user = SteamId::create($userId, false); $this->appId = $appId; $this->steamId64 = $this->user->getSteamId64(); $params = ['appid' => $this->schema->getAppId(), 'steamid' => $this->steamId64]; $data = WebApi::getJSONObject('ISteamUserStats', 'GetUserStatsForGame', 2, $params); $this->achievements = []; foreach ($data->playerstats->achievements as $achievement) { $apiName = $achievement->name; $unlocked = $achievement->achieved == 1; $this->achievements[] = $this->schema->getAchievement($apiName)->getInstance($this->user, $unlocked); } $this->values = []; foreach ($data->playerstats->stats as $datum) { $this->values[] = $this->schema->getDatum($datum->name)->getInstance($this->user, $datum->value); } }
/** * Updates the contents of the backpack using Steam Web API */ public function fetch() { $params = ['SteamID' => $this->steamId64]; $result = WebApi::getJSONData("IEconItems_{$this->getAppId()}", 'GetPlayerItems', 1, $params); $this->items = []; $this->preliminaryItems = []; foreach ($result->items as $itemData) { if ($itemData != null) { $inventoryClass = new \ReflectionClass(get_class($this)); $namespace = $inventoryClass->getNamespaceName(); $itemClass = $namespace . '\\' . $inventoryClass->getConstant('ITEM_CLASS'); $item = new $itemClass($this, $itemData); if ($item->isPreliminary()) { $this->preliminaryItems[] = $item; } else { $this->items[$item->getBackpackPosition() - 1] = $item; } } } $this->fetchDate = time(); }
/** * Resolves a vanity URL of a Steam Community profile to a 64bit numeric * SteamID * * @param string $vanityUrl The vanity URL of a Steam Community profile * @return string The 64bit SteamID for the given vanity URL * @throws WebApiException if the request to Steam's Web API fails */ public static function resolveVanityUrl($vanityUrl) { $params = ['vanityurl' => $vanityUrl]; $json = WebApi::getJSON('ISteamUser', 'ResolveVanityURL', 1, $params); $result = json_decode($json); $result = $result->response; if ($result->success != 1) { return null; } return $result->steamid; }
/** * Updates the contents of the backpack using Steam Web API */ protected function internalFetch() { $params = ['SteamID' => $this->steamId64]; $result = WebApi::getJSONData("IEconItems_{$this->getAppId()}", 'GetPlayerItems', 1, $params); $this->items = []; $this->preliminaryItems = []; foreach ($result->items as $itemData) { if ($itemData != null) { $inventoryClass = get_called_class(); $itemClass = $inventoryClass::ITEM_CLASS; $item = new $itemClass($this, $itemData); if ($item->isPreliminary()) { $this->preliminaryItems[] = $item; } else { $this->items[$item->getBackpackPosition() - 1] = $item; } } } }
/** * Returns the overall number of players currently playing this game * * @return int The number of players playing this game */ public function getPlayerCount() { $params = ['appid' => $this->appId]; $result = WebApi::getJSONObject('ISteamUserStats', 'GetNumberOfCurrentPlayers', 1, $params); return $result->response->player_count; }
/** * Fetches the groups this user is member of * * Uses the ISteamUser/GetUserGroupList interface. * * @return SteamGroup[] The groups of this user * @see getGroups() */ public function fetchGroups() { $params = ['steamid' => $this->getSteamId64()]; $result = WebApi::getJSONObject('ISteamUser', 'GetUserGroupList', 1, $params); $this->groups = []; foreach ($result->response->groups as $groupData) { $this->groups[] = SteamGroup::create($groupData->gid, false); } return $this->groups; }