1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Syntax\SteamApi\Steam; |
4
|
|
|
|
5
|
|
|
use Syntax\SteamApi\Client; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use Syntax\SteamApi\Containers\App as AppContainer; |
8
|
|
|
|
9
|
|
|
class App extends Client |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var bool |
13
|
|
|
*/ |
14
|
|
|
|
15
|
2 |
|
public function __construct() |
16
|
|
|
{ |
17
|
2 |
|
parent::__construct(); |
18
|
2 |
|
$this->url = 'http://store.steampowered.com/'; |
19
|
2 |
|
$this->interface = 'api'; |
20
|
2 |
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param $appIds |
24
|
|
|
* @param null $country |
25
|
|
|
* @param null $language |
26
|
|
|
* @return Collection |
27
|
|
|
*/ |
28
|
1 |
View Code Duplication |
public function appDetails($appIds, $country = null, $language = null) |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
// Set up the api details |
31
|
1 |
|
$this->method = 'appdetails'; |
32
|
1 |
|
$this->version = null; |
33
|
|
|
|
34
|
|
|
// Set up the arguments |
35
|
|
|
$arguments = [ |
36
|
1 |
|
'appids' => $appIds, |
37
|
1 |
|
'cc' => $country, |
38
|
1 |
|
'l' => $language, |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
// Get the client |
42
|
1 |
|
$client = $this->setUpClient($arguments); |
43
|
|
|
|
44
|
1 |
|
return $this->convertToObjects($client); |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
public function GetAppList() |
48
|
|
|
{ |
49
|
|
|
// Set up the api details |
50
|
1 |
|
$this->url = 'http://api.steampowered.com/'; |
51
|
1 |
|
$this->interface = 'ISteamApps'; |
52
|
1 |
|
$this->method = __FUNCTION__; |
53
|
1 |
|
$this->version = 'v0001'; |
54
|
|
|
|
55
|
|
|
// Get the client |
56
|
1 |
|
$client = $this->setUpClient(); |
57
|
|
|
|
58
|
1 |
|
return $client->applist->apps->app; |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
protected function convertToObjects($apps) |
62
|
|
|
{ |
63
|
1 |
|
$convertedApps = $this->convertGames($apps); |
64
|
|
|
|
65
|
1 |
|
$apps = $this->sortObjects($convertedApps); |
66
|
|
|
|
67
|
1 |
|
return $apps; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param $apps |
72
|
|
|
* |
73
|
|
|
* @return Collection |
74
|
|
|
*/ |
75
|
1 |
|
protected function convertGames($apps) |
76
|
|
|
{ |
77
|
1 |
|
$convertedApps = new Collection(); |
78
|
|
|
|
79
|
1 |
|
foreach ($apps as $app) { |
80
|
1 |
|
if (isset($app->data)) { |
81
|
1 |
|
$convertedApps->add(new AppContainer($app->data)); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
1 |
|
return $convertedApps; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.