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

84 lines
3.2 KiB
Go
Raw Normal View History

2017-02-13 16:40:27 +00:00
package discogs
import (
"github.com/google/go-querystring/query"
)
2017-02-13 16:40:27 +00:00
2017-04-16 20:49:50 +00:00
// SearchService ...
2017-02-14 19:01:50 +00:00
type SearchService struct {
2018-03-12 21:12:06 +00:00
url string
}
func newSearchService(url string) *SearchService {
return &SearchService{
url: url,
}
2017-02-14 19:01:50 +00:00
}
2018-03-17 20:12:25 +00:00
// SearchRequest describes search request
2017-02-13 16:40:27 +00:00
type SearchRequest struct {
Q string `url:"q,omitempty"` // search query
Type string `url:"type,omitempty"` // one of release, master, artist, label
Title string `url:"title,omitempty"` // search by combined “Artist Name - Release Title” title field
ReleaseTitle string `url:"release_title,omitempty"` // search release titles
Credit string `url:"credit,omitempty"` // search release credits
Artist string `url:"artist,omitempty"` // search artist names
Anv string `url:"anv,omitempty"` // search artist ANV
Label string `url:"label,omitempty"` // search label names
Genre string `url:"genre,omitempty"` // search genres
Style string `url:"style,omitempty"` // search styles
Country string `url:"country,omitempty"` // search release country
Year string `url:"year,omitempty"` // search release year
Format string `url:"format,omitempty"` // search formats
Catno string `url:"catno,omitempty"` // search catalog number
Barcode string `url:"barcode,omitempty"` // search barcodes
Track string `url:"track,omitempty"` // search track titles
Submitter string `url:"submitter,omitempty"` // search submitter username
2018-03-28 17:18:24 +00:00
Contributor string `url:"contributor,omitempty"` // search contributor usernames
2017-02-13 16:40:27 +00:00
Page int `url:"page,omitempty"`
PerPage int `url:"per_page,omitempty"`
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-25 16:39:32 +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"`
ResourceURL string `json:"resource_url,omitempty"`
Type string `json:"type,omitempty"`
ID int `json:"id,omitempty"`
2017-02-13 16:40:27 +00:00
}
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
2018-03-17 17:59:51 +00:00
// TODO(irlndts): improve params to pass
func (s *SearchService) Search(req SearchRequest) (*Search, error) {
params, err := query.Values(req)
if err != nil {
return nil, err
}
2018-03-12 21:12:06 +00:00
var search *Search
if err := request(s.url, params, &search); err != nil {
return nil, err
}
return search, nil
2017-02-13 16:40:27 +00:00
}