Skip to content

Commit 629db7f

Browse files
committed
Better location handling. Fixing casing for player container
1 parent 7ba8ca3 commit 629db7f

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

examples/user/GetPlayerSummaries.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Array
3131
[locCountryCode] => US
3232
[locStateCode] => TX
3333
[locCityId] => 3620
34+
[location] => stdClass Object
35+
(
36+
[country] => United States
37+
[state] => Texas
38+
[city] => Dallas
39+
)
3440
)
3541

3642
)

src/Syntax/SteamApi/Containers/Player.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class Player extends BaseContainer {
4646

4747
public $locCityId;
4848

49+
public $location;
50+
4951
public function __construct($player)
5052
{
5153
$this->steamId = $player->steamid;
@@ -63,13 +65,36 @@ public function __construct($player)
6365
$this->avatarFullUrl = $player->avatarfull;
6466
$this->personaState = $this->convertPersonaState($player->personastate);
6567
$this->personaStateId = $player->personastate;
66-
$this->realName = $this->checkIssetField($player, 'realName');
67-
$this->primaryClanId = $this->checkIssetField($player, 'primaryClanId');
68+
$this->realName = $this->checkIssetField($player, 'realname');
69+
$this->primaryClanId = $this->checkIssetField($player, 'primaryclanid');
6870
$this->timecreated = $this->checkIssetField($player, 'timecreated');
69-
$this->personaStateFlags = $this->checkIssetField($player, 'personaStateFlags');
70-
$this->locCountryCode = $this->checkIssetField($player, 'locCountryCode');
71-
$this->locStateCode = $this->checkIssetField($player, 'locStateCode');
72-
$this->locCityId = $this->checkIssetField($player, 'locCityId');
71+
$this->personaStateFlags = $this->checkIssetField($player, 'personastateflags');
72+
$this->locCountryCode = $this->checkIssetField($player, 'loccountrycode');
73+
$this->locStateCode = $this->checkIssetField($player, 'locstatecode');
74+
$this->locCityId = $this->checkIssetField($player, 'loccityid');
75+
$this->location = $this->getLocation();
76+
}
77+
78+
protected function getLocation()
79+
{
80+
$countriesFile = json_decode(\file_get_contents(__DIR__ . '/../Resources/countries.json'));
81+
$result = new \stdClass;
82+
83+
if ($this->locCountryCode != null) {
84+
$result->country = $countriesFile->{$this->locCountryCode}->name;
85+
}
86+
87+
if ($this->locCountryCode != null && $this->locStateCode != null) {
88+
$result->state = $countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->name;
89+
}
90+
91+
if ($this->locCountryCode != null && $this->locStateCode != null && $this->locCityId != null) {
92+
if (! empty($countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities)) {
93+
$result->city = $countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities->{$this->locCityId}->name;
94+
}
95+
}
96+
97+
return $result;
7398
}
7499

75100
protected function convertPersonaState($personaState)

src/Syntax/SteamApi/Resources/countries.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/BaseTester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function checkPlayerProperties($friendsList)
6565
$this->assertObjectHasAttributes($attributes, $friendsList[0]);
6666

6767
$attributes = [
68-
'locCountryCode', 'locStateCode', 'locCityId'
68+
'locCountryCode', 'locStateCode', 'locCityId', 'location'
6969
];
7070
$this->assertObjectHasAttributes($attributes, $friendsList[0]);
7171

0 commit comments

Comments
 (0)