From de1e81b89d4b6c1198baf292c229e2e291948be1 Mon Sep 17 00:00:00 2001 From: irlndts Date: Fri, 11 Mar 2016 17:07:35 +0300 Subject: [PATCH] Artist Releases block --- artists.go | 19 ++++++++++++++++++- artists_test.go | 11 +++++++++++ commonstructs.go | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/artists.go b/artists.go index 0a151cb..be0ebd8 100644 --- a/artists.go +++ b/artists.go @@ -10,7 +10,11 @@ type ArtistService struct { } type ArtistParams struct { - Artist_id string + Artist_id string + Sort string // year, title, format + Sort_order string // asc, desc + Page int + Per_page int } type Artist struct { @@ -26,6 +30,11 @@ type Artist struct { Members []Member `json:"members"` } +type ArtistReleases struct { + Paginastion Page `json:"pagination"` + Releases []ReleaseSource `json:"releases"` +} + func newArtistService(api *apirequest.API) *ArtistService { return &ArtistService{ api: api.Path("artists/"), @@ -39,3 +48,11 @@ func (self *ArtistService) Artist(params *ArtistParams) (*Artist, *http.Response resp, err := self.api.New().Get(params.Artist_id).Receive(artist, apiError) return artist, resp, relevantError(err, *apiError) } + +func (self *ArtistService) Releases(params *ArtistParams) (*ArtistReleases, *http.Response, error) { + releases := new(ArtistReleases) + apiError := new(APIError) + + resp, err := self.api.New().Get(params.Artist_id+"/releases").QueryStruct(params).Receive(releases, apiError) + return releases, resp, relevantError(err, *apiError) +} diff --git a/artists_test.go b/artists_test.go index e120040..7d31d66 100644 --- a/artists_test.go +++ b/artists_test.go @@ -16,3 +16,14 @@ func TestArtistService_Artist(t *testing.T) { check(t, err) assert(t, artist.Id == expectedId, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedId, artist.Id)) } + +func TestArtistService_Releases(t *testing.T) { + expectedArtist := "Dave Clarke" + + client := &http.Client{} + d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs") + releases, _, err := d.Artist.Releases(&ArtistParams{Artist_id: "1000", Sort: "year", Sort_order: "desc"}) + + check(t, err) + assert(t, releases.Releases[0].Artist == expectedArtist, fmt.Sprintf("Releses.Artist looked for %s, and received %s ", expectedArtist, releases.Releases[0].Artist)) +} diff --git a/commonstructs.go b/commonstructs.go index 288860b..e9df596 100644 --- a/commonstructs.go +++ b/commonstructs.go @@ -137,4 +137,7 @@ type ReleaseSource struct { Thumb string `json:"thumb"` Title string `json:"title"` Year int `json:"year"` + Main_release int `json:"main_release"` + Role string `json:"role"` + Type string `json:"type"` }