labels block added

This commit is contained in:
irlndts 2016-03-10 18:10:08 +03:00
parent 2dd5b6734c
commit 3cd62fafbb
6 changed files with 73 additions and 5 deletions

View File

@ -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"`
}

View File

@ -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()),
}
}

View File

@ -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)
}

42
labels.go Normal file
View File

@ -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)
}

18
labels_test.go Normal file
View File

@ -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))
}

View File

@ -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"`