diff --git a/.discogs.go.swp b/.discogs.go.swp deleted file mode 100644 index 175473d..0000000 Binary files a/.discogs.go.swp and /dev/null differ diff --git a/.models.go.swp b/.models.go.swp deleted file mode 100644 index 61ae027..0000000 Binary files a/.models.go.swp and /dev/null differ diff --git a/discogs.go b/discogs.go index f08aa57..2e0aff9 100644 --- a/discogs.go +++ b/discogs.go @@ -64,7 +64,7 @@ func NewClient(o *Options) (*Client, error) { Artist: newArtistService(o.URL + "/artists/"), Label: newLabelService(o.URL + "/labels/"), Master: newMasterService(o.URL + "/masters/"), - Search: newSearchService(base.New()), + Search: newSearchService(o.URL + "/database/search"), }, nil } diff --git a/examples/discogs_example.go b/examples/discogs_example.go index aef3fb0..b5359ef 100644 --- a/examples/discogs_example.go +++ b/examples/discogs_example.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "net/url" "github.com/irlndts/go-discogs" ) @@ -17,7 +18,9 @@ func main() { 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 { fmt.Println(err) return diff --git a/search.go b/search.go index 6485540..2199760 100644 --- a/search.go +++ b/search.go @@ -1,17 +1,19 @@ package discogs -import ( - "net/http" - - "github.com/irlndts/go-apirequest" -) +import "net/url" // SearchService ... 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 { Q string // search query (optional) Type string // one of release, master, artist, label (optional) @@ -32,8 +34,8 @@ type SearchRequest struct { Submitter string // search submitter username (optional) Contributer string // search contributor usernames (optional) - Page int // optional - Per_page int // optional + Page int // optional + PerPage int // optional } // Search describes search response @@ -60,20 +62,15 @@ type Result struct { ID int `json:"id,omitempty"` } -func newSearchService(api *apirequest.API) *SearchService { - return &SearchService{ - api: api.Path("database/search"), - } -} - // 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) - - resp, err := self.api.New().QueryStruct(params).Receive(search, apiError) - return search, resp, relevantError(err, *apiError) +// TODO(irlndts): improve params to pass +func (s *SearchService) Search(params url.Values) (*Search, error) { + var search *Search + if err := request(s.url, params, &search); err != nil { + return nil, err + } + return search, nil }