Skip to content

Commit 881be37

Browse files
Merge pull request #74 from jastend/master
Language attribute for client requests
2 parents f62796c + e1227aa commit 881be37

File tree

10 files changed

+217
-3
lines changed

10 files changed

+217
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ before_script:
2323
script:
2424
- phpunit --coverage-clover=coverage.clover
2525
- wget https://scrutinizer-ci.com/ocular.phar
26-
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
26+
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Each service from the Steam API has its own methods you can use.
5656
- [User](#user)
5757
- [User Stats](#user-stats)
5858
- [App](#app)
59+
- [Package](#package)
5960
- [Group](#group)
6061

6162
### Global
@@ -310,13 +311,15 @@ Steam::app()
310311
```
311312

312313
#### appDetails
313-
This gets all the details for a game. This is most of the infomation from the store page of a game.
314+
This gets all the details for a game. This is most of the information from the store page of a game.
314315

315316
##### Arguments
316317

317318
Name | Type | Description | Required | Default
318319
-----|------|-------------|----------|---------
319320
appIds| int[] | The ids of the games you want details for | Yes |
321+
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 |
322+
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 |
320323

321324

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

327330
> Example Output: [GetAppList](./examples/app/GetAppList.txt)
328331
332+
### Package
333+
This method will get details for packages.
334+
335+
```php
336+
Steam::package()
337+
```
338+
339+
#### packageDetails
340+
This gets all the details for a package. This is most of the information from the store page of a package.
341+
342+
##### Arguments
343+
344+
Name | Type | Description | Required | Default
345+
-----|------|-------------|----------|---------
346+
packIds| int[] | The ids of the packages you want details for | Yes |
347+
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 |
348+
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 |
349+
350+
351+
> Example Output: [packageDetails](./examples/package/packageDetails.txt)
352+
329353
### Group
330354
This service is used to get details on a Steam group.
331355

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Array
2+
(
3+
[0] => stdClass Object
4+
(
5+
[id] => 76710
6+
[name] => Just Cause 3 XL
7+
[page_image] => https: //steamcdn-a.akamaihd.net/steam/subs/76710/header.jpg?t=1449600260
8+
[header] => https: //steamcdn-a.akamaihd.net/steam/subs/76710/header_ratio.jpg?t=1449600260
9+
[small_logo] => https: //steamcdn-a.akamaihd.net/steam/subs/76710/capsule_231x87.jpg?t=1449600260
10+
[apps] => Array(
11+
[0] => stdClass Object(
12+
[id] => 225540
13+
[name] => Just Cause™ 3
14+
)
15+
16+
[1] => stdClass Object(
17+
[id] => 401850
18+
[name] => Just Cause™ 3 DLC: Air, Land & Sea Expansion Pass
19+
)
20+
21+
)
22+
23+
[page_content] => none[price] => stdClass Object(
24+
[currency] => USD
25+
[initial] => 4499
26+
[final] => 4499
27+
[discount_percent] => 0
28+
[individual] => 4498
29+
)
30+
31+
[platforms] => stdClass Object(
32+
[windows] => 1
33+
[mac] =>
34+
[linux] =>
35+
)
36+
37+
[release] => stdClass Object(
38+
[coming_soon] =>
39+
[date] =>
40+
)
41+
42+
[controller] => stdClass Object(
43+
[full_gamepad] => 1
44+
)
45+
46+
)
47+
)

src/Syntax/SteamApi/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* @method \Syntax\SteamApi\Steam\User user($steamId)
1818
* @method \Syntax\SteamApi\Steam\User\Stats userStats($steamId)
1919
* @method \Syntax\SteamApi\Steam\App app()
20+
* @method \Syntax\Steamapi\Steam\Package package()
2021
* @method \Syntax\SteamApi\Steam\Group group()
2122
* @method \Syntax\SteamApi\Steam\Item item($appId)
2223
*/
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Syntax\SteamApi\Containers;
4+
5+
class Package extends BaseContainer
6+
{
7+
public $id;
8+
public $name;
9+
public $page_image;
10+
public $header;
11+
public $small_logo;
12+
public $apps;
13+
public $page_content;
14+
public $price;
15+
public $platforms;
16+
public $release;
17+
18+
public function __construct($package, $id)
19+
{
20+
$this->id = (int) $id;
21+
$this->name = $package->name;
22+
$this->apps = $package->apps;
23+
$this->page_content = $this->checkIssetField($package, 'page_content', 'none');
24+
$this->header = $this->checkIssetField($package, 'header_image', 'none');
25+
$this->small_logo = $this->checkIssetField($package, 'small_logo', 'none');
26+
$this->page_image = $this->checkIssetField($package, 'page_image', 'none');
27+
$this->price = $this->formatPriceObject($package, 'price');
28+
$this->platforms = $package->platforms;
29+
$this->controller = $package->controller;
30+
$this->release = $package->release_date;
31+
}
32+
}

src/Syntax/SteamApi/Steam/App.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function __construct()
1515
$this->interface = 'api';
1616
}
1717

18-
public function appDetails($appIds)
18+
public function appDetails($appIds, $country = null, $language = null)
1919
{
2020
// Set up the api details
2121
$this->method = 'appdetails';
@@ -24,6 +24,8 @@ public function appDetails($appIds)
2424
// Set up the arguments
2525
$arguments = [
2626
'appids' => $appIds,
27+
'cc' => $country,
28+
'l' => $language,
2729
];
2830

2931
// Get the client
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Syntax\SteamApi\Steam;
4+
5+
use Syntax\SteamApi\Client;
6+
use NukaCode\Database\Collection;
7+
use Syntax\SteamApi\Containers\Package as PackageContainer;
8+
9+
class Package extends Client
10+
{
11+
public function __construct()
12+
{
13+
parent::__construct();
14+
$this->url = 'http://store.steampowered.com/';
15+
$this->interface = 'api';
16+
}
17+
18+
public function packageDetails($packIds, $cc = null, $language = null)
19+
{
20+
// Set up the api details
21+
$this->method = 'packagedetails';
22+
$this->version = null;
23+
// Set up the arguments
24+
$arguments = [
25+
'packageids' => $packIds,
26+
'cc' => $cc,
27+
'l' => $language,
28+
];
29+
// Get the client
30+
$client = $this->setUpClient($arguments);
31+
$packs = $this->convertToObjects($client, $packIds);
32+
33+
return $packs;
34+
}
35+
36+
protected function convertToObjects($package, $packIds)
37+
{
38+
$convertedPacks = $this->convertPacks($package, $packIds);
39+
$package = $this->sortObjects($convertedPacks);
40+
41+
return $package;
42+
}
43+
44+
/**
45+
* @param $packs
46+
*
47+
* @return Collection
48+
*/
49+
protected function convertPacks($packages, $packIds)
50+
{
51+
$convertedPacks = new Collection();
52+
foreach ($packages as $package) {
53+
if (isset($package->data)) {
54+
$convertedPacks->add(new PackageContainer($package->data, $packIds));
55+
}
56+
}
57+
58+
return $convertedPacks;
59+
}
60+
}

src/config/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
* Once you get your key, add it here.
88
*/
99
'steamApiKey' => env('STEAM_API_KEY'),
10+
1011
);

tests/BaseTester.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class BaseTester extends TestCase {
1515

1616
protected $appId = 620;
1717

18+
protected $packageId = 76710;
19+
1820
protected $groupId = 103582791429521412;
1921

2022
protected $groupName = 'Valve';
@@ -87,6 +89,11 @@ protected function checkAppProperties($app)
8789
$this->checkNestedAppProperties($app);
8890
}
8991

92+
protected function checkPackageProperties($package)
93+
{
94+
$this->checkNestedPackageProperties($package);
95+
}
96+
9097
protected function checkGroupProperties($group)
9198
{
9299
$this->checkGroupMainSummaryProperties($group);
@@ -134,6 +141,18 @@ private function checkNestedAppProperties($app)
134141
$this->assertObjectHasAttributes($attributes, $app->metacritic);
135142
}
136143

144+
/**
145+
* @param $packahe
146+
*/
147+
private function checkNestedPackageProperties($packahe)
148+
{
149+
$attributes = ['currency', 'initial', 'final', 'discount_percent', 'individual'];
150+
$this->assertObjectHasAttributes($attributes, $packahe->price);
151+
152+
$attributes = ['windows', 'mac', 'linux'];
153+
$this->assertObjectHasAttributes($attributes, $packahe->platforms);
154+
}
155+
137156
/**
138157
* @param $group
139158
*/

tests/PackageTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
require_once 'BaseTester.php';
4+
5+
/** @group Package */
6+
class PackageTest extends BaseTester
7+
{
8+
/** @test */
9+
public function it_gets_details_for_an_package_by_id()
10+
{
11+
$details = $this->steamClient->package()->packageDetails($this->packageId);
12+
13+
$this->assertCount(1, $details);
14+
15+
$detail = $details->first();
16+
17+
$this->checkPackageProperties($detail);
18+
$this->checkPackageClasses($detail);
19+
}
20+
21+
/**
22+
* @param $detail
23+
*/
24+
private function checkPackageClasses($detail)
25+
{
26+
$this->assertInstanceOf('Syntax\SteamApi\Containers\Package', $detail);
27+
}
28+
}

0 commit comments

Comments
 (0)