From 916e1f0bd6a36aa52f24b611364a7ea9efc964d2 Mon Sep 17 00:00:00 2001 From: irlndts Date: Tue, 20 Feb 2018 18:16:34 +0300 Subject: [PATCH] Improvement token --- discogs.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/discogs.go b/discogs.go index 1559e57..0564b14 100644 --- a/discogs.go +++ b/discogs.go @@ -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