This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
go-discogs/artists.go

65 lines
1.7 KiB
Go
Raw Normal View History

2016-03-10 14:48:15 +00:00
package discogs
import (
"github.com/irlndts/go-apirequest"
"net/http"
)
2017-05-09 14:07:11 +00:00
// ArtistService ...
2016-03-10 14:48:15 +00:00
type ArtistService struct {
api *apirequest.API
}
2017-05-09 14:07:11 +00:00
// ArtistParams ...
2016-03-10 14:48:15 +00:00
type ArtistParams struct {
2016-03-11 14:07:35 +00:00
Artist_id string
Sort string // year, title, format
Sort_order string // asc, desc
Page int
Per_page int
2016-03-10 14:48:15 +00:00
}
2017-05-09 14:07:11 +00:00
// Artist ...
2016-03-10 14:48:15 +00:00
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"`
}
2017-05-09 14:07:11 +00:00
// Artistreleases ...
2016-03-11 14:07:35 +00:00
type ArtistReleases struct {
Paginastion Page `json:"pagination"`
Releases []ReleaseSource `json:"releases"`
}
2016-03-10 14:48:15 +00:00
func newArtistService(api *apirequest.API) *ArtistService {
return &ArtistService{
api: api.Path("artists/"),
}
}
2017-05-09 14:07:11 +00:00
// Artist ...
2016-03-10 14:48:15 +00:00
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)
}
2016-03-11 14:07:35 +00:00
2017-05-09 14:07:11 +00:00
// Releases ...
2016-03-11 14:07:35 +00:00
func (self *ArtistService) Releases(params *ArtistParams) (*ArtistReleases, *http.Response, error) {
releases := new(ArtistReleases)
apiError := new(APIError)
resp, err := self.api.New().Get(params.Artist_id+"/releases").QueryStruct(params).Receive(releases, apiError)
return releases, resp, relevantError(err, *apiError)
}