From 3cd62fafbb38ad5e5ed156b30bb16fadcc4f7df3 Mon Sep 17 00:00:00 2001 From: irlndts Date: Thu, 10 Mar 2016 18:10:08 +0300 Subject: [PATCH] labels block added --- commonstructs.go | 8 ++++++- discogs.go | 2 ++ examples/discogs_example.go | 6 +++--- labels.go | 42 +++++++++++++++++++++++++++++++++++++ labels_test.go | 18 ++++++++++++++++ releases.go | 2 +- 6 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 labels.go create mode 100644 labels_test.go diff --git a/commonstructs.go b/commonstructs.go index 16d59e5..3f6b3e4 100644 --- a/commonstructs.go +++ b/commonstructs.go @@ -35,7 +35,7 @@ type Track struct { Extraartists []ArtistSource `json:"extraartists"` } -type Label struct { +type LabelSource struct { Catno string `json:"catno"` Entity_type string `json:"entity_type"` Id int `json:"id"` @@ -120,3 +120,9 @@ type Member struct { Name string `json:"name"` Resource_url string `json:"resource_url"` } + +type Sublable struct { + Resource_url string `json:"url"` + Id int `json:"id"` + Name string `json:"name"` +} diff --git a/discogs.go b/discogs.go index e3f4275..b2a0aff 100644 --- a/discogs.go +++ b/discogs.go @@ -16,6 +16,7 @@ type Client struct { Release *ReleaseService Master *MasterService Artist *ArtistService + Label *LabelService } // NewClient returns a new Client. @@ -27,6 +28,7 @@ func NewClient(httpClient *http.Client) *Client { Release: newReleaseService(base.New()), Master: newMasterService(base.New()), Artist: newArtistService(base.New()), + Label: newLabelService(base.New()), } } diff --git a/examples/discogs_example.go b/examples/discogs_example.go index 722e12c..fcc5f16 100644 --- a/examples/discogs_example.go +++ b/examples/discogs_example.go @@ -14,14 +14,14 @@ func main() { params := &discogs.ReleaseParams{Release_id: "8138518"} release, _, err := d.Release.Release(params) */ - params := &discogs.ArtistParams{Artist_id: "1000"} - artist, _, err := d.Artist.Artist(params) + params := &discogs.LabelParams{Label_id: "1000"} + label, _, err := d.Label.Label(params) if err != nil { fmt.Println(err) } else { //fmt.Println(release.Title) - fmt.Println(artist.Id) + fmt.Println(label.Name) } //fmt.Println(resp) } diff --git a/labels.go b/labels.go new file mode 100644 index 0000000..898eef6 --- /dev/null +++ b/labels.go @@ -0,0 +1,42 @@ +package discogs + +import ( + "github.com/irlndts/go-apirequest" + "net/http" +) + +type LabelService struct { + api *apirequest.API +} + +type LabelParams struct { + Label_id string +} + +type Label struct { + Profile string `json:"profile"` + Releases_url string `json:"releases_url"` + Name string `json:"name"` + Contact_info string `json:"contact_info"` + Uri string `json:"uri"` + Sublabels []Sublable `json:"sublabels"` + Urls []string `json:"urls"` + Images []Image `json:"images"` + Resource_url string `json:"resource_url"` + Id int `json:"id"` + Data_quality string `json:"data_quality"` +} + +func newLabelService(api *apirequest.API) *LabelService { + return &LabelService{ + api: api.Path("labels/"), + } +} + +func (self *LabelService) Label(params *LabelParams) (*Label, *http.Response, error) { + label := new(Label) + apiError := new(APIError) + + resp, err := self.api.New().Get(params.Label_id).Receive(label, apiError) + return label, resp, relevantError(err, *apiError) +} diff --git a/labels_test.go b/labels_test.go new file mode 100644 index 0000000..02278ab --- /dev/null +++ b/labels_test.go @@ -0,0 +1,18 @@ +package discogs + +import ( + "fmt" + "net/http" + "testing" +) + +func TestLabelService_Label(t *testing.T) { + expectedId := 1000 + + client := &http.Client{} + d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs") + label, _, err := d.Label.Label(&LabelParams{Label_id: "1000"}) + + check(t, err) + assert(t, label.Id == expectedId, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedId, label.Id)) +} diff --git a/releases.go b/releases.go index 00188e1..75985f7 100644 --- a/releases.go +++ b/releases.go @@ -31,7 +31,7 @@ type Release struct { Genres []string `json:"genres"` Identifiers []Identifier `json:"identifiers"` Images []Image `json:"images"` - Labels []Label `json:"labels"` + Labels []LabelSource `json:"labels"` Master_id int `json:"master_id"` Master_url string `json:"master_url"` Notes string `josn:"notes"`