Skip to content

Commit

Permalink
improve connector methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Nov 15, 2022
1 parent a449307 commit f044a9a
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/SteamConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Astrotomic\SteamSdk;

use Astrotomic\SteamSdk\Data\PlayerBan;
use Astrotomic\SteamSdk\Data\PlayerSummary;
use Astrotomic\SteamSdk\Enums\Relationship;
use Astrotomic\SteamSdk\Enums\VanityType;
use Astrotomic\SteamSdk\Requests\GetAppListRequest;
Expand Down Expand Up @@ -47,20 +49,49 @@ public function defaultQuery(): array
]);
}

/**
* @return \Spatie\LaravelData\DataCollection<array-key, \Astrotomic\SteamSdk\Data\ApiInterface>
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
*/
public function getSupportedApiList(): DataCollection
{
return $this->send(
new GetSupportedApiListRequest()
)->dto();
}

/**
* @param string|null $countrycode
* @param string|null $statecode
* @return \Spatie\LaravelData\DataCollection<array-key, \Astrotomic\SteamSdk\Data\LocationCountry|\Astrotomic\SteamSdk\Data\LocationState|\Astrotomic\SteamSdk\Data\LocationCity>
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
*/
public function queryLocations(?string $countrycode = null, ?string $statecode = null): DataCollection
{
return $this->send(
new QueryLocationsRequest($countrycode, $statecode)
)->dto();
}

/**
* @param int $appid
* @param int|null $maxlength
* @param \Carbon\CarbonInterface|null $enddate
* @param int|null $count
* @param array|null $feeds
* @param array|null $tags
* @return \Spatie\LaravelData\DataCollection<array-key, \Astrotomic\SteamSdk\Data\NewsItem>
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
*/
public function getNewsForApp(
int $appid,
int|null $maxlength = null,
Expand All @@ -74,34 +105,104 @@ public function getNewsForApp(
)->dto();
}

/**
* @param int $gameid
* @return \Spatie\LaravelData\DataCollection<array-key, \Astrotomic\SteamSdk\Data\AchievementPercentage>
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
*/
public function getGlobalAchievementPercentagesForApp(int $gameid): DataCollection
{
return $this->send(
new GetGlobalAchievementPercentagesForAppRequest($gameid)
)->dto();
}

/**
* @param array<array-key, string>|string $steamids
* @return \Spatie\LaravelData\DataCollection<array-key, \Astrotomic\SteamSdk\Data\PlayerSummary>
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
*/
public function getPlayerSummaries(array|string $steamids): DataCollection
{
return $this->send(
new GetPlayerSummariesRequest($steamids)
)->dto();
}

/**
* @param string $steamid
* @return \Astrotomic\SteamSdk\Data\PlayerSummary|null
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
*/
public function getPlayerSummary(string $steamid): ?PlayerSummary
{
return $this->send(
new GetPlayerSummariesRequest($steamid)
)->dto()->toCollection()->firstWhere('steamid', $steamid);
}

/**
* @param string $steamid
* @param \Astrotomic\SteamSdk\Enums\Relationship|null $relationship
* @return \Spatie\LaravelData\DataCollection<array-key, \Astrotomic\SteamSdk\Data\Friend>
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
*/
public function getFriendList(string $steamid, ?Relationship $relationship = null): DataCollection
{
return $this->send(
new GetFriendListRequest($steamid, $relationship)
)->dto();
}

/**
* @param array<array-key, string>|string $steamids
* @return \Spatie\LaravelData\DataCollection<array-key, \Astrotomic\SteamSdk\Data\PlayerBan>
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
*/
public function getPlayerBans(array|string $steamids): DataCollection
{
return $this->send(
new GetPlayerBansRequest($steamids)
)->dto();
}

/**
* @param string $steamid
* @return \Astrotomic\SteamSdk\Data\PlayerBan|null
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
*/
public function getPlayerBan(string $steamid): ?PlayerBan
{
return $this->send(
new GetPlayerBansRequest($steamid)
)->dto()->toCollection()->firstWhere('steamid', $steamid);
}

/**
* @return \Spatie\LaravelData\DataCollection<array-key, \Astrotomic\SteamSdk\Data\App>
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
*/
public function getAppList(): DataCollection
{
return $this->send(
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/Requests/GetPlayerBansRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
Assert::assertSame($ban->steamid, $ban->steamid()->ConvertToUInt64());
});
})->with('userids');

it('returns single player bans', function (string $steamid): void {
$ban = app(SteamConnector::class)->getPlayerBan(steamid: $steamid);

Assert::assertInstanceOf(PlayerBan::class, $ban);

Assert::assertSame($ban->steamid, $ban->steamid()->ConvertToUInt64());
})->with('userids');
12 changes: 12 additions & 0 deletions tests/Feature/Requests/GetPlayerSummariesRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@
UrlAssertions::assertValidLoose($player->avatarfull);
});
})->with('userids');

it('returns single player summary', function (string $steamid): void {
$player = app(SteamConnector::class)->getPlayerSummary(steamid: $steamid);

Assert::assertInstanceOf(PlayerSummary::class, $player);

Assert::assertSame($player->steamid, $player->steamid()->ConvertToUInt64());
UrlAssertions::assertValidLoose($player->profileurl);
UrlAssertions::assertValidLoose($player->avatar);
UrlAssertions::assertValidLoose($player->avatarmedium);
UrlAssertions::assertValidLoose($player->avatarfull);
})->with('userids');

0 comments on commit f044a9a

Please sign in to comment.