1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Syntax\SteamApi\Steam; |
4
|
|
|
|
5
|
|
|
use Syntax\SteamApi\Client; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use Syntax\SteamApi\Containers\Game; |
8
|
|
|
use Syntax\SteamApi\Containers\Player\Level; |
9
|
|
|
|
10
|
|
|
class Player extends Client |
11
|
|
|
{ |
12
|
|
|
public function __construct($steamId) |
13
|
|
|
{ |
14
|
|
|
parent::__construct(); |
15
|
|
|
$this->interface = 'IPlayerService'; |
16
|
|
|
$this->isService = true; |
17
|
|
|
$this->steamId = $steamId; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function GetSteamLevel() |
21
|
|
|
{ |
22
|
|
|
// Set up the api details |
23
|
|
|
$this->setApiDetails(__FUNCTION__, 'v0001'); |
24
|
|
|
|
25
|
|
|
// Set up the arguments |
26
|
|
|
$arguments = ['steamId' => $this->steamId]; |
27
|
|
|
|
28
|
|
|
// Get the client |
29
|
|
|
$client = $this->getServiceResponse($arguments); |
30
|
|
|
|
31
|
|
|
return $client->player_level; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function GetPlayerLevelDetails() |
35
|
|
|
{ |
36
|
|
|
$details = $this->GetBadges(); |
37
|
|
|
|
38
|
|
|
$details = new Level($details); |
39
|
|
|
|
40
|
|
|
return $details; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function GetBadges() |
44
|
|
|
{ |
45
|
|
|
// Set up the api details |
46
|
|
|
$this->setApiDetails(__FUNCTION__, 'v0001'); |
47
|
|
|
|
48
|
|
|
// Set up the arguments |
49
|
|
|
$arguments = ['steamId' => $this->steamId]; |
50
|
|
|
|
51
|
|
|
// Get the client |
52
|
|
|
return $this->getServiceResponse($arguments); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function GetCommunityBadgeProgress($badgeId = null) |
56
|
|
|
{ |
57
|
|
|
// Set up the api details |
58
|
|
|
$this->setApiDetails(__FUNCTION__, 'v0001'); |
59
|
|
|
|
60
|
|
|
// Set up the arguments |
61
|
|
|
$arguments = ['steamId' => $this->steamId]; |
62
|
|
|
if ($badgeId != null) { |
63
|
|
|
$arguments['badgeid'] = $badgeId; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Get the client |
67
|
|
|
return $this->getServiceResponse($arguments); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function GetOwnedGames($includeAppInfo = true, $includePlayedFreeGames = false, $appIdsFilter = []) |
71
|
|
|
{ |
72
|
|
|
// Set up the api details |
73
|
|
|
$this->setApiDetails(__FUNCTION__, 'v0001'); |
74
|
|
|
|
75
|
|
|
// Set up the arguments |
76
|
|
|
$arguments = ['steamId' => $this->steamId]; |
77
|
|
|
if ($includeAppInfo) { |
78
|
|
|
$arguments['include_appinfo'] = $includeAppInfo; |
79
|
|
|
} |
80
|
|
|
if ($includePlayedFreeGames) { |
81
|
|
|
$arguments['include_played_free_games'] = $includePlayedFreeGames; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$appIdsFilter = (array) $appIdsFilter; |
85
|
|
|
|
86
|
|
|
if (count($appIdsFilter) > 0) { |
87
|
|
|
$arguments['appids_filter'] = $appIdsFilter; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// Get the client |
91
|
|
|
$client = $this->getServiceResponse($arguments); |
92
|
|
|
|
93
|
|
|
// Clean up the games |
94
|
|
|
return $this->convertToObjects(isset($client->games) ? $client->games : []); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function GetRecentlyPlayedGames($count = null) |
98
|
|
|
{ |
99
|
|
|
// Set up the api details |
100
|
|
|
$this->setApiDetails(__FUNCTION__, 'v0001'); |
101
|
|
|
|
102
|
|
|
// Set up the arguments |
103
|
|
|
$arguments = ['steamId' => $this->steamId]; |
104
|
|
|
if (! is_null($count)) { |
105
|
|
|
$arguments['count'] = $count; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
// Get the client |
109
|
|
|
$client = $this->getServiceResponse($arguments); |
110
|
|
|
|
111
|
|
|
if (isset($client->total_count) && $client->total_count > 0) { |
112
|
|
|
// Clean up the games |
113
|
|
|
return $this->convertToObjects($client->games); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return null; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function IsPlayingSharedGame($appIdPlaying) |
120
|
|
|
{ |
121
|
|
|
// Set up the api details |
122
|
|
|
$this->setApiDetails(__FUNCTION__, 'v0001'); |
123
|
|
|
|
124
|
|
|
// Set up the arguments |
125
|
|
|
$arguments = [ |
126
|
|
|
'steamId' => $this->steamId, |
127
|
|
|
'appid_playing' => $appIdPlaying, |
128
|
|
|
]; |
129
|
|
|
|
130
|
|
|
// Get the client |
131
|
|
|
$client = $this->getServiceResponse($arguments); |
132
|
|
|
|
133
|
|
|
return $client->lender_steamid; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
protected function convertToObjects($games) |
137
|
|
|
{ |
138
|
|
|
$convertedGames = $this->convertGames($games); |
139
|
|
|
|
140
|
|
|
$games = $this->sortObjects($convertedGames); |
141
|
|
|
|
142
|
|
|
return $games; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
private function convertGames($games) |
146
|
|
|
{ |
147
|
|
|
$convertedGames = new Collection; |
148
|
|
|
|
149
|
|
|
foreach ($games as $game) { |
150
|
|
|
$convertedGames->add(new Game($game)); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $convertedGames; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|