1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Syntax\SteamApi\Steam; |
4
|
|
|
|
5
|
|
|
use Syntax\SteamApi\Client; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use Syntax\SteamApi\Containers\Item as ItemContainer; |
8
|
|
|
use Syntax\SteamApi\Exceptions\ApiCallFailedException; |
9
|
|
|
use Syntax\SteamApi\Inventory; |
10
|
|
|
|
11
|
|
|
class Item extends Client |
12
|
|
|
{ |
13
|
1 |
|
public function __construct() |
14
|
|
|
{ |
15
|
1 |
|
parent::__construct(); |
16
|
1 |
|
$this->url = 'http://store.steampowered.com/'; |
17
|
1 |
|
$this->isService = true; |
18
|
1 |
|
$this->interface = 'api'; |
19
|
1 |
|
} |
20
|
|
|
|
21
|
1 |
|
public function GetPlayerItems($appId, $steamId) |
22
|
|
|
{ |
23
|
|
|
// Set up the api details |
24
|
1 |
|
$this->url = 'http://api.steampowered.com/'; |
25
|
1 |
|
$this->interface = 'IEconItems_' . $appId; |
26
|
1 |
|
$this->method = __FUNCTION__; |
27
|
1 |
|
$this->version = 'v0001'; |
28
|
|
|
|
29
|
1 |
|
$arguments = ['steamId' => $steamId]; |
30
|
|
|
|
31
|
|
|
try { |
32
|
|
|
// Get the client |
33
|
1 |
|
$client = $this->setUpClient($arguments); |
34
|
|
|
} catch (ApiCallFailedException $exception) { |
35
|
|
|
// No items exist for this game. |
36
|
|
|
return null; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// Clean up the items |
40
|
1 |
|
$items = $this->convertToObjects($client->result->items); |
41
|
|
|
|
42
|
|
|
// Return a full inventory |
43
|
1 |
|
return (array) new Inventory($client->result->num_backpack_slots, $items); |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
protected function convertToObjects($items) |
47
|
|
|
{ |
48
|
1 |
|
return $this->convertItems($items); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param array $items |
53
|
|
|
* |
54
|
|
|
* @return Collection |
55
|
|
|
*/ |
56
|
1 |
|
protected function convertItems($items) |
57
|
|
|
{ |
58
|
1 |
|
$convertedItems = new Collection(); |
59
|
|
|
|
60
|
1 |
|
foreach ($items as $item) { |
61
|
|
|
$convertedItems->add(new ItemContainer($item)); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
return $convertedItems; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|