Skip to content
Draft
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions podcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
72 changes: 72 additions & 0 deletions podcast_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
6 changes: 1 addition & 5 deletions show.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand Down Expand Up @@ -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
}

Expand Down