Improvement token

This commit is contained in:
irlndts 2018-02-20 18:16:34 +03:00
parent d0f617733a
commit 916e1f0bd6
1 changed files with 6 additions and 12 deletions

View File

@ -14,14 +14,11 @@ const (
type Options struct {
Currency string
UserAgent string
Token string
}
// Client is a Discogs client for making Discogs API requests.
type Client struct {
api *apirequest.API
currency string
// services
Release *ReleaseService
Master *MasterService
Artist *ArtistService
@ -41,9 +38,12 @@ func NewClient(o *Options) (*Client, error) {
return nil, err
}
return &Client{
api: base,
// set token, it's required for some queries like search
if o.Token != "" {
base.Set("Authorization", "Discogs token="+o.Token)
}
return &Client{
Release: newReleaseService(base.New(), cur),
Artist: newArtistService(base.New()),
Label: newLabelService(base.New()),
@ -52,12 +52,6 @@ func NewClient(o *Options) (*Client, error) {
}, nil
}
// 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
}
// currency validates currency for marketplace data.
// Defaults to the authenticated users currency. Must be one of the following:
// USD GBP EUR CAD AUD JPY CHF MXN BRL NZD SEK ZAR