Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added methods for the new Events api #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package myradio

import (
"strconv"
"time"

"github.com/UniversityRadioYork/myradio-go/api"
)

type Event struct {
ID int `json:"id"`
Title string `json:"title"`
HTMLDescription string `json:"description_html"`
StartTime time.Time
StartTimeRaw string `json:"start"`
EndTime time.Time
EndTimeRaw string `json:"end"`
Host User `json:"host"`
}

func (e *Event) populateEventTimes() (err error) {
e.StartTime, err = time.Parse(time.RFC3339, e.StartTimeRaw)
if err != nil {
return
}

e.EndTime, err = time.Parse(time.RFC3339, e.EndTimeRaw)
return
}

func (s *Session) GetEventsNext(n int) ([]Event, error) {
req := api.NewRequest("/event/next")
req.Params["n"] = []string{strconv.Itoa(n)}
var events []Event
err := s.do(req).Into(&events)
if err != nil {
return nil, err
}

for k := range events {
err = events[k].populateEventTimes()
if err != nil {
return nil, err
}
}

return events, nil
}

func (s *Session) GetEventsInRange(start time.Time, end time.Time) ([]Event, error) {
req := api.NewRequest("/event/inrange")
req.Params["start"] = []string{start.String()}
req.Params["end"] = []string{end.String()}
var events []Event
err := s.do(req).Into(&events)
if err != nil {
return nil, err
}

for k := range events {
err = events[k].populateEventTimes()
if err != nil {
return nil, err
}
}

return events, nil
}