This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
go-discogs/discogs.go

52 lines
1.2 KiB
Go
Raw Normal View History

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-13 16:40:27 +00:00
libVeresion = "0.1"
discogsAPI = "https://api.discogs.com/"
useragent = "irlndts/go-discogs/0.1"
token = "oQTQKAprakIQfWOkAxTdYyDpgUqahHtdbHTuYkIy"
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.
2016-03-11 14:47:23 +00:00
func NewClient() *Client {
2017-02-13 16:40:27 +00:00
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()),
Search: newSearchService(base),
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
}