diff --git a/podcast.go b/podcast.go index c9d3a88..c21eecf 100644 --- a/podcast.go +++ b/podcast.go @@ -62,3 +62,10 @@ func (s *Session) GetAllShowPodcasts(id int) (result []Podcast, err error) { err = s.getf("/show/%d/allpodcasts", id).Into(&result) return } + +// GetPodcastSearchMeta retrieves all Podcasts whose metadata matches a given search term. +// This consumes one API request. +func (s *Session) GetPodcastSearchMeta(term string) (podcasts []Podcast, err error) { + err = s.getf("/podcast/searchmeta/%s", term).Into(&podcasts) + return +} diff --git a/podcast_test.go b/podcast_test.go new file mode 100644 index 0000000..7e3a158 --- /dev/null +++ b/podcast_test.go @@ -0,0 +1,72 @@ +package myradio_test + +import ( + "reflect" + "testing" + "time" + + myradio "github.com/UniversityRadioYork/myradio-go" +) + +const getPodcastSearchMetaJson = ` +[{ + "podcast_id": 1234, + "title": "test podcast", + "description": "an amazing podcast", + "status": "Published", + "time": 1234512345, + "uri": "https://myradio.example.com/media/podcasts/podcast1234.mp3", + "editlink": { + "display": "icon", + "value": "pencil", + "title": "Edit Podcast", + "url": "https://myradio.example.com/podcast/editPodcast/1234" + }, + "micrositelink": { + "display": "icon", + "value": "link", + "title": "Microsites", + "url": "https://myradio.example.com/microsites/1234" + }, + "photo": "https://myradio.example.com/media/image_meta/MyRadioImageMetadata/podcast1234.jpeg" +}]` + +// TestGetSearchMetaUnmarshal tests the unmarshalling logic of GetSearchMeta. +// It does not test the API endpoint. +func TestGetPodcastSearchMetaUnmarshal(t *testing.T) { + expected := []myradio.Podcast{{ + PodcastID: 1234, + Title: "test podcast", + Description: "an amazing podcast", + Status: "Published", + Time: myradio.Time{time.Unix(1234512345, 0)}, + File: "https://myradio.example.com/media/podcasts/podcast1234.mp3", + EditLink: myradio.Link{ + Display: "icon", + Value: "pencil", + Title: "Edit Podcast", + URL: "https://myradio.example.com/podcast/editPodcast/1234", + }, + MicrositeLink: myradio.Link{ + Display: "icon", + Value: "link", + Title: "Microsites", + URL: "https://myradio.example.com/microsites/1234", + }, + Photo: "https://myradio.example.com/media/image_meta/MyRadioImageMetadata/podcast1234.jpeg", + }} + + session, err := myradio.MockSession([]byte(getPodcastSearchMetaJson)) + if err != nil { + t.Error(err) + } + + podcast, err := session.GetPodcastSearchMeta("test") + if err != nil { + t.Error(err) + } + + if !reflect.DeepEqual(podcast, expected) { + t.Errorf("expected:\n%v\n\ngot:\n%v", expected, podcast) + } +} diff --git a/show.go b/show.go index c3da505..f7d82b9 100644 --- a/show.go +++ b/show.go @@ -1,9 +1,5 @@ package myradio -import ( - "net/url" -) - // Credit represents a show credit associating a user with a show. type Credit struct { Type int `json:"type"` @@ -40,7 +36,7 @@ type Link struct { // GetSearchMeta retrieves all shows whose metadata matches a given search term. // This consumes one API request. func (s *Session) GetSearchMeta(term string) (shows []ShowMeta, err error) { - err = s.getf("/show/searchmeta/%s", url.QueryEscape(term)).Into(&shows) + err = s.getf("/show/searchmeta/%s", term).Into(&shows) return }