2016-03-04 16:08:02 +00:00
|
|
|
package discogs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2017-02-13 16:40:27 +00:00
|
|
|
|
|
|
|
"github.com/irlndts/go-apirequest"
|
2016-03-04 16:08:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2017-02-14 19:01:50 +00:00
|
|
|
discogsAPI = "https://api.discogs.com/"
|
2016-03-04 16:08:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Client is a Discogs client for making Discogs API requests.
|
|
|
|
type Client struct {
|
2016-03-04 16:48:26 +00:00
|
|
|
api *apirequest.API
|
|
|
|
Release *ReleaseService
|
2016-03-10 14:25:55 +00:00
|
|
|
Master *MasterService
|
2016-03-10 14:48:15 +00:00
|
|
|
Artist *ArtistService
|
2016-03-10 15:10:08 +00:00
|
|
|
Label *LabelService
|
2017-02-13 16:40:27 +00:00
|
|
|
Search *SearchService
|
2016-03-04 16:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewClient returns a new Client.
|
2017-02-14 19:01:50 +00:00
|
|
|
func NewClient(useragent, token string) *Client {
|
|
|
|
base := apirequest.New().Client(&http.Client{}).Base(discogsAPI).Add("User-Agent", useragent).Add("Authorization", "Discogs token="+token)
|
2016-03-04 16:08:02 +00:00
|
|
|
|
|
|
|
return &Client{
|
2016-03-04 16:48:26 +00:00
|
|
|
api: base,
|
2016-03-10 14:48:15 +00:00
|
|
|
Artist: newArtistService(base.New()),
|
2016-03-10 15:10:08 +00:00
|
|
|
Label: newLabelService(base.New()),
|
2017-02-13 16:40:27 +00:00
|
|
|
Master: newMasterService(base.New()),
|
|
|
|
Release: newReleaseService(base.New()),
|
2017-02-14 19:01:50 +00:00
|
|
|
Search: newSearchService(base.New()),
|
2016-03-04 16:08:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 14:54:25 +00:00
|
|
|
|
2017-02-13 16:40:27 +00:00
|
|
|
// UserAgent sets specified user agent
|
|
|
|
// Discogs required it
|
2016-03-09 14:54:25 +00:00
|
|
|
func (c *Client) UserAgent(useragent string) *Client {
|
|
|
|
c.api.Set("User-Agent", useragent)
|
|
|
|
return c
|
|
|
|
}
|
2017-02-13 16:40:27 +00:00
|
|
|
|
|
|
|
// Token sets tokens, it's required for some queries like search
|
|
|
|
func (c *Client) Token(token string) *Client {
|
|
|
|
c.api.Set("Authorization", "Discogs token="+token)
|
|
|
|
return c
|
|
|
|
}
|