Skip to content

Commit b317863

Browse files
Travis BlasingameTravis Blasingame
authored andcommitted
Added automatic steam ID resolution on getPlayerSummaries. Updated docs and examples
1 parent e944ded commit b317863

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ maxlength | int | The maximum number of characters to return | No | null
7373
### Player
7474
The [Player Service](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetOwnedGames_.28v0001.29) is used to get details on players.
7575

76-
When instantiating the player class, you are required to pass a steamId.
76+
When instantiating the player class, you are required to pass a steamId or steam community ID.
7777

7878
```php
7979
Steam::player($steamId)
@@ -137,7 +137,7 @@ appId| int | The game to check for | Yes |
137137
### User
138138
The [User](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetFriendList_.28v0001.29) WebAPI call is used to get details about the user specifically.
139139

140-
When instantiating the user class, you are required to pass a steamId.
140+
When instantiating the user class, you are required to pass a steamId or steam community ID.
141141

142142
```php
143143
Steam::user($steamId)
@@ -187,7 +187,7 @@ steamId| int[] | An array of (or singular) steam id(s) to get details for | No
187187
### User Stats
188188
The [User Stats](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerAchievements_.28v0001.29) WebAPI call is used to get details about a user's gaming.
189189

190-
When instantiating the user stats class, you are required to pass a steamId.
190+
When instantiating the user stats class, you are required to pass a steamId or steam community ID.
191191

192192
```php
193193
Steam::userStats($steamId)

examples/user/GetPlayerSummaries.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Array
33
[0] => Syntax\SteamApi\Containers\Player Object
44
(
55
[steamId] => 76561198022436617
6+
[communityId] => STEAM_0:1:9846342
67
[communityVisibilityState] => 3
78
[profileState] => 1
89
[personaName] => Stygian

src/Syntax/SteamApi/Client.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,24 @@ public function get()
4747
return $this;
4848
}
4949

50-
public function convertCommunityIdToSteamId(int $id)
50+
/**
51+
* @param int $id
52+
*
53+
* @return string
54+
*/
55+
public function convertCommunityIdToSteamId($id)
5156
{
5257
$x = ($id - 76561197960265728) / 2;
5358

5459
return 'STEAM_0:' . is_float($x) . ':' . (int)$x;
5560
}
5661

57-
public function convertSteamIdToCommunityId(string $id)
62+
/**
63+
* @param string $id
64+
*
65+
* @return string
66+
*/
67+
public function convertSteamIdToCommunityId($id)
5868
{
5969
$x = explode(':', $id);
6070
return (string) ($x[2] * 2) + 76561197960265728 + $x[1];

src/Syntax/SteamApi/Containers/Player.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php namespace Syntax\SteamApi\Containers;
22

3+
use Syntax\SteamApi\Client;
4+
35
class Player {
46

57
public $steamId;
68

9+
public $communityId;
10+
711
public $communityVisibilityState;
812

913
public $profileState;
@@ -47,6 +51,7 @@ class Player {
4751
public function __construct($player)
4852
{
4953
$this->steamId = $player->steamid;
54+
$this->communityId = (new Client)->convertCommunityIdToSteamId((int) $this->steamId);
5055
$this->communityVisibilityState = $player->communityvisibilitystate;
5156
$this->profileState = $player->profilestate;
5257
$this->personaName = $player->personaname;

0 commit comments

Comments
 (0)