Skip to content

Commit

Permalink
add ResolveVanityURL request
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Nov 7, 2022
1 parent 762a754 commit 9b833a6
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $steam->getPlayerSummaries($steamid);
|| **GET** | `ISteamUser/GetFriendList/v1` | `$steam->getFriendList()` |
|| **GET** | `ISteamUser/GetPlayerBans/v1` | `$steam->getPlayerBans()` |
|| **GET** | `ISteamUser/GetPlayerSummaries/v2` | `$steam->getPlayerSummaries()` |
|| **GET** | `ISteamUser/ResolveVanityURL/v1` | `$steam->resolveVanityUrl()` |
|| **GET** | `ISteamUserStats/GetGlobalAchievementPercentagesForApp/v2` | `$steam->getGlobalAchievementPercentagesForApp()` |
|| **GET** | `ISteamWebAPIUtil/GetSupportedAPIList/v1` | `$steam->getSupportedApiList()` |
|| **GET** | `actions/QueryLocations` | `$steam->queryLocations()` |
Expand All @@ -47,7 +48,6 @@ $steam->getPlayerSummaries($steamid);
| 🗒️ | **GET** | `IPlayerService/GetSteamLevel/v1` | |
| 🗒️ | **GET** | `IPlayerService/IsPlayingSharedGame/v1` | |
| 🗒️ | **GET** | `ISteamUser/GetUserGroupList/v1` | |
| 🗒️ | **GET** | `ISteamUser/ResolveVanityURL/v1` | |
| 🗒️ | **GET** | `ISteamUserStats/GetGlobalStatsForGame/v1` | |
| 🗒️ | **GET** | `ISteamUserStats/GetNumberOfCurrentPlayers/v1` | |
| 🗒️ | **GET** | `ISteamUserStats/GetPlayerAchievements/v1` | |
Expand Down
10 changes: 10 additions & 0 deletions src/Enums/VanityType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Astrotomic\SteamSdk\Enums;

enum VanityType: int
{
case Individual = 1;
case Group = 2;
case GameGroup = 3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Sammyjo20\Saloon\Http\SaloonResponse;
use Sammyjo20\Saloon\Traits\Plugins\CastsToDto;

class GetSupportedAPIListRequest extends SaloonRequest
class GetSupportedApiListRequest extends SaloonRequest
{
use CastsToDto;

Expand Down
30 changes: 30 additions & 0 deletions src/Requests/ResolveVanityUrlRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Astrotomic\SteamSdk\Requests;

use Astrotomic\SteamSdk\Enums\VanityType;
use Sammyjo20\Saloon\Http\SaloonRequest;

class ResolveVanityUrlRequest extends SaloonRequest
{
protected ?string $method = 'GET';

public function __construct(
public readonly string $vanityurl,
public readonly VanityType $url_type,
) {
}

public function defineEndpoint(): string
{
return '/ISteamUser/ResolveVanityURL/v1';
}

public function defaultQuery(): array
{
return [
'vanityurl' => $this->vanityurl,
'url_type' => $this->url_type->value,
];
}
}
21 changes: 19 additions & 2 deletions src/SteamConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@
use Astrotomic\SteamSdk\Collections\PlayerBanCollection;
use Astrotomic\SteamSdk\Collections\PlayerSummaryCollection;
use Astrotomic\SteamSdk\Enums\Relationship;
use Astrotomic\SteamSdk\Enums\VanityType;
use Astrotomic\SteamSdk\Requests\GetAppListRequest;
use Astrotomic\SteamSdk\Requests\GetFriendListRequest;
use Astrotomic\SteamSdk\Requests\GetGlobalAchievementPercentagesForAppRequest;
use Astrotomic\SteamSdk\Requests\GetNewsForAppRequest;
use Astrotomic\SteamSdk\Requests\GetPlayerBansRequest;
use Astrotomic\SteamSdk\Requests\GetPlayerSummariesRequest;
use Astrotomic\SteamSdk\Requests\GetSupportedAPIListRequest;
use Astrotomic\SteamSdk\Requests\GetSupportedApiListRequest;
use Astrotomic\SteamSdk\Requests\QueryLocationsRequest;
use Astrotomic\SteamSdk\Requests\ResolveVanityUrlRequest;
use Astrotomic\SteamSdk\Responses\SteamResponse;
use Carbon\CarbonInterface;
use InvalidArgumentException;
use Sammyjo20\Saloon\Http\SaloonConnector;
use Sammyjo20\Saloon\Traits\Plugins\AcceptsJson;
use Sammyjo20\Saloon\Traits\Plugins\AlwaysThrowsOnErrors;
use SteamID;

class SteamConnector extends SaloonConnector
{
Expand Down Expand Up @@ -55,7 +59,7 @@ public function defaultQuery(): array
public function getSupportedApiList(): ApiInterfaceCollection
{
return $this->send(
new GetSupportedAPIListRequest()
new GetSupportedApiListRequest()
)->dto();
}

Expand Down Expand Up @@ -115,4 +119,17 @@ public function getAppList(): AppCollection
new GetAppListRequest()
)->dto();
}

public function resolveVanityUrl(string $vanityurl): ?SteamID
{
try {
return SteamID::SetFromURL($vanityurl, function (string $vanityurl, int $type): ?string {
return $this->send(
new ResolveVanityUrlRequest($vanityurl, VanityType::from($type))
)->json('response.steamid');
});
} catch (InvalidArgumentException) {
return null;
}
}
}
24 changes: 24 additions & 0 deletions tests/Feature/Requests/ResolveVanityUrlRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use PHPUnit\Framework\Assert;

it('returns resolved steamid', closure: function (string $vanityurl, string $expected): void {
$steamid = $this->steam->resolveVanityUrl(vanityurl: $vanityurl);

Assert::assertInstanceOf(SteamID::class, $steamid);
Assert::assertSame($expected, $steamid->ConvertToUInt64());
})->with([
['https://steamcommunity.com/profiles/76561198061912622', '76561198061912622'],
['https://steamcommunity.com/profiles/[U:1:101646894]', '76561198061912622'],
['https://steamcommunity.com/id/gummibeer/', '76561198061912622'],
['https://s.team/p/jbw-bddv', '76561198061912622'],
['https://steamcommunity.com/groups/archiasf', '103582791440160998'],
]);

it('returns null for invalid vanity', closure: function (string $vanityurl): void {
$steamid = $this->steam->resolveVanityUrl(vanityurl: $vanityurl);

Assert::assertNull($steamid);
})->with([
'https://steamcommunity.com/profiles/[U:1:jbw-bddv]',
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"statusCode":200,"headers":{"Server":["nginx"],"Content-Type":["application\/json; charset=UTF-8"],"Expires":["Mon, 07 Nov 2022 20:53:39 GMT"],"Date":["Mon, 07 Nov 2022 20:53:39 GMT"],"Content-Length":["57"],"Connection":["keep-alive"]},"data":"{\"response\":{\"steamid\":\"103582791440160998\",\"success\":1}}"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"statusCode":200,"headers":{"Server":["nginx"],"Content-Type":["application\/json; charset=UTF-8"],"Expires":["Mon, 07 Nov 2022 20:52:02 GMT"],"Date":["Mon, 07 Nov 2022 20:52:02 GMT"],"Content-Length":["56"],"Connection":["keep-alive"]},"data":"{\"response\":{\"steamid\":\"76561198061912622\",\"success\":1}}"}

0 comments on commit 9b833a6

Please sign in to comment.