Merge pull request #16 from irlndts/DSCGS-11
This commit is contained in:
commit
2bc2347afc
BIN
.discogs.go.swp
BIN
.discogs.go.swp
Binary file not shown.
BIN
.models.go.swp
BIN
.models.go.swp
Binary file not shown.
@ -64,7 +64,7 @@ func NewClient(o *Options) (*Client, error) {
|
|||||||
Artist: newArtistService(o.URL + "/artists/"),
|
Artist: newArtistService(o.URL + "/artists/"),
|
||||||
Label: newLabelService(o.URL + "/labels/"),
|
Label: newLabelService(o.URL + "/labels/"),
|
||||||
Master: newMasterService(o.URL + "/masters/"),
|
Master: newMasterService(o.URL + "/masters/"),
|
||||||
Search: newSearchService(base.New()),
|
Search: newSearchService(o.URL + "/database/search"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/irlndts/go-discogs"
|
"github.com/irlndts/go-discogs"
|
||||||
)
|
)
|
||||||
@ -17,7 +18,9 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
release, err := d.Master.Versions(1147170, nil)
|
params := url.Values{}
|
||||||
|
params.Set("q", "Ska-Jazz Review")
|
||||||
|
release, err := d.Search.Search(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
37
search.go
37
search.go
@ -1,17 +1,19 @@
|
|||||||
package discogs
|
package discogs
|
||||||
|
|
||||||
import (
|
import "net/url"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/irlndts/go-apirequest"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SearchService ...
|
// SearchService ...
|
||||||
type SearchService struct {
|
type SearchService struct {
|
||||||
api *apirequest.API
|
url string
|
||||||
}
|
}
|
||||||
|
|
||||||
// SerachRequest describes search request json
|
func newSearchService(url string) *SearchService {
|
||||||
|
return &SearchService{
|
||||||
|
url: url,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SerachRequest describes search request
|
||||||
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)
|
||||||
@ -33,7 +35,7 @@ type SearchRequest struct {
|
|||||||
Contributer string // search contributor usernames (optional)
|
Contributer string // search contributor usernames (optional)
|
||||||
|
|
||||||
Page int // optional
|
Page int // optional
|
||||||
Per_page int // optional
|
PerPage int // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search describes search response
|
// Search describes search response
|
||||||
@ -60,20 +62,15 @@ type Result struct {
|
|||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSearchService(api *apirequest.API) *SearchService {
|
|
||||||
return &SearchService{
|
|
||||||
api: api.Path("database/search"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search makes search request to discogs.
|
// Search makes search request to discogs.
|
||||||
// Issue a search query to our database. This endpoint accepts pagination parameters.
|
// Issue a search query to our database. This endpoint accepts pagination parameters.
|
||||||
// Authentication (as any user) is required.
|
// Authentication (as any user) is required.
|
||||||
// https://www.discogs.com/developers/#page:database,header:database-search
|
// https://www.discogs.com/developers/#page:database,header:database-search
|
||||||
func (self *SearchService) Search(params *SearchRequest) (*Search, *http.Response, error) {
|
// TODO(irlndts): improve params to pass
|
||||||
search := new(Search)
|
func (s *SearchService) Search(params url.Values) (*Search, error) {
|
||||||
apiError := new(APIError)
|
var search *Search
|
||||||
|
if err := request(s.url, params, &search); err != nil {
|
||||||
resp, err := self.api.New().QueryStruct(params).Receive(search, apiError)
|
return nil, err
|
||||||
return search, resp, relevantError(err, *apiError)
|
}
|
||||||
|
return search, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user