Artist block
This commit is contained in:
parent
e790defb31
commit
2dd5b6734c
41
artists.go
Normal file
41
artists.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package discogs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/irlndts/go-apirequest"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ArtistService struct {
|
||||||
|
api *apirequest.API
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArtistParams struct {
|
||||||
|
Artist_id string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Artist struct {
|
||||||
|
Namevariations []string `json:"namevariations"`
|
||||||
|
Profile string `json:"profile"`
|
||||||
|
Releases_url string `json:"releases_url"`
|
||||||
|
Resource_url string `json:"resource_url"`
|
||||||
|
Uri string `json:"uri"`
|
||||||
|
Urls []string `json:"urls"`
|
||||||
|
Data_quality string `json:"data_quality"`
|
||||||
|
Id int `json:"id"`
|
||||||
|
Images []Image `json:"images"`
|
||||||
|
Members []Member `json:"members"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func newArtistService(api *apirequest.API) *ArtistService {
|
||||||
|
return &ArtistService{
|
||||||
|
api: api.Path("artists/"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *ArtistService) Artist(params *ArtistParams) (*Artist, *http.Response, error) {
|
||||||
|
artist := new(Artist)
|
||||||
|
apiError := new(APIError)
|
||||||
|
|
||||||
|
resp, err := self.api.New().Get(params.Artist_id).Receive(artist, apiError)
|
||||||
|
return artist, resp, relevantError(err, *apiError)
|
||||||
|
}
|
18
artists_test.go
Normal file
18
artists_test.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package discogs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestArtistService_Artist(t *testing.T) {
|
||||||
|
expectedId := 1000
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
|
||||||
|
artist, _, err := d.Artist.Artist(&ArtistParams{Artist_id: "1000"})
|
||||||
|
|
||||||
|
check(t, err)
|
||||||
|
assert(t, artist.Id == expectedId, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedId, artist.Id))
|
||||||
|
}
|
@ -8,7 +8,7 @@ type Video struct {
|
|||||||
Uri string `json:"uri"`
|
Uri string `json:"uri"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Artist struct {
|
type ArtistSource struct {
|
||||||
Anv string `json:"anv"`
|
Anv string `json:"anv"`
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Join string `json:"join"`
|
Join string `json:"join"`
|
||||||
@ -28,21 +28,11 @@ type Image struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Track struct {
|
type Track struct {
|
||||||
Duration string `json:"duration"`
|
Duration string `json:"duration"`
|
||||||
Position string `json:"position"`
|
Position string `json:"position"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Type string `json:"type_"`
|
Type string `json:"type_"`
|
||||||
Extraartists []Extraartist `json:"extraartists"`
|
Extraartists []ArtistSource `json:"extraartists"`
|
||||||
}
|
|
||||||
|
|
||||||
type Extraartist struct {
|
|
||||||
Anv string `json:"anv"`
|
|
||||||
Id int `json:"id"`
|
|
||||||
Join string `json:"join"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Resource_url string `json:"resource_url"`
|
|
||||||
Role string `json:"role"`
|
|
||||||
Tracks string `json:"tracks"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Label struct {
|
type Label struct {
|
||||||
@ -123,3 +113,10 @@ type Version struct {
|
|||||||
Thumb string `json:"thumb"`
|
Thumb string `json:"thumb"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Member struct {
|
||||||
|
Active bool `json:"active"`
|
||||||
|
Id int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Resource_url string `json:"resource_url"`
|
||||||
|
}
|
||||||
|
@ -15,6 +15,7 @@ type Client struct {
|
|||||||
api *apirequest.API
|
api *apirequest.API
|
||||||
Release *ReleaseService
|
Release *ReleaseService
|
||||||
Master *MasterService
|
Master *MasterService
|
||||||
|
Artist *ArtistService
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a new Client.
|
// NewClient returns a new Client.
|
||||||
@ -25,6 +26,7 @@ func NewClient(httpClient *http.Client) *Client {
|
|||||||
api: base,
|
api: base,
|
||||||
Release: newReleaseService(base.New()),
|
Release: newReleaseService(base.New()),
|
||||||
Master: newMasterService(base.New()),
|
Master: newMasterService(base.New()),
|
||||||
|
Artist: newArtistService(base.New()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,14 +14,14 @@ func main() {
|
|||||||
params := &discogs.ReleaseParams{Release_id: "8138518"}
|
params := &discogs.ReleaseParams{Release_id: "8138518"}
|
||||||
release, _, err := d.Release.Release(params)
|
release, _, err := d.Release.Release(params)
|
||||||
*/
|
*/
|
||||||
params := &discogs.MasterVersionParams{Master_id: "1000", Page: 2, Per_page: 1}
|
params := &discogs.ArtistParams{Artist_id: "1000"}
|
||||||
master, _, err := d.Master.Versions(params)
|
artist, _, err := d.Artist.Artist(params)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
//fmt.Println(release.Title)
|
//fmt.Println(release.Title)
|
||||||
fmt.Println(master)
|
fmt.Println(artist.Id)
|
||||||
}
|
}
|
||||||
//fmt.Println(resp)
|
//fmt.Println(resp)
|
||||||
}
|
}
|
||||||
|
60
releases.go
60
releases.go
@ -14,36 +14,36 @@ type ReleaseParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Release struct {
|
type Release struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Artists []Artist `json:"artists"`
|
Artists []ArtistSource `json:"artists"`
|
||||||
Data_quality string `json:"data_quality"`
|
Data_quality string `json:"data_quality"`
|
||||||
Thumb string `json:"thumb"`
|
Thumb string `json:"thumb"`
|
||||||
Community Community `json:"community"`
|
Community Community `json:"community"`
|
||||||
Companies []Company `json:"companies"`
|
Companies []Company `json:"companies"`
|
||||||
Country string `json:"country"`
|
Country string `json:"country"`
|
||||||
Date_added string `json:"date_added"`
|
Date_added string `json:"date_added"`
|
||||||
Date_changed string `json:"date_changed"`
|
Date_changed string `json:"date_changed"`
|
||||||
Estimated_weight int `json:"estimated_weight"`
|
Estimated_weight int `json:"estimated_weight"`
|
||||||
Extraartists []Extraartist `json:"extraartists"`
|
Extraartists []ArtistSource `json:"extraartists"`
|
||||||
Format_quantity int `json:"format_quantity"`
|
Format_quantity int `json:"format_quantity"`
|
||||||
Formats []Format `json:"formats"`
|
Formats []Format `json:"formats"`
|
||||||
Genres []string `json:"genres"`
|
Genres []string `json:"genres"`
|
||||||
Identifiers []Identifier `json:"identifiers"`
|
Identifiers []Identifier `json:"identifiers"`
|
||||||
Images []Image `json:"images"`
|
Images []Image `json:"images"`
|
||||||
Labels []Label `json:"labels"`
|
Labels []Label `json:"labels"`
|
||||||
Master_id int `json:"master_id"`
|
Master_id int `json:"master_id"`
|
||||||
Master_url string `json:"master_url"`
|
Master_url string `json:"master_url"`
|
||||||
Notes string `josn:"notes"`
|
Notes string `josn:"notes"`
|
||||||
Released string `json:"released"`
|
Released string `json:"released"`
|
||||||
Released_formatted string `json:"released_formatted"`
|
Released_formatted string `json:"released_formatted"`
|
||||||
Resource_url string `json:"resource_url"`
|
Resource_url string `json:"resource_url"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Styles []string `json:"styles"`
|
Styles []string `json:"styles"`
|
||||||
Tracklist []Track `json:"tracklist"`
|
Tracklist []Track `json:"tracklist"`
|
||||||
Uri string `json:"uri"`
|
Uri string `json:"uri"`
|
||||||
Videos []Video `json:"videos"`
|
Videos []Video `json:"videos"`
|
||||||
Year int `json:"year"`
|
Year int `json:"year"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newReleaseService(api *apirequest.API) *ReleaseService {
|
func newReleaseService(api *apirequest.API) *ReleaseService {
|
||||||
|
Reference in New Issue
Block a user