Minor fixings

This commit is contained in:
irlndts 2017-04-17 00:09:01 +03:00
parent bce16b5ed1
commit 26dbacfe44
2 changed files with 20 additions and 32 deletions

View File

@ -23,9 +23,7 @@ type Client struct {
// NewClient returns a new Client. // NewClient returns a new Client.
func NewClient(useragent, token string) *Client { func NewClient(useragent, token string) *Client {
base := apirequest.New().Client(&http.Client{}).Base(discogsAPI).Add("User-Agent", useragent).Add("Authorization", "Discogs token="+token) base := apirequest.New().Client(&http.Client{}).Base(discogsAPI).Add("User-Agent", useragent).Add("Authorization", "Discogs token="+token)
return &Client{ return &Client{
api: base,
Artist: newArtistService(base.New()), Artist: newArtistService(base.New()),
Label: newLabelService(base.New()), Label: newLabelService(base.New()),
Master: newMasterService(base.New()), Master: newMasterService(base.New()),
@ -33,16 +31,3 @@ func NewClient(useragent, token string) *Client {
Search: newSearchService(base.New()), Search: newSearchService(base.New()),
} }
} }
// UserAgent sets specified user agent
// Discogs required it
func (c *Client) UserAgent(useragent string) *Client {
c.api.Set("User-Agent", useragent)
return c
}
// 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
}

View File

@ -11,7 +11,7 @@ type SearchService struct {
api *apirequest.API api *apirequest.API
} }
// SerachRequest implements search request model // SerachRequest describes search request json
type SearchRequest struct { type SearchRequest struct {
Q string // search query (optional) Q string // search query (optional)
Type string // one of release, master, artist, label (optional) Type string // one of release, master, artist, label (optional)
@ -39,25 +39,25 @@ type SearchRequest struct {
// Search describes search response // Search describes search response
type Search struct { type Search struct {
Pagination Page `json:"pagination"` Pagination Page `json:"pagination"`
Results []Result `json:"results"` Results []Result `json:"results,omitempty"`
} }
// Result describes a part of search result // Result describes a part of search result
type Result struct { type Result struct {
Style []string `json:"style"` Style []string `json:"style,omitempty"`
Thumb string `json:"thumb"` Thumb string `json:"thumb,omitempty"`
Title string `json:"title"` Title string `json:"title,omitempty"`
Country string `json:"country"` Country string `json:"country,omitempty"`
Format []string `json:"format"` Format []string `json:"format,omitempty"`
Uri string `json:"uri"` Uri string `json:"uri,omitempty"`
Community Community `json:"community"` Community Community `json:"community,omitempty"`
Label []string `json:"label"` Label []string `json:"label,omitempty"`
Catno string `json:"catno"` Catno string `json:"catno,omitempty"`
Year string `json:"year"` Year string `json:"year,omitempty"`
Genre []string `json:"genre"` Genre []string `json:"genre,omitempty"`
Resource_url string `json:"resource_url"` Resource_url string `json:"resource_url,omitempty"`
Type string `json:"type"` Type string `json:"type,omitempty"`
Id int `json:"id"` Id int `json:"id,omitempty"`
} }
func newSearchService(api *apirequest.API) *SearchService { func newSearchService(api *apirequest.API) *SearchService {
@ -66,7 +66,10 @@ func newSearchService(api *apirequest.API) *SearchService {
} }
} }
// Search makes search request to discogs // Search makes search request to discogs.
// Issue a search query to our database. This endpoint accepts pagination parameters.
// Authentication (as any user) is required.
// https://www.discogs.com/developers/#page:database,header:database-search
func (self *SearchService) Search(params *SearchRequest) (*Search, *http.Response, error) { func (self *SearchService) Search(params *SearchRequest) (*Search, *http.Response, error) {
search := new(Search) search := new(Search)
apiError := new(APIError) apiError := new(APIError)