Skip to content

Commit 3d52f4d

Browse files
committed
Fixing an issue where some games would fail to find their achievements due to redirects. Fixes #48
1 parent 3b013bf commit 3d52f4d

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/Syntax/SteamApi/Client.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,26 @@ protected function setUpXml(array $arguments = [])
135135
return simplexml_load_file($steamUrl . '?' . $parameters);
136136
}
137137

138+
public function getRedirectUrl()
139+
{
140+
$ch = curl_init();
141+
curl_setopt($ch, CURLOPT_URL, $this->url);
142+
curl_setopt($ch, CURLOPT_HEADER, true);
143+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
144+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
145+
146+
curl_exec($ch);
147+
$this->url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
148+
curl_close($ch);
149+
}
150+
138151
/**
139-
* @param \Guzzle\Http\Message\RequestInterface $request
152+
* @param \GuzzleHttp\Psr7\Request $request
140153
*
141-
* @throws ApiCallFailedException
142-
* @return stdClass
154+
* @return \stdClass
155+
* @throws \Syntax\SteamApi\Exceptions\ApiCallFailedException
143156
*/
144-
protected function sendRequest($request)
157+
protected function sendRequest(Request $request)
145158
{
146159
// Try to get the result. Handle the possible exceptions that can arise
147160
try {

src/Syntax/SteamApi/Steam/User/Stats.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,17 @@ public function GetPlayerAchievements($appId)
8080
return $achievements;
8181
} catch (\Exception $e) {
8282
// In rare cases, games can force the use of a simplified name instead of an app ID
83-
// In these cases, try again with the name.
83+
// In these cases, try again by grabbing the redirected url.
8484
if (is_int($appId)) {
85-
$app = $this->app()->appDetails($appId);
85+
$this->getRedirectUrl();
8686

87-
if (isset($app->first()->name)) {
88-
$appName = str_replace(' ', '', $app->first()->name);
87+
// Get the client
88+
$client = $this->setUpXml($arguments);
8989

90-
return $this->GetPlayerAchievements($appName);
91-
}
90+
// Clean up the games
91+
$achievements = $this->convertToObjects($client->achievements->achievement);
92+
93+
return $achievements;
9294
}
9395

9496
// If the name and ID fail, return null.

0 commit comments

Comments
 (0)