Skip to content

Commit

Permalink
Merge pull request syntaxerrors#74 from jastend/master
Browse files Browse the repository at this point in the history
Language attribute for client requests
  • Loading branch information
stygiansabyss committed Jul 19, 2018
2 parents f62796c + e1227aa commit 881be37
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ before_script:
script:
- phpunit --coverage-clover=coverage.clover
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Each service from the Steam API has its own methods you can use.
- [User](#user)
- [User Stats](#user-stats)
- [App](#app)
- [Package](#package)
- [Group](#group)

### Global
Expand Down Expand Up @@ -310,13 +311,15 @@ Steam::app()
```

#### appDetails
This gets all the details for a game. This is most of the infomation from the store page of a game.
This gets all the details for a game. This is most of the information from the store page of a game.

##### Arguments

Name | Type | Description | Required | Default
-----|------|-------------|----------|---------
appIds| int[] | The ids of the games you want details for | Yes |
cc | string | The cc is the country code, you can get appropriate currency values according to [ISO 3166-1](https://wikipedia.org/wiki/ISO_3166-1) | No |
l | string | The l is the language parameter, you can get the appropriate language according to [ISO 639-1](https://wikipedia.org/wiki/ISO_639-1) (If there is one) | No |


> Example Output: [appDetails](./examples/app/appDetails.txt)
Expand All @@ -326,6 +329,27 @@ This method will return an array of app objects directly from Steam. It include

> Example Output: [GetAppList](./examples/app/GetAppList.txt)
### Package
This method will get details for packages.

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

#### packageDetails
This gets all the details for a package. This is most of the information from the store page of a package.

##### Arguments

Name | Type | Description | Required | Default
-----|------|-------------|----------|---------
packIds| int[] | The ids of the packages you want details for | Yes |
cc | string | The cc is the country code, you can get appropriate currency values according to [ISO 3166-1](https://wikipedia.org/wiki/ISO_3166-1) | No |
l | string | The l is the language parameter, you can get the appropriate language according to [ISO 639-1](https://wikipedia.org/wiki/ISO_639-1) (If there is one) | No |


> Example Output: [packageDetails](./examples/package/packageDetails.txt)
### Group
This service is used to get details on a Steam group.

Expand Down
47 changes: 47 additions & 0 deletions examples/package/packageDetails.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Array
(
[0] => stdClass Object
(
[id] => 76710
[name] => Just Cause 3 XL
[page_image] => https: //steamcdn-a.akamaihd.net/steam/subs/76710/header.jpg?t=1449600260
[header] => https: //steamcdn-a.akamaihd.net/steam/subs/76710/header_ratio.jpg?t=1449600260
[small_logo] => https: //steamcdn-a.akamaihd.net/steam/subs/76710/capsule_231x87.jpg?t=1449600260
[apps] => Array(
[0] => stdClass Object(
[id] => 225540
[name] => Just Cause™ 3
)

[1] => stdClass Object(
[id] => 401850
[name] => Just Cause™ 3 DLC: Air, Land & Sea Expansion Pass
)

)

[page_content] => none[price] => stdClass Object(
[currency] => USD
[initial] => 4499
[final] => 4499
[discount_percent] => 0
[individual] => 4498
)

[platforms] => stdClass Object(
[windows] => 1
[mac] =>
[linux] =>
)

[release] => stdClass Object(
[coming_soon] =>
[date] =>
)

[controller] => stdClass Object(
[full_gamepad] => 1
)

)
)
1 change: 1 addition & 0 deletions src/Syntax/SteamApi/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @method \Syntax\SteamApi\Steam\User user($steamId)
* @method \Syntax\SteamApi\Steam\User\Stats userStats($steamId)
* @method \Syntax\SteamApi\Steam\App app()
* @method \Syntax\Steamapi\Steam\Package package()
* @method \Syntax\SteamApi\Steam\Group group()
* @method \Syntax\SteamApi\Steam\Item item($appId)
*/
Expand Down
32 changes: 32 additions & 0 deletions src/Syntax/SteamApi/Containers/Package.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Syntax\SteamApi\Containers;

class Package extends BaseContainer
{
public $id;
public $name;
public $page_image;
public $header;
public $small_logo;
public $apps;
public $page_content;
public $price;
public $platforms;
public $release;

public function __construct($package, $id)
{
$this->id = (int) $id;
$this->name = $package->name;
$this->apps = $package->apps;
$this->page_content = $this->checkIssetField($package, 'page_content', 'none');
$this->header = $this->checkIssetField($package, 'header_image', 'none');
$this->small_logo = $this->checkIssetField($package, 'small_logo', 'none');
$this->page_image = $this->checkIssetField($package, 'page_image', 'none');
$this->price = $this->formatPriceObject($package, 'price');
$this->platforms = $package->platforms;
$this->controller = $package->controller;
$this->release = $package->release_date;
}
}
4 changes: 3 additions & 1 deletion src/Syntax/SteamApi/Steam/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct()
$this->interface = 'api';
}

public function appDetails($appIds)
public function appDetails($appIds, $country = null, $language = null)
{
// Set up the api details
$this->method = 'appdetails';
Expand All @@ -24,6 +24,8 @@ public function appDetails($appIds)
// Set up the arguments
$arguments = [
'appids' => $appIds,
'cc' => $country,
'l' => $language,
];

// Get the client
Expand Down
60 changes: 60 additions & 0 deletions src/Syntax/SteamApi/Steam/Package.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Syntax\SteamApi\Steam;

use Syntax\SteamApi\Client;
use NukaCode\Database\Collection;
use Syntax\SteamApi\Containers\Package as PackageContainer;

class Package extends Client
{
public function __construct()
{
parent::__construct();
$this->url = 'http://store.steampowered.com/';
$this->interface = 'api';
}

public function packageDetails($packIds, $cc = null, $language = null)
{
// Set up the api details
$this->method = 'packagedetails';
$this->version = null;
// Set up the arguments
$arguments = [
'packageids' => $packIds,
'cc' => $cc,
'l' => $language,
];
// Get the client
$client = $this->setUpClient($arguments);
$packs = $this->convertToObjects($client, $packIds);

return $packs;
}

protected function convertToObjects($package, $packIds)
{
$convertedPacks = $this->convertPacks($package, $packIds);
$package = $this->sortObjects($convertedPacks);

return $package;
}

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

return $convertedPacks;
}
}
1 change: 1 addition & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
* Once you get your key, add it here.
*/
'steamApiKey' => env('STEAM_API_KEY'),

);
19 changes: 19 additions & 0 deletions tests/BaseTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class BaseTester extends TestCase {

protected $appId = 620;

protected $packageId = 76710;

protected $groupId = 103582791429521412;

protected $groupName = 'Valve';
Expand Down Expand Up @@ -87,6 +89,11 @@ protected function checkAppProperties($app)
$this->checkNestedAppProperties($app);
}

protected function checkPackageProperties($package)
{
$this->checkNestedPackageProperties($package);
}

protected function checkGroupProperties($group)
{
$this->checkGroupMainSummaryProperties($group);
Expand Down Expand Up @@ -134,6 +141,18 @@ private function checkNestedAppProperties($app)
$this->assertObjectHasAttributes($attributes, $app->metacritic);
}

/**
* @param $packahe
*/
private function checkNestedPackageProperties($packahe)
{
$attributes = ['currency', 'initial', 'final', 'discount_percent', 'individual'];
$this->assertObjectHasAttributes($attributes, $packahe->price);

$attributes = ['windows', 'mac', 'linux'];
$this->assertObjectHasAttributes($attributes, $packahe->platforms);
}

/**
* @param $group
*/
Expand Down
28 changes: 28 additions & 0 deletions tests/PackageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

require_once 'BaseTester.php';

/** @group Package */
class PackageTest extends BaseTester
{
/** @test */
public function it_gets_details_for_an_package_by_id()
{
$details = $this->steamClient->package()->packageDetails($this->packageId);

$this->assertCount(1, $details);

$detail = $details->first();

$this->checkPackageProperties($detail);
$this->checkPackageClasses($detail);
}

/**
* @param $detail
*/
private function checkPackageClasses($detail)
{
$this->assertInstanceOf('Syntax\SteamApi\Containers\Package', $detail);
}
}

0 comments on commit 881be37

Please sign in to comment.