DSCGS-9 Rewrite MasterService
This commit is contained in:
parent
93ddab1b21
commit
615c7561ad
12
artists.go
12
artists.go
@ -27,12 +27,6 @@ type Artist struct {
|
|||||||
Members []Member `json:"members"`
|
Members []Member `json:"members"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArtistReleases ...
|
|
||||||
type ArtistReleases struct {
|
|
||||||
Pagination Page `json:"pagination"`
|
|
||||||
Releases []ReleaseSource `json:"releases"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Artist represents a person in the discogs database
|
// Artist represents a person in the discogs database
|
||||||
func (s *ArtistService) Artist(artistID int) (*Artist, error) {
|
func (s *ArtistService) Artist(artistID int) (*Artist, error) {
|
||||||
var artist *Artist
|
var artist *Artist
|
||||||
@ -42,6 +36,12 @@ func (s *ArtistService) Artist(artistID int) (*Artist, error) {
|
|||||||
return artist, nil
|
return artist, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArtistReleases ...
|
||||||
|
type ArtistReleases struct {
|
||||||
|
Pagination Page `json:"pagination"`
|
||||||
|
Releases []ReleaseSource `json:"releases"`
|
||||||
|
}
|
||||||
|
|
||||||
// Releases returns a list of releases and masters associated with the artist.
|
// Releases returns a list of releases and masters associated with the artist.
|
||||||
func (s *ArtistService) Releases(artistID int, pagination *Pagination) (*ArtistReleases, error) {
|
func (s *ArtistService) Releases(artistID int, pagination *Pagination) (*ArtistReleases, error) {
|
||||||
var releases *ArtistReleases
|
var releases *ArtistReleases
|
||||||
|
@ -63,7 +63,7 @@ func NewClient(o *Options) (*Client, error) {
|
|||||||
Release: newReleaseService(o.URL+"/releases/", cur),
|
Release: newReleaseService(o.URL+"/releases/", cur),
|
||||||
Artist: newArtistService(o.URL + "/artists/"),
|
Artist: newArtistService(o.URL + "/artists/"),
|
||||||
Label: newLabelService(base.New()),
|
Label: newLabelService(base.New()),
|
||||||
Master: newMasterService(base.New()),
|
Master: newMasterService(o.URL + "/masters/"),
|
||||||
Search: newSearchService(base.New()),
|
Search: newSearchService(base.New()),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -100,7 +100,6 @@ func request(path string, params url.Values, resp interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(string(body))
|
|
||||||
|
|
||||||
return json.Unmarshal(body, &resp)
|
return json.Unmarshal(body, &resp)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
release, err := d.Artist.Releases(168101, nil)
|
release, err := d.Master.Versions(1147170, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
52
masters.go
52
masters.go
@ -1,24 +1,21 @@
|
|||||||
package discogs
|
package discogs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/irlndts/go-apirequest"
|
"strconv"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MasterService struct {
|
type MasterService struct {
|
||||||
api *apirequest.API
|
url string
|
||||||
}
|
}
|
||||||
|
|
||||||
type MasterParams struct {
|
func newMasterService(url string) *MasterService {
|
||||||
Master_id string
|
return &MasterService{
|
||||||
}
|
url: url,
|
||||||
|
}
|
||||||
type MasterVersionParams struct {
|
|
||||||
Master_id string
|
|
||||||
Page int
|
|
||||||
Per_page int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Master resource represents a set of similar releases.
|
||||||
|
// Masters (also known as `master releases`) have a `main release` which is often the chronologically earliest.
|
||||||
type Master struct {
|
type Master struct {
|
||||||
Styles []string `json:"styles"`
|
Styles []string `json:"styles"`
|
||||||
Genres []string `json:"genres"`
|
Genres []string `json:"genres"`
|
||||||
@ -37,27 +34,26 @@ type Master struct {
|
|||||||
Data_quality string `json:"data_quality"`
|
Data_quality string `json:"data_quality"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Master returns a master release
|
||||||
|
func (s *MasterService) Master(masterID int) (*Master, error) {
|
||||||
|
var master *Master
|
||||||
|
if err := request(s.url+strconv.Itoa(masterID), nil, &master); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return master, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MasterVersions retrieves a list of all releases that are versions of this master.
|
||||||
type MasterVersions struct {
|
type MasterVersions struct {
|
||||||
Pagination Page `json:"pagination"`
|
Pagination Page `json:"pagination"`
|
||||||
Versions []Version `json:"versions"`
|
Versions []Version `json:"versions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMasterService(api *apirequest.API) *MasterService {
|
// Versions retrieves a list of all Releases that are versions of this master
|
||||||
return &MasterService{
|
func (s *MasterService) Versions(masterID int, pagination *Pagination) (*MasterVersions, error) {
|
||||||
api: api.Path("masters/"),
|
var versions *MasterVersions
|
||||||
|
if err := request(s.url+strconv.Itoa(masterID)+"/versions", pagination.toParams(), &versions); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
return versions, nil
|
||||||
|
|
||||||
func (self *MasterService) Master(params *MasterParams) (*Master, *http.Response, error) {
|
|
||||||
master := new(Master)
|
|
||||||
apiError := new(APIError)
|
|
||||||
resp, err := self.api.New().Get(params.Master_id).Receive(master, apiError)
|
|
||||||
return master, resp, relevantError(err, *apiError)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *MasterService) Versions(params *MasterVersionParams) (*MasterVersions, *http.Response, error) {
|
|
||||||
versions := new(MasterVersions)
|
|
||||||
apiError := new(APIError)
|
|
||||||
resp, err := self.api.New().Get(params.Master_id+"/versions").QueryStruct(params).Receive(versions, apiError)
|
|
||||||
return versions, resp, relevantError(err, *apiError)
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user