1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SchoppAx\Sleeper\Api; |
4
|
|
|
|
5
|
|
|
use SchoppAx\Sleeper\Api\Utility\Validation; |
6
|
|
|
|
7
|
|
|
class Drafts extends Api |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @param string $userId |
12
|
|
|
* @param string $season |
13
|
|
|
* @param string[optional] $sport default is nfl |
14
|
|
|
* @return array |
15
|
|
|
* @throws InvalidArgumentException if params doesn't match |
16
|
1 |
|
* @throws ClientException if status code <> 200 |
17
|
|
|
* @throws Exception if response body equals null |
18
|
1 |
|
*/ |
19
|
|
|
public function byUser(string $userId, string $season, string $sport = 'nfl'): array |
20
|
|
|
{ |
21
|
|
|
if(!Validation::between($season, 2015, date("Y")) || !Validation::contains(['nfl'], $sport)) { |
|
|
|
|
22
|
|
|
throw new \InvalidArgumentException("byUser function only accepts seasons since 2015 and sport type 'nfl'. Inputs were: {$season}, {$sport}"); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
return $this->get('user/' . $userId . '/drafts/'. $sport .'/' . $season); |
26
|
|
|
} |
27
|
1 |
|
|
28
|
|
|
/** |
29
|
1 |
|
* @param string $leagueId |
30
|
|
|
* @return array |
31
|
|
|
* @throws ClientException if status code <> 200 |
32
|
|
|
* @throws Exception if response body equals null |
33
|
|
|
*/ |
34
|
|
|
public function byLeague(string $leagueId): array |
35
|
|
|
{ |
36
|
|
|
return $this->get('league/'. $leagueId .'/drafts'); |
37
|
|
|
} |
38
|
1 |
|
|
39
|
|
|
/** |
40
|
1 |
|
* @param string $draftId |
41
|
|
|
* @return array |
42
|
|
|
* @throws ClientException if status code <> 200 |
43
|
|
|
* @throws Exception if response body equals null |
44
|
|
|
*/ |
45
|
|
|
public function find(string $draftId): array |
46
|
|
|
{ |
47
|
|
|
return $this->get('/draft/' . $draftId); |
48
|
|
|
} |
49
|
1 |
|
|
50
|
|
|
/** |
51
|
1 |
|
* @param string $draftId |
52
|
|
|
* @return array |
53
|
|
|
* @throws ClientException if status code <> 200 |
54
|
|
|
* @throws Exception if response body equals null |
55
|
|
|
*/ |
56
|
|
|
public function picks(string $draftId): array |
57
|
|
|
{ |
58
|
|
|
return $this->get('/draft/' . $draftId .'/picks'); |
59
|
|
|
} |
60
|
1 |
|
|
61
|
|
|
/** |
62
|
1 |
|
* @param string $draftId |
63
|
|
|
* @return array |
64
|
|
|
* @throws ClientException if status code <> 200 |
65
|
|
|
* @throws Exception if response body equals null |
66
|
|
|
*/ |
67
|
|
|
public function tradedPicks(string $draftId): array |
68
|
|
|
{ |
69
|
|
|
return $this->get('/draft/' . $draftId .'/traded_picks'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|