Merge pull request #13 from irlndts/DSCGS-9

This commit is contained in:
Artem Piskun 2018-03-12 21:14:16 +03:00 committed by GitHub
commit fcb075f0f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 37 deletions

View File

@ -27,12 +27,6 @@ type Artist struct {
Members []Member `json:"members"`
}
// ArtistReleases ...
type ArtistReleases struct {
Pagination Page `json:"pagination"`
Releases []ReleaseSource `json:"releases"`
}
// Artist represents a person in the discogs database
func (s *ArtistService) Artist(artistID int) (*Artist, error) {
var artist *Artist
@ -42,6 +36,12 @@ func (s *ArtistService) Artist(artistID int) (*Artist, error) {
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.
func (s *ArtistService) Releases(artistID int, pagination *Pagination) (*ArtistReleases, error) {
var releases *ArtistReleases

View File

@ -63,7 +63,7 @@ func NewClient(o *Options) (*Client, error) {
Release: newReleaseService(o.URL+"/releases/", cur),
Artist: newArtistService(o.URL + "/artists/"),
Label: newLabelService(base.New()),
Master: newMasterService(base.New()),
Master: newMasterService(o.URL + "/masters/"),
Search: newSearchService(base.New()),
}, nil
}
@ -100,7 +100,6 @@ func request(path string, params url.Values, resp interface{}) error {
if err != nil {
return err
}
fmt.Println(string(body))
return json.Unmarshal(body, &resp)
}

View File

@ -17,7 +17,7 @@ func main() {
return
}
release, err := d.Artist.Releases(168101, nil)
release, err := d.Master.Versions(1147170, nil)
if err != nil {
fmt.Println(err)
return

View File

@ -1,24 +1,21 @@
package discogs
import (
"github.com/irlndts/go-apirequest"
"net/http"
"strconv"
)
type MasterService struct {
api *apirequest.API
url string
}
type MasterParams struct {
Master_id string
}
type MasterVersionParams struct {
Master_id string
Page int
Per_page int
func newMasterService(url string) *MasterService {
return &MasterService{
url: url,
}
}
// 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 {
Styles []string `json:"styles"`
Genres []string `json:"genres"`
@ -37,27 +34,26 @@ type Master struct {
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 {
Pagination Page `json:"pagination"`
Versions []Version `json:"versions"`
}
func newMasterService(api *apirequest.API) *MasterService {
return &MasterService{
api: api.Path("masters/"),
// Versions retrieves a list of all Releases that are versions of this master
func (s *MasterService) Versions(masterID int, pagination *Pagination) (*MasterVersions, error) {
var versions *MasterVersions
if err := request(s.url+strconv.Itoa(masterID)+"/versions", pagination.toParams(), &versions); err != nil {
return nil, err
}
}
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)
return versions, nil
}