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

72 lines
2.3 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-02-14 19:01:50 +00:00
type SearchService struct {
api *apirequest.API
}
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
}
type Search struct {
2017-02-14 19:01:50 +00:00
Pagination Page `json:"pagination"`
Results []Result `json:"results"`
2017-02-13 16:40:27 +00:00
}
2017-02-14 19:01:50 +00:00
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"`
2017-02-13 16:40:27 +00:00
}
func newSearchService(api *apirequest.API) *SearchService {
return &SearchService{
api: api.Path("database/search"),
}
}
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)
}