Skip to content

Commit

Permalink
[Laravel 10] Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nicekiwi committed Apr 27, 2024
1 parent ef5b7e0 commit 98af434
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 118 deletions.
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ Next, update composer from the terminal.
Lastly, publish the config file. You can get your API key from [Steam](http://steamcommunity.com/dev/apikey).

php artisan vendor:publish
php artisan vendor:publish --provider="Syntax\SteamApi\SteamApiServiceProvider"

## Usage

```php
use SteamApi;

/** Get Portal 2 */
$apps = SteamApi::app()->appDetails([620]);

echo $app->first()->name;
```

Each service from the Steam API has its own methods you can use.

- [Global](#global)
Expand Down Expand Up @@ -75,7 +84,7 @@ format | string | The format you want back. | No | null
##### Example usage

```php
Steam::convertId($id, $format);
SteamApi::convertId($id, $format);
```

> Example Output: [convertId](./examples/global/convertId.txt)
Expand All @@ -84,7 +93,7 @@ Steam::convertId($id, $format);
The [Steam News](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetNewsForApp_.28v0002.29) web api is used to get articles for games.

```php
Steam::news()
SteamApi::news()
```

#### GetNewsForApp
Expand All @@ -102,7 +111,7 @@ maxlength | int | The maximum number of characters to return | No | null

```php
<?php
$news = Steam::news()->GetNewsForApp($appId, 5, 500)->newsitems;
$news = SteamApi::news()->GetNewsForApp($appId, 5, 500)->newsitems;
?>
```

Expand All @@ -114,7 +123,7 @@ The [Player Service](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetO
When instantiating the player class, you are required to pass a steamId or Steam community ID.

```php
Steam::player($steamId)
SteamApi::player($steamId)
```

#### GetSteamLevel
Expand Down Expand Up @@ -178,7 +187,7 @@ The [User](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetFriendList_
When instantiating the user class, you are required to pass at least one steamId or steam community ID.

```php
Steam::user($steamId)
SteamApi::user($steamId)
```

#### ResolveVanityURL
Expand All @@ -191,7 +200,7 @@ Name | Type | Description | Required | Default
displayName| string | The display name to get the steam ID for. In `http://steamcommunity.com/id/gabelogannewell` it would be `gabelogannewell`. | Yes | NULL

```php
$player = Steam::user($steamId)->ResolveVanityURL('gabelogannewell');
$player = SteamApi::user($steamId)->ResolveVanityURL('gabelogannewell');
```

> Example Output: [ResolveVanityURL](./examples/user/ResolveVanityURL.txt)
Expand All @@ -208,11 +217,11 @@ steamId| int[] | An array of (or singular) steam ID(s) to get details for | No
```php
// One user
$steamId = 76561197960287930;
$player = Steam::user($steamId)->GetPlayerSummaries()[0];
$player = SteamApi::user($steamId)->GetPlayerSummaries()[0];

// Several users
$steamIds = [76561197960287930, 76561197968575517]
$players = Steam::user($steamIds)->GetPlayerSummaries();
$players = SteamApi::user($steamIds)->GetPlayerSummaries();
```

> Example Output: [GetPlayerSummaries](./examples/user/GetPlayerSummaries.txt)
Expand Down Expand Up @@ -250,7 +259,7 @@ The [User Stats](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlaye
When instantiating the user stats class, you are required to pass a steamID or Steam community ID.

```php
Steam::userStats($steamId)
SteamApi::userStats($steamId)
```

#### GetPlayerAchievements
Expand Down Expand Up @@ -306,7 +315,7 @@ appId| int | The ID of the game you want the details for. | Yes |
This area will get details for games.

```php
Steam::app()
SteamApi::app()
```

#### appDetails
Expand All @@ -332,7 +341,7 @@ This method will return an array of app objects directly from Steam. It include
This method will get details for packages.

```php
Steam::package()
SteamApi::package()
```

#### packageDetails
Expand All @@ -353,7 +362,7 @@ l | string | The l is the language parameter, you can get the appropriate langua
This method will get user inventory for item.

```php
Steam::item()
SteamApi::item()
```

#### GetPlayerItems
Expand All @@ -374,7 +383,7 @@ steamid | int | The steamid of the Steam user you want for | Yes |
This service is used to get details on a Steam group.

```php
Steam::group()
SteamApi::group()
```

#### GetGroupSummary
Expand All @@ -390,7 +399,7 @@ group| string or int | The ID or the name of the group. | Yes

```php
<?php
$news = Steam::group()->GetGroupSummary('Valve');
$news = SteamApi::group()->GetGroupSummary('Valve');
?>
```

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^10.5",
"phpunit/phpunit": "^10.5|^11.0",
"orchestra/testbench": "^8.0",
"vlucas/phpdotenv": "^5.6",
"rector/rector": "^1.0"
Expand Down
66 changes: 0 additions & 66 deletions src/Syntax/SteamApi/Command/SteamAppGrabber.php

This file was deleted.

16 changes: 8 additions & 8 deletions src/Syntax/SteamApi/Steam/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,40 @@ public function __construct()
* @throws ApiCallFailedException
* @throws GuzzleException
*/
public function packageDetails($packIds, $cc = null, $language = null): Collection
public function packageDetails($packId, $cc = null, $language = null): Collection
{
// Set up the api details
$this->method = 'packagedetails';
$this->version = null;
// Set up the arguments
$arguments = [
'packageids' => $packIds,
'packageids' => $packId,
'cc' => $cc,
'l' => $language,
];
// Get the client
$client = $this->setUpClient($arguments);

return $this->convertToObjects($client, $packIds);
return $this->convertToObjects($client, $packId);
}

protected function convertToObjects($package, $packIds): Collection
protected function convertToObjects($package, $packId): Collection
{
$convertedPacks = $this->convertPacks($package, $packIds);
$convertedPacks = $this->convertPacks($package, $packId);
return $this->sortObjects($convertedPacks);
}

/**
* @param $packages
* @param $packIds
* @param $packId
* @return Collection
*/
protected function convertPacks($packages, $packIds): Collection
protected function convertPacks($packages, $packId): Collection
{
$convertedPacks = new Collection();
foreach ($packages as $package) {
if (isset($package->data)) {
$convertedPacks->add(new PackageContainer($package->data, $packIds));
$convertedPacks->add(new PackageContainer($package->data, $packId));
}
}

Expand Down
31 changes: 4 additions & 27 deletions src/Syntax/SteamApi/SteamApiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@

namespace Syntax\SteamApi;

use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;

class SteamApiServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
public function boot(): void
{
$this->publishes([__DIR__ . '/../../config/config.php' => config_path('steam-api.php')]);
}
Expand All @@ -29,32 +21,17 @@ public function boot()
*
* @return void
*/
public function register()
{
$this->registerAlias();

$this->app->singleton('steam-api', fn() => new Client);
}

/**
* Register the alias for package.
*
* @return void
*/
protected function registerAlias()
public function register(): void
{
$this->app->booting(function () {
$loader = AliasLoader::getInstance();
$loader->alias('Steam', \Syntax\SteamApi\Facades\SteamApi::class);
});
$this->app->singleton('steam-api', fn () => new Client());
}

/**
* Get the services provided by the provider.
*
* @return string[]
*/
public function provides()
public function provides(): array
{
return ['steam-api'];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function it_gets_details_for_an_package_by_id()
/**
* @param $detail
*/
private function checkPackageClasses($detail)
private function checkPackageClasses($detail): void
{
$this->assertInstanceOf(\Syntax\SteamApi\Containers\Package::class, $detail);
}
Expand Down

0 comments on commit 98af434

Please sign in to comment.