-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.go
192 lines (163 loc) · 6.5 KB
/
player.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package yfquery
import (
"fmt"
"net/url"
)
// PlayerQuery can be used to query the /players or /player Yahoo Fantasy endpoints.
type PlayerQuery struct {
query
}
// PlayerStatus represents a player's ownership status.
type PlayerStatus string
// Enum for a player's ownership status.
const (
PlayerStatusUnknown PlayerStatus = ""
PlayerStatusAvailable = "A"
PlayerStatusFreeAgent = "FA"
PlayerStatusWaiver = "W"
PlayerStatusTaken = "T"
PlayerStatusKeeper = "K"
)
// PlayerSortCriteria represents the sort criteria for players.
type PlayerSortCriteria string
// Enum for player sort criteria.
const (
PlayerSortCriteriaUnknown PlayerSortCriteria = ""
PlayerSortCriteriaName = "NAME"
PlayerSortCriteriaOverallRank = "OR"
PlayerSortCriteriaActualRank = "AR"
PlayerSortCriteriaFantasyPoints = "PTS"
)
// PlayerSortType represent the sort type for players.
type PlayerSortType string
// Enum for player sort type.
const (
PlayerSortTypeUnknown PlayerSortType = ""
PlayerSortTypeSeason = "season"
PlayerSortTypeDate = "date"
PlayerSortTypeWeek = "week"
PlayerSortTypeLastMonth = "lastmonth"
PlayerSortTypeLastWeek = "lastweek"
)
// Players returns a PlayerQuery for the /players endpoint.
func Players() *PlayerQuery {
return &PlayerQuery{query{resource: "player", isCollection: true}}
}
// Player returns a PlayerQuery for the /player endpoint.
func Player() *PlayerQuery {
return &PlayerQuery{query{resource: "player"}}
}
// Keys adds the "player_keys" parameter with the given keys to the query.
func (p *PlayerQuery) Keys(keys []string) *PlayerQuery {
p.keys = append(p.keys, keys...)
return p
}
// Key sets the "player_keys" parameter to the the given key. When querying the
// /game endpoint the key will be appended to the query path (i.e. /player/<key>).
func (p *PlayerQuery) Key(key string) *PlayerQuery {
p.keys = []string{key}
return p
}
// Position adds the "position" parameter with the provided position to the query.
// Valid player positions can be provided as input (e.x. "QB", "PG")
func (p *PlayerQuery) Position(pos string) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("position=%s", pos))
return p
}
// Status adds the "status" parameter with the provided status to the query.
func (p *PlayerQuery) Status(status PlayerStatus) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("status=%s", status))
return p
}
// Search adds the "search" parameter with the provided name to the query.
func (p *PlayerQuery) Search(name string) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("search=%s", url.QueryEscape(name)))
return p
}
// Sort adds the "sort" parameter with the provided sort criteria to the query.
func (p *PlayerQuery) Sort(sort PlayerSortCriteria) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("sort=%s", sort))
return p
}
// SortByStat adds the "sort" parameter with the provided stat id to the query.
func (p *PlayerQuery) SortByStat(statID int) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("sort=%d", statID))
return p
}
// SortType adds the "sort_type" parameter with the provided type to the query.
func (p *PlayerQuery) SortType(sortType PlayerSortType) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("sort_type=%s", sortType))
return p
}
// SortSeason adds the "sort_season" parameter with the provided season to the
// query.
func (p *PlayerQuery) SortSeason(season int) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("sort_season=%d", season))
return p
}
// SortDate adds the "sort_date" parameter with the provided date to the query.
// date should be formatted as YYYY-MM-DD.
func (p *PlayerQuery) SortDate(date string) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("sort_date=%s", date))
return p
}
// SortWeek adds the "sort_week" parameter with the provided week to the query.
// Yahoo only supports this parameter for football. week is expected by Yahoo
// to be a positive integer.
func (p *PlayerQuery) SortWeek(week int) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("sort_week=%d", week))
return p
}
// Start adds the "start" parameter with the provided start to the query. start
// is expected by Yahoo to be a positive integer.
func (p *PlayerQuery) Start(start int) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("start=%d", start))
return p
}
// Count adds the "count" parameter with the provided count to the query. count
// is expected by Yahoo to be a positive integer.
func (p *PlayerQuery) Count(count int) *PlayerQuery {
p.params = append(p.params, fmt.Sprintf("count=%d", count))
return p
}
// Ownership adds the "ownership" subresource to the request. If combined with
// other subresources, they are all combined into the "out" parameter, otherwise
// it is added to the request path (i.e. player/ownership).
func (p *PlayerQuery) Ownership() *PlayerQuery {
p.outs = append(p.outs, "ownership")
return p
}
// Opponent adds the "opponent" subresource to the request. If combined with
// other subresources, they are all combined into the "out" parameter, otherwise
// it is added to the request path (i.e. player/opponent).
func (p *PlayerQuery) Opponent() *PlayerQuery {
p.outs = append(p.outs, "opponent")
return p
}
// PercentOwned adds the "percent_owned" subresource to the request. If combined with
// other subresources, they are all combined into the "out" parameter, otherwise
// it is added to the request path (i.e. player/percent_owned).
func (p *PlayerQuery) PercentOwned() *PlayerQuery {
p.outs = append(p.outs, "percent_owned")
return p
}
// DraftAnalysis adds the "draft_analysis" subresource to the request. If combined with
// other subresources, they are all combined into the "out" parameter, otherwise
// it is added to the request path (i.e. player/draft_analysis).
func (p *PlayerQuery) DraftAnalysis() *PlayerQuery {
p.outs = append(p.outs, "draft_analysis")
return p
}
// StatsWithDefaults adds the "stats" subresource to the request. If combined with
// other subresources, they are all combined into the "out" parameter, otherwise
// it is added to the request path (i.e. player/stats).
func (p *PlayerQuery) StatsWithDefaults() *PlayerQuery {
p.outs = append(p.outs, "stats")
return p
}
// Stats returns a StatsQuery for the /stats subresource.
func (p *PlayerQuery) Stats() *StatsQuery {
st := Stats()
st.base = p.ToString()
return st
}