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/search.go

80 lines
2.8 KiB
Go
Raw Normal View History

2017-02-13 16:40:27 +00:00
package discogs
import (
"net/http"
"github.com/irlndts/go-apirequest"
)
2017-04-16 20:49:50 +00:00
// SearchService ...
2017-02-14 19:01:50 +00:00
type SearchService struct {
api *apirequest.API
}
2017-04-16 21:09:01 +00:00
// SerachRequest describes search request json
2017-02-13 16:40:27 +00:00
type SearchRequest struct {
2017-02-14 19:01:50 +00:00
Q string // search query (optional)
Type string // one of release, master, artist, label (optional)
Title string // search by combined “Artist Name - Release Title” title field (optional)
Release_title string // search release titles (optional)
Credit string // search release credits (optional)
Artist string // search artist names (optional)
Anv string // search artist ANV (optional)
Label string // search label names (optional)
Genre string // search genres (optional)
Style string // search styles (optional)
Country string // search release country (optional)
Year string // search release year (optional)
Format string // search formats (optional)
Catno string // search catalog number (optional)
Barcode string // search barcodes (optional)
Track string // search track titles (optional)
Submitter string // search submitter username (optional)
Contributer string // search contributor usernames (optional)
2017-02-13 16:40:27 +00:00
2017-02-14 19:01:50 +00:00
Page int // optional
Per_page int // optional
2017-02-13 16:40:27 +00:00
}
2017-04-16 20:49:50 +00:00
// Search describes search response
2017-02-13 16:40:27 +00:00
type Search struct {
2017-02-14 19:01:50 +00:00
Pagination Page `json:"pagination"`
2017-04-16 21:09:01 +00:00
Results []Result `json:"results,omitempty"`
2017-02-13 16:40:27 +00:00
}
2017-04-16 20:49:50 +00:00
// Result describes a part of search result
2017-02-14 19:01:50 +00:00
type Result struct {
2017-04-16 21:09:01 +00:00
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"`
2017-02-13 16:40:27 +00:00
}
func newSearchService(api *apirequest.API) *SearchService {
return &SearchService{
api: api.Path("database/search"),
}
}
2017-04-16 21:09:01 +00:00
// 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
2017-02-13 16:40:27 +00:00
func (self *SearchService) Search(params *SearchRequest) (*Search, *http.Response, error) {
search := new(Search)
apiError := new(APIError)
2017-02-14 19:01:50 +00:00
resp, err := self.api.New().QueryStruct(params).Receive(search, apiError)
2017-02-13 16:40:27 +00:00
return search, resp, relevantError(err, *apiError)
}