Completed
Pull Request — master (#112)
by
unknown
02:09
created

Player::GetBadges()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 4
cp 0
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Syntax\SteamApi\Steam;
4
5
use Syntax\SteamApi\Client;
6
use Illuminate\Support\Collection;
7
use Syntax\SteamApi\Containers\Game;
8
use Syntax\SteamApi\Containers\Player\Level;
9
10
class Player extends Client
11
{
12
    public function __construct($steamId)
13
    {
14
        parent::__construct();
15
        $this->interface = 'IPlayerService';
16
        $this->isService = true;
17
        $this->steamId   = $steamId;
18
    }
19
20
    public function GetSteamLevel()
21
    {
22
        // Set up the api details
23
        $this->setApiDetails(__FUNCTION__, 'v0001');
24
25
        // Set up the arguments
26
        $arguments = ['steamId' => $this->steamId];
27
28
        // Get the client
29
        $client = $this->getServiceResponse($arguments);
30
31
        return $client->player_level;
32
    }
33
34
    public function GetPlayerLevelDetails()
35
    {
36
        $details = $this->GetBadges();
37
        
38
        if(count((array)$details) == 0){
39
            return NULL;
40
        }
41
42
        $details = new Level($details);
43
44
        return $details;
45
    }
46
47
    public function GetBadges()
48
    {
49
        // Set up the api details
50
        $this->setApiDetails(__FUNCTION__, 'v0001');
51
52
        // Set up the arguments
53
        $arguments = ['steamId' => $this->steamId];
54
55
        // Get the client
56
        return $this->getServiceResponse($arguments);
57
    }
58
59
    public function GetCommunityBadgeProgress($badgeId = null)
60
    {
61
        // Set up the api details
62
        $this->setApiDetails(__FUNCTION__, 'v0001');
63
64
        // Set up the arguments
65
        $arguments = ['steamId' => $this->steamId];
66
        if ($badgeId != null) {
67
            $arguments['badgeid'] = $badgeId;
68
        }
69
70
        // Get the client
71
        return $this->getServiceResponse($arguments);
72
    }
73
74
    public function GetOwnedGames($includeAppInfo = true, $includePlayedFreeGames = false, $appIdsFilter = [])
75
    {
76
        // Set up the api details
77
        $this->setApiDetails(__FUNCTION__, 'v0001');
78
79
        // Set up the arguments
80
        $arguments = ['steamId' => $this->steamId];
81
        if ($includeAppInfo) {
82
            $arguments['include_appinfo'] = $includeAppInfo;
83
        }
84
        if ($includePlayedFreeGames) {
85
            $arguments['include_played_free_games'] = $includePlayedFreeGames;
86
        }
87
88
        $appIdsFilter = (array) $appIdsFilter;
89
90
        if (count($appIdsFilter) > 0) {
91
            $arguments['appids_filter'] = $appIdsFilter;
92
        }
93
94
        // Get the client
95
        $client = $this->getServiceResponse($arguments);
96
97
        // Clean up the games
98
        return $this->convertToObjects(isset($client->games) ? $client->games : []);
99
    }
100
101
    public function GetRecentlyPlayedGames($count = null)
102
    {
103
        // Set up the api details
104
        $this->setApiDetails(__FUNCTION__, 'v0001');
105
106
        // Set up the arguments
107
        $arguments = ['steamId' => $this->steamId];
108
        if (! is_null($count)) {
109
            $arguments['count'] = $count;
110
        }
111
112
        // Get the client
113
        $client = $this->getServiceResponse($arguments);
114
115
        if (isset($client->total_count) && $client->total_count > 0) {
116
            // Clean up the games
117
            return $this->convertToObjects($client->games);
118
        }
119
120
        return null;
121
    }
122
123
    public function IsPlayingSharedGame($appIdPlaying)
124
    {
125
        // Set up the api details
126
        $this->setApiDetails(__FUNCTION__, 'v0001');
127
128
        // Set up the arguments
129
        $arguments = [
130
            'steamId'       => $this->steamId,
131
            'appid_playing' => $appIdPlaying,
132
        ];
133
134
        // Get the client
135
        $client = $this->getServiceResponse($arguments);
136
137
        return $client->lender_steamid;
138
    }
139
140
    protected function convertToObjects($games)
141
    {
142
        $convertedGames = $this->convertGames($games);
143
144
        $games = $this->sortObjects($convertedGames);
145
146
        return $games;
147
    }
148
149
    private function convertGames($games)
150
    {
151
        $convertedGames = new Collection;
152
153
        foreach ($games as $game) {
154
            $convertedGames->add(new Game($game));
155
        }
156
157
        return $convertedGames;
158
    }
159
}
160