Artist block

This commit is contained in:
irlndts 2016-03-10 17:48:15 +03:00
parent e790defb31
commit 2dd5b6734c
6 changed files with 107 additions and 49 deletions

41
artists.go Normal file
View 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
View 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))
}

View File

@ -8,7 +8,7 @@ type Video struct {
Uri string `json:"uri"`
}
type Artist struct {
type ArtistSource struct {
Anv string `json:"anv"`
Id int `json:"id"`
Join string `json:"join"`
@ -28,21 +28,11 @@ type Image struct {
}
type Track struct {
Duration string `json:"duration"`
Position string `json:"position"`
Title string `json:"title"`
Type string `json:"type_"`
Extraartists []Extraartist `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"`
Duration string `json:"duration"`
Position string `json:"position"`
Title string `json:"title"`
Type string `json:"type_"`
Extraartists []ArtistSource `json:"extraartists"`
}
type Label struct {
@ -123,3 +113,10 @@ type Version struct {
Thumb string `json:"thumb"`
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"`
}

View File

@ -15,6 +15,7 @@ type Client struct {
api *apirequest.API
Release *ReleaseService
Master *MasterService
Artist *ArtistService
}
// NewClient returns a new Client.
@ -25,6 +26,7 @@ func NewClient(httpClient *http.Client) *Client {
api: base,
Release: newReleaseService(base.New()),
Master: newMasterService(base.New()),
Artist: newArtistService(base.New()),
}
}

View File

@ -14,14 +14,14 @@ func main() {
params := &discogs.ReleaseParams{Release_id: "8138518"}
release, _, err := d.Release.Release(params)
*/
params := &discogs.MasterVersionParams{Master_id: "1000", Page: 2, Per_page: 1}
master, _, err := d.Master.Versions(params)
params := &discogs.ArtistParams{Artist_id: "1000"}
artist, _, err := d.Artist.Artist(params)
if err != nil {
fmt.Println(err)
} else {
//fmt.Println(release.Title)
fmt.Println(master)
fmt.Println(artist.Id)
}
//fmt.Println(resp)
}

View File

@ -14,36 +14,36 @@ type ReleaseParams struct {
}
type Release struct {
Title string `json:"title"`
Id int `json:"id"`
Artists []Artist `json:"artists"`
Data_quality string `json:"data_quality"`
Thumb string `json:"thumb"`
Community Community `json:"community"`
Companies []Company `json:"companies"`
Country string `json:"country"`
Date_added string `json:"date_added"`
Date_changed string `json:"date_changed"`
Estimated_weight int `json:"estimated_weight"`
Extraartists []Extraartist `json:"extraartists"`
Format_quantity int `json:"format_quantity"`
Formats []Format `json:"formats"`
Genres []string `json:"genres"`
Identifiers []Identifier `json:"identifiers"`
Images []Image `json:"images"`
Labels []Label `json:"labels"`
Master_id int `json:"master_id"`
Master_url string `json:"master_url"`
Notes string `josn:"notes"`
Released string `json:"released"`
Released_formatted string `json:"released_formatted"`
Resource_url string `json:"resource_url"`
Status string `json:"status"`
Styles []string `json:"styles"`
Tracklist []Track `json:"tracklist"`
Uri string `json:"uri"`
Videos []Video `json:"videos"`
Year int `json:"year"`
Title string `json:"title"`
Id int `json:"id"`
Artists []ArtistSource `json:"artists"`
Data_quality string `json:"data_quality"`
Thumb string `json:"thumb"`
Community Community `json:"community"`
Companies []Company `json:"companies"`
Country string `json:"country"`
Date_added string `json:"date_added"`
Date_changed string `json:"date_changed"`
Estimated_weight int `json:"estimated_weight"`
Extraartists []ArtistSource `json:"extraartists"`
Format_quantity int `json:"format_quantity"`
Formats []Format `json:"formats"`
Genres []string `json:"genres"`
Identifiers []Identifier `json:"identifiers"`
Images []Image `json:"images"`
Labels []Label `json:"labels"`
Master_id int `json:"master_id"`
Master_url string `json:"master_url"`
Notes string `josn:"notes"`
Released string `json:"released"`
Released_formatted string `json:"released_formatted"`
Resource_url string `json:"resource_url"`
Status string `json:"status"`
Styles []string `json:"styles"`
Tracklist []Track `json:"tracklist"`
Uri string `json:"uri"`
Videos []Video `json:"videos"`
Year int `json:"year"`
}
func newReleaseService(api *apirequest.API) *ReleaseService {