Skip to content

Commit a682158

Browse files
author
Ernest E
committed
feat: add package method
This change added a Package class based on App class Package class have `packageDetails` method `packageDetails` method accepts three argument like `app()->appDetails`
1 parent 0879070 commit a682158

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

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+
}
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+
}

0 commit comments

Comments
 (0)