1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SchoppAx\Sleeper\Api; |
4
|
|
|
|
5
|
|
|
use SchoppAx\Sleeper\Api\Utility\Validation; |
6
|
|
|
|
7
|
|
|
class Leagues extends Api |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @param string $leagueId |
12
|
|
|
* @return array |
13
|
|
|
* @throws ClientException if status code <> 200 |
14
|
4 |
|
* @throws Exception if response body equals null |
15
|
|
|
*/ |
16
|
4 |
|
public function find(string $leagueId): array |
17
|
|
|
{ |
18
|
|
|
return $this->get('league/' . $leagueId); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param string $userId |
23
|
|
|
* @param int $season |
24
|
|
|
* @param string[optional] $sport default is nfl |
25
|
|
|
* @return array |
26
|
|
|
* @throws InvalidArgumentException if params doesn't match |
27
|
1 |
|
* @throws ClientException if status code <> 200 |
28
|
|
|
* @throws Exception if response body equals null |
29
|
1 |
|
*/ |
30
|
|
|
public function byUser(string $userId, int $season, string $sport = 'nfl'): array |
31
|
|
|
{ |
32
|
|
|
if(!Validation::between($season, 2015, date("Y")) || !Validation::contains(['nfl'], $sport)) { |
|
|
|
|
33
|
|
|
throw new \InvalidArgumentException("byUser function only accepts seasons since 2015 and sport type 'nfl'. Inputs were: {$season}, {$sport}"); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $this->get('user/' . $userId . '/leagues/'. $sport .'/' . $season); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
1 |
|
* @param string $leagueId |
41
|
|
|
* @param int $week |
42
|
1 |
|
* @return array |
43
|
|
|
* @throws InvalidArgumentException if params doesn't match |
44
|
|
|
* @throws ClientException if status code <> 200 |
45
|
|
|
* @throws Exception if response body equals null |
46
|
|
|
*/ |
47
|
|
|
public function matchups(string $leagueId, int $week): array |
48
|
|
|
{ |
49
|
|
|
if(!Validation::between($week, 1, 16)) { |
50
|
|
|
throw new \InvalidArgumentException("matchups function only accepts weeks between 1 and 16. Input was: {$week}"); |
51
|
1 |
|
} |
52
|
|
|
|
53
|
1 |
|
return $this->get('league/' . $leagueId . '/matchups/' . $week); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string[optional] $sport default is nfl |
58
|
|
|
* @return array |
59
|
|
|
* @throws InvalidArgumentException if params doesn't match |
60
|
|
|
* @throws ClientException if status code <> 200 |
61
|
|
|
* @throws Exception if response body equals null |
62
|
1 |
|
*/ |
63
|
|
|
public function state(string $sport = 'nfl'): array |
64
|
1 |
|
{ |
65
|
|
|
$supported = ['nfl', 'nba', 'lcs']; |
66
|
|
|
if(!Validation::contains($supported, $sport)) { |
67
|
|
|
$strSupported = join(", ", $supported); |
68
|
|
|
throw new \InvalidArgumentException("state function only accepts sports like {$strSupported}. Input was: {$sport}"); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->get('state/'. $sport); |
72
|
|
|
} |
73
|
1 |
|
|
74
|
|
|
/** |
75
|
1 |
|
* @param string $leagueId |
76
|
|
|
* @return array |
77
|
|
|
* @throws ClientException if status code <> 200 |
78
|
|
|
* @throws Exception if response body equals null |
79
|
|
|
*/ |
80
|
|
|
public function users(string $leagueId): array |
81
|
|
|
{ |
82
|
|
|
return $this->get('league/' . $leagueId . '/users'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $leagueId |
87
|
|
|
* @return array |
88
|
|
|
* @throws ClientException if status code <> 200 |
89
|
|
|
* @throws Exception if response body equals null |
90
|
|
|
*/ |
91
|
|
|
public function rosters(string $leagueId): array |
92
|
|
|
{ |
93
|
|
|
return $this->get('league/' . $leagueId . '/rosters'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $leagueId |
98
|
|
|
* @return array |
99
|
|
|
* @throws ClientException if status code <> 200 |
100
|
|
|
* @throws Exception if response body equals null |
101
|
|
|
*/ |
102
|
|
|
public function winnersBracket(string $leagueId): array |
103
|
|
|
{ |
104
|
|
|
return $this->get('league/' . $leagueId . '/winners_bracket'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string $leagueId |
109
|
|
|
* @return array |
110
|
|
|
* @throws ClientException if status code <> 200 |
111
|
|
|
* @throws Exception if response body equals null |
112
|
|
|
*/ |
113
|
|
|
public function losersBracket(string $leagueId): array |
114
|
|
|
{ |
115
|
|
|
return $this->get('league/' . $leagueId . '/losers_bracket'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string $leagueId |
120
|
|
|
* @param int $round |
121
|
|
|
* @return array |
122
|
|
|
* @throws InvalidArgumentException if params doesn't match |
123
|
|
|
* @throws ClientException if status code <> 200 |
124
|
|
|
* @throws Exception if response body equals null |
125
|
|
|
*/ |
126
|
|
|
public function transactions(string $leagueId, int $round): array |
127
|
|
|
{ |
128
|
|
|
if(!Validation::between($round, 1, 16)) { |
129
|
|
|
throw new \InvalidArgumentException("transactions function only accepts rounds between 1 and 16. Input was: {$round}"); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $this->get('league/' . $leagueId . '/transactions/' . $round); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param string $leagueId |
137
|
|
|
* @return array |
138
|
|
|
* @throws ClientException if status code <> 200 |
139
|
|
|
* @throws Exception if response body equals null |
140
|
|
|
*/ |
141
|
|
|
public function tradedPicks(string $leagueId): array |
142
|
|
|
{ |
143
|
|
|
return $this->get('league/' . $leagueId . '/traded_picks'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
} |
147
|
|
|
|