From 1091d9be0216c352069830308fe5c53205193557 Mon Sep 17 00:00:00 2001 From: irlndts Date: Tue, 13 Mar 2018 00:12:06 +0300 Subject: [PATCH 1/4] DSCGS-11 Improve SearchService --- .discogs.go.swp | Bin 12288 -> 12288 bytes .search.go.swp | Bin 0 -> 12288 bytes discogs.go | 3 +- .../.discogs_example.go.swp | Bin 16384 -> 12288 bytes examples/discogs_example.go | 5 ++- search.go | 38 ++++++++---------- 6 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 .search.go.swp rename .models.go.swp => examples/.discogs_example.go.swp (64%) diff --git a/.discogs.go.swp b/.discogs.go.swp index 175473ddd4c9d921175b96fa88addcb9c246ce8e..9d2f48df31c1ff4b65e21f2ec2a253394e4a09bb 100644 GIT binary patch delta 297 zcmZojXh@JsG6?hZRj|-AU;qLE28LsAmPP55N;34AZj}1Q&zQAYP~bB^FBdBV!#OsH z3ZRezKVy9=7Xw2q5Jv-X6cDQd@ik5chQ&Z!3BU+~f#E3--v;8DKs*hI zrvUL}Aoc-bZXo`}&cN^%h+hHmH6XqU#Jhob4iI+(aUBp>192P>$FeghGZ+FH3P3Cj z!~#J473jV%Kzsp+L2f7#x8N10Yrg zVg(?U2jbsAH-g;xWAi~pUe<{R^e3NF)7UJiUck(ilvtdq=a*Wpp}BdsRw^q1yY(>s diff --git a/.search.go.swp b/.search.go.swp new file mode 100644 index 0000000000000000000000000000000000000000..e99411de3ba113a1c9ae4953c6905ae3646623db GIT binary patch literal 12288 zcmeHNONbmr7_Rt895osu2x^eZ2EvTY&O{}+t^~4Ki7a^#cQ*kIA*t!EndxkI*H~4( z%Ou3)=*^QCO@asG$%`j1UWJGt>QPiQXTh92c=D_2>Y47DNg&5SHGK4R|IhlW{=aM4 z>Kr(;a)K_j4iH?s2wC|1%lCg!FOXXY35jH!hFTfPeXk{{d7|b|u;7Rg8}mz%Y{epA z@ubm*&SASJ+DZoPUZne3rxl2#J(kRekqSglwH0SF=(l=e(v5%i40r|}lz~il=NER8 z*I#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qi-4ju-JU>a-ySA(~)hJO(p1&@M9z|TMmwt+$L6|fqt0#|~+U`_uk@DTVh zcmVtmG{J5#3PwN~e2hMS2;Kz02hV~dpaq)XyMW@_1N`9?@CtYZyaHYUuYgy;E8rFQ ztQEkg4JlMAqoBnlZzimSl2Z12Wm2fVa?5VquA?`4dTpHv=)?hs-XA&<*rY#KA4GRT}af@s!ZbaJ9K8-Zx>Jv<#M+!P!;Wq z^VfAQ$zl&iMguHMDtZqnx$l0Kg=4ge!bTQzFghCG1WnDRQ7!0e1q0Z}4kNu?&>yIH zhgP+(KUZ1yrN){9QdCH6iC}k}n=8#=;QBy{ds2aIf4%X9|8vIh*e!Ow`G-@|OdnXj zVYAlCV%KT-EX0%Ax_}mHnK|<|OGcO%1()jr{YhwDkbNA4!IIFo_v0bcA_1=o; zxuV~W@Xgnu!nS4;mKpPTh*slwqQhAb#SKsjg*>KuuZ{ofU%qb);l$~F_6F*e&qTyMGARl1S7%kG_Pu|u5ShIPAlvAd7UZ`owuPW8?izAxYtA9jDx IMz(?UZ=xJYyZ`_I 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..4249429 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,14 @@ 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) +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 } From 4b824487ea551569427eda450654e5146685370f Mon Sep 17 00:00:00 2001 From: irlndts Date: Tue, 13 Mar 2018 00:12:37 +0300 Subject: [PATCH 2/4] DSCGS-11 Improve SearchService --- examples/.discogs_example.go.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 examples/.discogs_example.go.swp diff --git a/examples/.discogs_example.go.swp b/examples/.discogs_example.go.swp deleted file mode 100644 index 472f535bfbeff2f740a607e600ef869e333185a6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2L2DC16vwCDa;O#+#Dg#$scdbsn_7?>=%H2*7OK)VIfx+B&15rVcXpkfZ8fF( zJ-jM@0L9PX#j_q2Jqdcz51{`f+ZJ*NcoO9e{FvD{^WM(pCty4)}+mPY)H0{+^we{mPl<|1dld@nCr9p1PAkwZ| z?D%1t1jjSAw$8&e$^-RCCRwcVpbR`H1Adf_7p7-2Kn5loC|swuJk6G_EDpcw7sV_; zbGkV>hi1tD86X2>fDDiUGC&5%02%nN47hBHJ;jMml&88-_ETeh`A8iZAOmE843Ggb zKnBPF86X2>fDDiUGVl)?kZs1EO*3}+BsP!#{||rv|2)Om5AYRy1|PtC@CLjFufPjX zfNNk5oCP!B7ixV2U%)5u5xfP@K_6()0vli*RKei=^MD!|AOmE843GgbKnBPF86X2> zfDHU?0|%_qNt}PzYU4Vdm|NJrZ$y<_6)Tymc~-%KidC+#27{xevGJ6(nARPR0iRvr zM#p@gVeK%pIt({fc-!An(uUo#^D=2=k|T38K-hWWAzmrAda|}I`+dHtcD33QM{79B z6gKu-GA>lUf585HR|hCo*-m@PH29ziQAJ>_uvVGyF=FCob8{GL=E|-{%D4s>+bVZA zMi Date: Sat, 17 Mar 2018 20:57:41 +0300 Subject: [PATCH 3/4] DSCGS-11 Cleanup --- .discogs.go.swp | Bin 12288 -> 0 bytes .search.go.swp | Bin 12288 -> 0 bytes discogs.go | 1 - 3 files changed, 1 deletion(-) delete mode 100644 .discogs.go.swp delete mode 100644 .search.go.swp diff --git a/.discogs.go.swp b/.discogs.go.swp deleted file mode 100644 index 9d2f48df31c1ff4b65e21f2ec2a253394e4a09bb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2Pi$009LEO?=z=H_6XQjHJVV`Wx9+@%E8Gn8p*Q7 z!AdOrB#Xl2#z|-M1%rhwkRl2eV%2C@{U~b&-6w;!SVq}`4DzGDklnbByLJjV1@2IR zwyF>A+s2;SyT_FJ6W&hR@zC5IF5-qe1)Ks-0jGddz$xGqa0)mDoC0^V0;;uvy@m~J z%r|i|KW@0;m|wbsQ@|gF4;%-_z|-KL`x*Ni`~|LoPr)T{4y=M0)By(r z;1TfcR`?Arf{(y?a2BkBQy>O=0RvaIF!ll9-~@OH%!6IvT7j_-!3t=C9pE1D$9;@_ z5555xz`Niba2^~2Tfv|ALIdz4xCX9*FTnfYZEzN>f>*!^um=#>0k(tR5vSk46`*7G zHE`^QhzROhC(*Nq*%>rD`n~vT((M#73xjpPm4HJNm`T& zCktjosl*CcqO%4Uf)(OA;Yd4&DUB0aWd*yGzBe>Xan@FG;?MA~R!NegUO!7E_eWq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M1ujW;uvRxoJ}_y(Yfa z3KiL;IYmvH&r5l+yj##}?^E37n}?D?sV}YOTdhj(#BPZN{X#OMOWEC-ZBk|d%gX6gLAvC%lU3B Date: Sat, 17 Mar 2018 20:59:51 +0300 Subject: [PATCH 4/4] DSCGS-11 Cleanup --- search.go | 1 + 1 file changed, 1 insertion(+) diff --git a/search.go b/search.go index 4249429..2199760 100644 --- a/search.go +++ b/search.go @@ -66,6 +66,7 @@ type Result struct { // 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 +// 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 {