diff --git a/commonstructs.go b/commonstructs.go index 3f6b3e4..288860b 100644 --- a/commonstructs.go +++ b/commonstructs.go @@ -126,3 +126,15 @@ type Sublable struct { Id int `json:"id"` Name string `json:"name"` } + +type ReleaseSource struct { + Artist string `json:"artist"` + Catno string `json:"catno"` + Format string `json:"format"` + Id int `json:"id"` + Resource_url string `json:"resource_url"` + Status string `json:"status"` + Thumb string `json:"thumb"` + Title string `json:"title"` + Year int `json:"year"` +} diff --git a/examples/discogs_example.go b/examples/discogs_example.go index fcc5f16..dcb7529 100644 --- a/examples/discogs_example.go +++ b/examples/discogs_example.go @@ -15,13 +15,13 @@ func main() { release, _, err := d.Release.Release(params) */ params := &discogs.LabelParams{Label_id: "1000"} - label, _, err := d.Label.Label(params) + label, _, err := d.Label.Releases(params) if err != nil { fmt.Println(err) } else { //fmt.Println(release.Title) - fmt.Println(label.Name) + fmt.Println(label.Releases[0].Title) } //fmt.Println(resp) } diff --git a/labels.go b/labels.go index 898eef6..569184b 100644 --- a/labels.go +++ b/labels.go @@ -11,6 +11,8 @@ type LabelService struct { type LabelParams struct { Label_id string + Page int + Per_page int } type Label struct { @@ -27,6 +29,11 @@ type Label struct { Data_quality string `json:"data_quality"` } +type LabelReleases struct { + Pagination Page `json:"pagination"` + Releases []ReleaseSource `json:"releases"` +} + func newLabelService(api *apirequest.API) *LabelService { return &LabelService{ api: api.Path("labels/"), @@ -40,3 +47,11 @@ func (self *LabelService) Label(params *LabelParams) (*Label, *http.Response, er resp, err := self.api.New().Get(params.Label_id).Receive(label, apiError) return label, resp, relevantError(err, *apiError) } + +func (self *LabelService) Releases(params *LabelParams) (*LabelReleases, *http.Response, error) { + releases := new(LabelReleases) + apiError := new(APIError) + + resp, err := self.api.New().Get(params.Label_id+"/releases").QueryStruct(params).Receive(releases, apiError) + return releases, resp, relevantError(err, *apiError) +} diff --git a/labels_test.go b/labels_test.go index 02278ab..ff52695 100644 --- a/labels_test.go +++ b/labels_test.go @@ -16,3 +16,14 @@ func TestLabelService_Label(t *testing.T) { check(t, err) assert(t, label.Id == expectedId, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedId, label.Id)) } + +func TestLabelService_Releases(t *testing.T) { + expectedId := "Good Time" + + client := &http.Client{} + d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs") + label, _, err := d.Label.Releases(&LabelParams{Label_id: "1000"}) + + check(t, err) + assert(t, label.Releases[0].Title == expectedId, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedId, label.Releases[0].Title)) +}