-
Notifications
You must be signed in to change notification settings - Fork 1
/
season.go
85 lines (71 loc) · 2.15 KB
/
season.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
package myradio
import "time"
// Season represents a season in the MyRadio schedule.
// A MyRadio season contains timeslots.
type Season struct {
ShowMeta
SeasonID int `json:"season_id"`
SeasonNum int `json:"season_num"`
SubmittedRaw string `json:"submitted"`
Submitted time.Time
RequestedTime string `json:"requested_time"`
FirstTimeRaw string `json:"first_time"`
FirstTime time.Time
NumEpisodes Link `json:"num_episodes"`
AllocateLink Link `json:"allocatelink"`
RejectLink Link `json:"rejectlink"`
Subtype ShowSeasonSubtype `json:"subtype"`
}
// isScheduled returns whether the Season has been scheduled.
// This consumes no API requests.
func (s *Season) isScheduled() bool {
return s.FirstTimeRaw != "Not Scheduled"
}
// populateSeasonTimes sets the times for the given Season given their raw values.
func (s *Season) populateSeasonTimes() (err error) {
if s.isScheduled() {
s.FirstTime, err = parseShortTime(s.FirstTimeRaw)
if err != nil {
return
}
}
s.Submitted, err = parseShortTime(s.SubmittedRaw)
return
}
// GetSeason retrieves the season with the given ID.
// This consumes one API request.
func (s *Session) GetSeason(id int) (season Season, err error) {
if err = s.getf("/season/%d/", id).Into(&season); err != nil {
return
}
err = season.populateSeasonTimes()
return
}
// GetTimeslotsForSeason retrieves all timeslots for the season with the given ID.
// This consumes one API request.
func (s *Session) GetTimeslotsForSeason(id int) (timeslots []Timeslot, err error) {
if err = s.getf("/season/%d/alltimeslots/", id).Into(×lots); err != nil {
return
}
for k := range timeslots {
err = timeslots[k].populateTimeslotTimes()
if err != nil {
return
}
}
return
}
// GetAllSeasonsInLatestTerm gets all seasons in the most recent term.
// This consumes one API request.
func (s *Session) GetAllSeasonsInLatestTerm() (seasons []Season, err error) {
if err = s.get("/season/allseasonsinlatestterm/").Into(&seasons); err != nil {
return
}
for k := range seasons {
err = seasons[k].populateSeasonTimes()
if err != nil {
return
}
}
return
}