oi! oi! oi!
This commit is contained in:
parent
037a2762df
commit
e790defb31
125
commonstructs.go
Normal file
125
commonstructs.go
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
package discogs
|
||||||
|
|
||||||
|
type Video struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Duration int `json:"duration"`
|
||||||
|
Embed bool `json:"embed"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Uri string `json:"uri"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Artist 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Track struct {
|
||||||
|
Duration string `json:"duration"`
|
||||||
|
Position string `json:"position"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Type string `json:"type_"`
|
||||||
|
Extraartists []Extraartist `json:"extraartists"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Extraartist 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Label 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Identifier struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Format struct {
|
||||||
|
Descriptions []string `json:"descriptions"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Qty string `json:"qty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Community struct {
|
||||||
|
Contributors []Contributor `json:"contributors"`
|
||||||
|
Data_quality string `json:"string"`
|
||||||
|
Have int `json:"have"`
|
||||||
|
Rating Rating `json:"rating"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Submitter Submitter `json:"submitter"`
|
||||||
|
Want int `json:"want"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Submitter struct {
|
||||||
|
Resource_url string `json:"resource_url"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Rating struct {
|
||||||
|
Average float32 `json:"average"`
|
||||||
|
Count int `json:"count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Contributor struct {
|
||||||
|
Resource_url string `json:"resource_url"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type URLS struct {
|
||||||
|
Last string `json:"last"`
|
||||||
|
Next string `json:"next"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
@ -14,6 +14,7 @@ const (
|
|||||||
type Client struct {
|
type Client struct {
|
||||||
api *apirequest.API
|
api *apirequest.API
|
||||||
Release *ReleaseService
|
Release *ReleaseService
|
||||||
|
Master *MasterService
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a new Client.
|
// NewClient returns a new Client.
|
||||||
@ -23,6 +24,7 @@ func NewClient(httpClient *http.Client) *Client {
|
|||||||
return &Client{
|
return &Client{
|
||||||
api: base,
|
api: base,
|
||||||
Release: newReleaseService(base.New()),
|
Release: newReleaseService(base.New()),
|
||||||
|
Master: newMasterService(base.New()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
discogs_test.go
Normal file
17
discogs_test.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package discogs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func check(t *testing.T, e error) {
|
||||||
|
if e != nil {
|
||||||
|
t.Error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func assert(t *testing.T, condition bool, assertion string) {
|
||||||
|
if !condition {
|
||||||
|
t.Errorf("Assertion failed: %v", assertion)
|
||||||
|
}
|
||||||
|
}
|
@ -9,12 +9,19 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
d := discogs.NewClient(client).UserAgent("TestDiscogsClient/0.0.1 +http://irlndts.moscow")
|
d := discogs.NewClient(client).UserAgent("TestDiscogsClient/0.0.1 +http://irlndts.moscow")
|
||||||
params := &discogs.ReleaseParams{Release_id: "1"}
|
|
||||||
|
/*
|
||||||
|
params := &discogs.ReleaseParams{Release_id: "8138518"}
|
||||||
release, _, err := d.Release.Release(params)
|
release, _, err := d.Release.Release(params)
|
||||||
|
*/
|
||||||
|
params := &discogs.MasterVersionParams{Master_id: "1000", Page: 2, Per_page: 1}
|
||||||
|
master, _, err := d.Master.Versions(params)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(release)
|
//fmt.Println(release.Title)
|
||||||
|
fmt.Println(master)
|
||||||
}
|
}
|
||||||
//fmt.Println(resp)
|
//fmt.Println(resp)
|
||||||
}
|
}
|
||||||
|
63
masters.go
Normal file
63
masters.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package discogs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/irlndts/go-apirequest"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MasterService struct {
|
||||||
|
api *apirequest.API
|
||||||
|
}
|
||||||
|
|
||||||
|
type MasterParams struct {
|
||||||
|
Master_id string
|
||||||
|
}
|
||||||
|
|
||||||
|
type MasterVersionParams struct {
|
||||||
|
Master_id string
|
||||||
|
Page int
|
||||||
|
Per_page int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Master struct {
|
||||||
|
Styles []string `json:"styles"`
|
||||||
|
Genres []string `json:"genres"`
|
||||||
|
Videos []Video `json:"videos"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Main_release int `json:"main_release"`
|
||||||
|
Main_release_url string `json:"main_release_url"`
|
||||||
|
Uri string `json:"uri"`
|
||||||
|
Artists []Artist `json:"artists"`
|
||||||
|
Version_url string `json:"version_url"`
|
||||||
|
Year int `json:"year"`
|
||||||
|
Images []Image `json:"images"`
|
||||||
|
Resource_url string `json:"resource_url"`
|
||||||
|
Tracklist []Track `json:"tracklist"`
|
||||||
|
Id int `json:"id"`
|
||||||
|
Data_quality string `json:"data_quality"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MasterVersions struct {
|
||||||
|
Pagination Page `json:"pagination"`
|
||||||
|
Versions []Version `json:"versions"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMasterService(api *apirequest.API) *MasterService {
|
||||||
|
return &MasterService{
|
||||||
|
api: api.Path("masters/"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MasterService) Master(params *MasterParams) (*Master, *http.Response, error) {
|
||||||
|
master := new(Master)
|
||||||
|
apiError := new(APIError)
|
||||||
|
resp, err := self.api.New().Get(params.Master_id).Receive(master, apiError)
|
||||||
|
return master, resp, relevantError(err, *apiError)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MasterService) Versions(params *MasterVersionParams) (*MasterVersions, *http.Response, error) {
|
||||||
|
versions := new(MasterVersions)
|
||||||
|
apiError := new(APIError)
|
||||||
|
resp, err := self.api.New().Get(params.Master_id+"/versions").QueryStruct(params).Receive(versions, apiError)
|
||||||
|
return versions, resp, relevantError(err, *apiError)
|
||||||
|
}
|
29
masters_test.go
Normal file
29
masters_test.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package discogs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMasterService_Master(t *testing.T) {
|
||||||
|
expectedTitle := "Elephant Riddim"
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
|
||||||
|
master, _, err := d.Master.Master(&MasterParams{Master_id: "960657"})
|
||||||
|
|
||||||
|
check(t, err)
|
||||||
|
assert(t, master.Title == expectedTitle, fmt.Sprintf("master.Title looked for %s, and received %s ", expectedTitle, master.Title))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMasterService_Versions(t *testing.T) {
|
||||||
|
expectedTitle := "Stardiver"
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
|
||||||
|
versions, _, err := d.Master.Versions(&MasterVersionParams{Master_id: "1000", Page: 1, Per_page: 1})
|
||||||
|
|
||||||
|
check(t, err)
|
||||||
|
assert(t, versions.Versions[0].Title == expectedTitle, fmt.Sprintf("master.Title looked for %s, and received %s ", expectedTitle, versions.Versions[0].Title))
|
||||||
|
}
|
120
releases.go
120
releases.go
@ -16,22 +16,22 @@ type ReleaseParams struct {
|
|||||||
type Release struct {
|
type Release struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Artists []artist `json:"artists"`
|
Artists []Artist `json:"artists"`
|
||||||
Data_quality string `json:"data_quality"`
|
Data_quality string `json:"data_quality"`
|
||||||
Thumb string `json:"thumb"`
|
Thumb string `json:"thumb"`
|
||||||
Community community `json:"community"`
|
Community Community `json:"community"`
|
||||||
Companies []company `json:"companies"`
|
Companies []Company `json:"companies"`
|
||||||
Country string `json:"country"`
|
Country string `json:"country"`
|
||||||
Date_added string `json:"date_added"`
|
Date_added string `json:"date_added"`
|
||||||
Date_changed string `json:"date_changed"`
|
Date_changed string `json:"date_changed"`
|
||||||
Estimated_weight int `json:"estimated_weight"`
|
Estimated_weight int `json:"estimated_weight"`
|
||||||
Extraartists []extraartist `json:"extraartists"`
|
Extraartists []Extraartist `json:"extraartists"`
|
||||||
Format_quantity int `json:"format_quantity"`
|
Format_quantity int `json:"format_quantity"`
|
||||||
Formats []format `json:"formats"`
|
Formats []Format `json:"formats"`
|
||||||
Genres []string `json:"genres"`
|
Genres []string `json:"genres"`
|
||||||
Identifiers []identifier `json:"identifiers"`
|
Identifiers []Identifier `json:"identifiers"`
|
||||||
Images []image `json:"images"`
|
Images []Image `json:"images"`
|
||||||
Labels []label `json:"labels"`
|
Labels []Label `json:"labels"`
|
||||||
Master_id int `json:"master_id"`
|
Master_id int `json:"master_id"`
|
||||||
Master_url string `json:"master_url"`
|
Master_url string `json:"master_url"`
|
||||||
Notes string `josn:"notes"`
|
Notes string `josn:"notes"`
|
||||||
@ -40,109 +40,12 @@ type Release struct {
|
|||||||
Resource_url string `json:"resource_url"`
|
Resource_url string `json:"resource_url"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Styles []string `json:"styles"`
|
Styles []string `json:"styles"`
|
||||||
Tracklist []tracklist `json:"tracklist"`
|
Tracklist []Track `json:"tracklist"`
|
||||||
Uri string `json:"uri"`
|
Uri string `json:"uri"`
|
||||||
Videos []video `json:"videos"`
|
Videos []Video `json:"videos"`
|
||||||
Year int `json:"year"`
|
Year int `json:"year"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type video struct {
|
|
||||||
Description string `json:"description"`
|
|
||||||
Duration int `json:"duration"`
|
|
||||||
Embed bool `json:"embed"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Uri string `json:"uri"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type tracklist struct {
|
|
||||||
Duration string `json:"duration"`
|
|
||||||
Position string `json:"position"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Type string `json:"type_"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type label 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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type identifier struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type format struct {
|
|
||||||
Descriptions []string `json:"descriptions"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Qty string `json:"qty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type extraartist 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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type community struct {
|
|
||||||
Contributors []contributor `json:"contributors"`
|
|
||||||
Data_quality string `json:"string"`
|
|
||||||
Have int `json:"have"`
|
|
||||||
Rating rating `json:"rating"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
Submitter submitter `json:"submitter"`
|
|
||||||
Want int `json:"want"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type submitter struct {
|
|
||||||
Resource_url string `json:"resource_url"`
|
|
||||||
Username string `json:"username"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type rating struct {
|
|
||||||
Average float32 `json:"average"`
|
|
||||||
Count int `json:"count"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type contributor struct {
|
|
||||||
Resource_url string `json:"resource_url"`
|
|
||||||
Username string `json:"username"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type artist 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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func newReleaseService(api *apirequest.API) *ReleaseService {
|
func newReleaseService(api *apirequest.API) *ReleaseService {
|
||||||
return &ReleaseService{
|
return &ReleaseService{
|
||||||
api: api.Path("releases/"),
|
api: api.Path("releases/"),
|
||||||
@ -152,6 +55,7 @@ func newReleaseService(api *apirequest.API) *ReleaseService {
|
|||||||
func (self *ReleaseService) Release(params *ReleaseParams) (*Release, *http.Response, error) {
|
func (self *ReleaseService) Release(params *ReleaseParams) (*Release, *http.Response, error) {
|
||||||
release := new(Release)
|
release := new(Release)
|
||||||
apiError := new(APIError)
|
apiError := new(APIError)
|
||||||
resp, err := self.api.New().Get(params.Release_id).QueryStruct(params).Receive(release, apiError)
|
|
||||||
|
resp, err := self.api.New().Get(params.Release_id).Receive(release, apiError)
|
||||||
return release, resp, relevantError(err, *apiError)
|
return release, resp, relevantError(err, *apiError)
|
||||||
}
|
}
|
||||||
|
18
releases_test.go
Normal file
18
releases_test.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package discogs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReleaseService_Release(t *testing.T) {
|
||||||
|
expectedTitle := "Elephant Riddim"
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs")
|
||||||
|
release, _, err := d.Release.Release(&ReleaseParams{Release_id: "8138518"})
|
||||||
|
|
||||||
|
check(t, err)
|
||||||
|
assert(t, release.Title == expectedTitle, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedTitle, release.Title))
|
||||||
|
}
|
Reference in New Issue
Block a user