From 26dbacfe4490046073173235f0f086d478dea1c3 Mon Sep 17 00:00:00 2001 From: irlndts Date: Mon, 17 Apr 2017 00:09:01 +0300 Subject: [PATCH] Minor fixings --- discogs.go | 15 --------------- search.go | 37 ++++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/discogs.go b/discogs.go index 7d40533..83e682c 100644 --- a/discogs.go +++ b/discogs.go @@ -23,9 +23,7 @@ type Client struct { // NewClient returns a new Client. func NewClient(useragent, token string) *Client { base := apirequest.New().Client(&http.Client{}).Base(discogsAPI).Add("User-Agent", useragent).Add("Authorization", "Discogs token="+token) - return &Client{ - api: base, Artist: newArtistService(base.New()), Label: newLabelService(base.New()), Master: newMasterService(base.New()), @@ -33,16 +31,3 @@ func NewClient(useragent, token string) *Client { 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 -} diff --git a/search.go b/search.go index 1bd9bc3..574be72 100644 --- a/search.go +++ b/search.go @@ -11,7 +11,7 @@ type SearchService struct { api *apirequest.API } -// SerachRequest implements search request model +// SerachRequest describes search request json type SearchRequest struct { Q string // search query (optional) Type string // one of release, master, artist, label (optional) @@ -39,25 +39,25 @@ type SearchRequest struct { // Search describes search response type Search struct { Pagination Page `json:"pagination"` - Results []Result `json:"results"` + Results []Result `json:"results,omitempty"` } // Result describes a part of search result type Result struct { - Style []string `json:"style"` - Thumb string `json:"thumb"` - Title string `json:"title"` - Country string `json:"country"` - Format []string `json:"format"` - Uri string `json:"uri"` - Community Community `json:"community"` - Label []string `json:"label"` - Catno string `json:"catno"` - Year string `json:"year"` - Genre []string `json:"genre"` - Resource_url string `json:"resource_url"` - Type string `json:"type"` - Id int `json:"id"` + Style []string `json:"style,omitempty"` + Thumb string `json:"thumb,omitempty"` + Title string `json:"title,omitempty"` + Country string `json:"country,omitempty"` + Format []string `json:"format,omitempty"` + Uri string `json:"uri,omitempty"` + Community Community `json:"community,omitempty"` + Label []string `json:"label,omitempty"` + Catno string `json:"catno,omitempty"` + Year string `json:"year,omitempty"` + Genre []string `json:"genre,omitempty"` + Resource_url string `json:"resource_url,omitempty"` + Type string `json:"type,omitempty"` + Id int `json:"id,omitempty"` } 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) { search := new(Search) apiError := new(APIError)