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"`
|
||||||
@ -32,17 +32,7 @@ type Track struct {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ 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"`
|
||||||
@ -25,7 +25,7 @@ type Release struct {
|
|||||||
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"`
|
||||||
|
Reference in New Issue
Block a user