|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SchoppAx\Sleeper\Api; |
|
4
|
|
|
|
|
5
|
|
|
use SchoppAx\Sleeper\Api\Utility\Validation; |
|
6
|
|
|
|
|
7
|
|
|
class Players extends Api |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Fetch all players (nfl only) |
|
11
|
|
|
* |
|
12
|
|
|
* @return array |
|
13
|
|
|
* @throws ClientException if status code <> 200 |
|
14
|
1 |
|
* @throws Exception if response body equals null |
|
15
|
|
|
*/ |
|
16
|
1 |
|
public function all(): array |
|
17
|
|
|
{ |
|
18
|
|
|
return $this->get('players/nfl'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Get a list of trending players based on adds or drops |
|
23
|
|
|
* |
|
24
|
|
|
* @param string $type |
|
25
|
|
|
* @param string $sport |
|
26
|
|
|
* @param int $hours |
|
27
|
|
|
* @param int $limit |
|
28
|
|
|
* |
|
29
|
|
|
* @return array |
|
30
|
|
|
* @throws InvalidArgumentException if params doesn't match |
|
31
|
|
|
* @throws ClientException if status code <> 200 |
|
32
|
|
|
* @throws Exception if response body equals null |
|
33
|
|
|
*/ |
|
34
|
|
|
public function trending(string $type, string $sport = 'nfl', int $hours = 24, int $limit = 25): array |
|
35
|
|
|
{ |
|
36
|
|
|
$type = strtolower($type); |
|
37
|
|
|
if(!Validation::contains(['add', 'drop'], $type)) { |
|
38
|
|
|
throw new \InvalidArgumentException("trending function only accepts type 'add' or 'drop'. Input was: {$type}"); |
|
39
|
|
|
} elseif(!Validation::contains($this->sports, $sport)) { |
|
40
|
|
|
$strSupported = join(", ", $this->sports); |
|
41
|
|
|
throw new \InvalidArgumentException("trending function only accepts sports like {$strSupported}. Input was: {$sport}"); |
|
42
|
|
|
} elseif(!Validation::between($hours, 1, 24)) { |
|
43
|
|
|
throw new \InvalidArgumentException("trending function only accepts hours between 1 and 24. Input was: {$hours}"); |
|
44
|
|
|
} elseif(!Validation::between($limit, 1, 200)) { |
|
45
|
|
|
throw new \InvalidArgumentException("trending function only accepts limits between 1 and 200. Input was: {$limit}"); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $this->get('players/'. $sport .'/trending/'. $type .'?lookback_hours='. $hours .'&limit='. $limit); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|