From 7a214b4b15b010b1cceb76732d29af4540722bea Mon Sep 17 00:00:00 2001 From: irlndts Date: Mon, 12 Mar 2018 23:31:47 +0300 Subject: [PATCH] DSCGS-10 Rewrite LabelService --- .discogs.go.swp | Bin 0 -> 12288 bytes .models.go.swp | Bin 0 -> 16384 bytes discogs.go | 2 +- labels.go | 74 ++++++++++++------------ models.go | 148 +++++++++++++++++++++++++++--------------------- 5 files changed, 120 insertions(+), 104 deletions(-) create mode 100644 .discogs.go.swp create mode 100644 .models.go.swp diff --git a/.discogs.go.swp b/.discogs.go.swp new file mode 100644 index 0000000000000000000000000000000000000000..175473ddd4c9d921175b96fa88addcb9c246ce8e GIT binary patch literal 12288 zcmeI2&ug4T7{{lDR<~LeD~O18`WEB6o6WnmR%io3Hb2@_n=~d(X-hA&@6KkYdG~$S znc0LkO%=t1C|<;a6uhW~iqwPp2Y435i{4f2MbusdwTgac=G|zR3G zzR!<0AzRyX{O}arAMGLdJV3}hKU_NXSmO~gyN?hdleDgtdGf!Xs?@xthNf6Nnq`Ya zRUxA!i&=8xpbPngm4&RLWL#Mgy4k5kan`Ezo($E6in9e($&b-OcH=z$+AH7{*q{O( z-5A=xojkqwDO>8hgI#pTgYz4l#G88syaHYUuYgy;E8rFI3U~#)0(Y_ky1j|Kgbi%Y zHzD%lrW=m=r9XHDyaHYUuYgy;E8rFI3U~#)0$u^HfLFjPa0e>D>VzEFLdYLmv3UId zzx((9wfhPA6Av446cB8 z!ONftX21ck3+x1sgRNi-_%rXX=TDLK=dAhO+zcQM{lHhuTmYVkLcHFJ`vC~cS zhbtWhhbE2%W!h%CIT$<}47QnMEfr0qaaPAx%0``&Udv!yMEmc~IbioWX_Ov6D z=r~I-W!Y*%MXI@Mu$Zr`7R??r355wlur3M#95-4znlO(WVerJ#=@hqu!|4)BM4iSR zDR~;7rL0zyd`U1Z5Z?g$Kz!Co^l&et!Tj7f#$vTlk10-rVBOQW?};-F4vo$jZxi#g z<}g+@Wu0p zr>ujYsTMKQyiPlc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~+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 literal 0 HcmV?d00001 diff --git a/discogs.go b/discogs.go index 8c39d8c..f08aa57 100644 --- a/discogs.go +++ b/discogs.go @@ -62,7 +62,7 @@ func NewClient(o *Options) (*Client, error) { return &Client{ Release: newReleaseService(o.URL+"/releases/", cur), Artist: newArtistService(o.URL + "/artists/"), - Label: newLabelService(base.New()), + Label: newLabelService(o.URL + "/labels/"), Master: newMasterService(o.URL + "/masters/"), Search: newSearchService(base.New()), }, nil diff --git a/labels.go b/labels.go index e5e484c..94a9e6e 100644 --- a/labels.go +++ b/labels.go @@ -1,58 +1,56 @@ package discogs import ( - "net/http" - - "github.com/irlndts/go-apirequest" + "strconv" ) +// LabelService ... type LabelService struct { - api *apirequest.API + url string } -type LabelParams struct { - Label_id string - Page int - Per_Page int +func newLabelService(url string) *LabelService { + return &LabelService{ + url: url, + } } +// Label resource represents a label, company, recording studio, location, +// or other entity involved with artists and releases. type Label struct { - Profile string `json:"profile"` - Releases_url string `json:"releases_url"` - Name string `json:"name"` - Contact_info string `json:"contact_info"` - Uri string `json:"uri"` - Sublabels []Sublable `json:"sublabels"` - Urls []string `json:"urls"` - Images []Image `json:"images"` - Resource_url string `json:"resource_url"` - Id int `json:"id"` - Data_quality string `json:"data_quality"` + Profile string `json:"profile"` + ReleasesURL string `json:"releases_url"` + Name string `json:"name"` + ContactInfo string `json:"contact_info"` + URI string `json:"uri"` + Sublabels []Sublable `json:"sublabels"` + URLs []string `json:"urls"` + Images []Image `json:"images"` + ResourceURL string `json:"resource_url"` + ID int `json:"id"` + DataQuality string `json:"data_quality"` } +// Label returns a label. +func (s *LabelService) Label(labelID int) (*Label, error) { + var label *Label + if err := request(s.url+strconv.Itoa(labelID), nil, &label); err != nil { + return nil, err + } + return label, nil +} + +// LabelReleases is a list of Releases associated with the label. type LabelReleases struct { Pagination Page `json:"pagination"` Releases []ReleaseSource `json:"releases"` } -func newLabelService(api *apirequest.API) *LabelService { - return &LabelService{ - api: api.Path("labels/"), +// Releases returns a list of Releases associated with the label. +func (s *LabelService) Releases(labelID int, pagination *Pagination) (*LabelReleases, error) { + var releases *LabelReleases + if err := request(s.url+strconv.Itoa(labelID)+"/releases", pagination.toParams(), &releases); err != nil { + return nil, err } -} - -func (self *LabelService) Label(params *LabelParams) (*Label, *http.Response, error) { - label := new(Label) - apiError := new(APIError) - - resp, err := self.api.New().Get(params.Label_id).Receive(label, apiError) - return label, resp, relevantError(err, *apiError) -} - -func (self *LabelService) Releases(params *LabelParams) (*LabelReleases, *http.Response, error) { - releases := new(LabelReleases) - apiError := new(APIError) - - resp, err := self.api.New().Get(params.Label_id+"/releases").QueryStruct(params).Receive(releases, apiError) - return releases, resp, relevantError(err, *apiError) + return releases, nil } diff --git a/models.go b/models.go index a2c50c4..c8f40b1 100644 --- a/models.go +++ b/models.go @@ -5,33 +5,37 @@ import ( "strconv" ) +// Video ... type Video struct { Description string `json:"description"` Duration int `json:"duration"` Embed bool `json:"embed"` Title string `json:"title"` - Uri string `json:"uri"` + URI string `json:"uri"` } +// ArtistSource ... type ArtistSource struct { - Anv string `json:"anv"` - Id int `json:"id"` - Join string `json:"join"` - Name string `json:"name:` - Resource_url string `json:"resource_url"` - Role string `json:"role"` - Tracks string `json:"tracks"` + Anv string `json:"anv"` + ID int `json:"id"` + Join string `json:"join"` + Name string `json:"name:` + ResourceURL string `json:"resource_url"` + Role string `json:"role"` + Tracks string `json:"tracks"` } +// Image ... type Image struct { - Height int `json:"height"` - Width int `json:"width"` - Resource_url string `json:"resource_url"` - Type string `json:"type"` - Uri string `json:"uri"` - Uri150 string `json:"uri150"` + Height int `json:"height"` + Width int `json:"width"` + ResourceURL string `json:"resource_url"` + Type string `json:"type"` + URI string `json:"uri"` + URI150 string `json:"uri150"` } +// Track ... type Track struct { Duration string `json:"duration"` Position string `json:"position"` @@ -40,37 +44,42 @@ type Track struct { Extraartists []ArtistSource `json:"extraartists"` } +// LabelSource ... type LabelSource struct { - Catno string `json:"catno"` - Entity_type string `json:"entity_type"` - Id int `json:"id"` - Name string `json:"name"` - Resource_url string `json:"resource_url"` + Catno string `json:"catno"` + EntityType string `json:"entity_type"` + ID int `json:"id"` + Name string `json:"name"` + ResourceURL string `json:"resource_url"` } +// Itentifier ... type Identifier struct { Type string `json:"type"` Value string `json:"value"` } +// Format ... type Format struct { Descriptions []string `json:"descriptions"` Name string `json:"name"` Qty string `json:"qty"` } +// Company ... type Company struct { - Catno string `json:"catno"` - Entity_type string `json:"entity_type"` - Entity_type_name string `json:"entity_type_name"` - Id int `json:"id"` - Name string `json:"name"` - Resource_url string `json:"resource_url"` + Catno string `json:"catno"` + EntityType string `json:"entity_type"` + EntityTypeName string `json:"entity_type_name"` + ID int `json:"id"` + Name string `json:"name"` + ResourceURL string `json:"resource_url"` } +// Community ... type Community struct { Contributors []Contributor `json:"contributors"` - Data_quality string `json:"string"` + DataQuality string `json:"string"` Have int `json:"have"` Rating Rating `json:"rating"` Status string `json:"status"` @@ -78,73 +87,82 @@ type Community struct { Want int `json:"want"` } +// Submitter ... type Submitter struct { - Resource_url string `json:"resource_url"` - Username string `json:"username"` + ResourceURL string `json:"resource_url"` + Username string `json:"username"` } +// Rating ... type Rating struct { Average float32 `json:"average"` Count int `json:"count"` } +// Contributor ... type Contributor struct { - Resource_url string `json:"resource_url"` - Username string `json:"username"` + ResourceURL string `json:"resource_url"` + Username string `json:"username"` } +// Page ... type Page struct { - Per_page int `json:"per_page"` - Items int `json:"items"` - Page int `json:"page"` - Urls URLS `json:"urls"` - Pages int `json:"pages"` + PerPage int `json:"per_page"` + Items int `json:"items"` + Page int `json:"page"` + URLs URLsList `json:"urls"` + Pages int `json:"pages"` } -type URLS struct { +// URLsList ... +type URLsList struct { Last string `json:"last"` Next string `json:"next"` } +// Version ... type Version struct { - Catno string `json:"catno"` - Country string `json:"country"` - Format string `json:"format"` - Id int `json:"id"` - Label string `json:"label"` - Released string `json:"released"` - Resource_url string `json:"resource_url"` - Status string `json:"status"` - Thumb string `json:"thumb"` - Title string `json:"title"` + Catno string `json:"catno"` + Country string `json:"country"` + Format string `json:"format"` + ID int `json:"id"` + Label string `json:"label"` + Released string `json:"released"` + ResourceURL string `json:"resource_url"` + Status string `json:"status"` + Thumb string `json:"thumb"` + Title string `json:"title"` } +// Member ... type Member struct { - Active bool `json:"active"` - Id int `json:"id"` - Name string `json:"name"` - Resource_url string `json:"resource_url"` + Active bool `json:"active"` + ID int `json:"id"` + Name string `json:"name"` + ResourceURL string `json:"resource_url"` } +// Sublable ... type Sublable struct { - Resource_url string `json:"url"` - Id int `json:"id"` - Name string `json:"name"` + ResourceURL string `json:"url"` + ID int `json:"id"` + Name string `json:"name"` } +// ReleaseSource ... type ReleaseSource struct { - Artist string `json:"artist"` - Catno string `json:"catno"` - Format string `json:"format"` - Id int `json:"id"` - Resource_url string `json:"resource_url"` - Status string `json:"status"` - Thumb string `json:"thumb"` - Title string `json:"title"` - Year int `json:"year"` - Main_release int `json:"main_release"` - Role string `json:"role"` - Type string `json:"type"` + Artist string `json:"artist"` + Catno string `json:"catno"` + Format string `json:"format"` + ID int `json:"id"` + ResourceURL string `json:"resource_url"` + Status string `json:"status"` + Thumb string `json:"thumb"` + Title string `json:"title"` + Year int `json:"year"` + MainRelease int `json:"main_release"` + Role string `json:"role"` + Type string `json:"type"` } // Pagination ...