diff --git a/artists.go b/artists.go new file mode 100644 index 0000000..0a151cb --- /dev/null +++ b/artists.go @@ -0,0 +1,41 @@ +package discogs + +import ( + "github.com/irlndts/go-apirequest" + "net/http" +) + +type ArtistService struct { + api *apirequest.API +} + +type ArtistParams struct { + Artist_id string +} + +type Artist struct { + Namevariations []string `json:"namevariations"` + Profile string `json:"profile"` + Releases_url string `json:"releases_url"` + Resource_url string `json:"resource_url"` + Uri string `json:"uri"` + Urls []string `json:"urls"` + Data_quality string `json:"data_quality"` + Id int `json:"id"` + Images []Image `json:"images"` + Members []Member `json:"members"` +} + +func newArtistService(api *apirequest.API) *ArtistService { + return &ArtistService{ + api: api.Path("artists/"), + } +} + +func (self *ArtistService) Artist(params *ArtistParams) (*Artist, *http.Response, error) { + artist := new(Artist) + apiError := new(APIError) + + resp, err := self.api.New().Get(params.Artist_id).Receive(artist, apiError) + return artist, resp, relevantError(err, *apiError) +} diff --git a/artists_test.go b/artists_test.go new file mode 100644 index 0000000..e120040 --- /dev/null +++ b/artists_test.go @@ -0,0 +1,18 @@ +package discogs + +import ( + "fmt" + "net/http" + "testing" +) + +func TestArtistService_Artist(t *testing.T) { + expectedId := 1000 + + client := &http.Client{} + d := NewClient(client).UserAgent("UnitTestClient/0.0.1 +https://github.com/irlndts/go-discogs") + artist, _, err := d.Artist.Artist(&ArtistParams{Artist_id: "1000"}) + + check(t, err) + assert(t, artist.Id == expectedId, fmt.Sprintf("Release.Title looked for %s, and received %s ", expectedId, artist.Id)) +} diff --git a/commonstructs.go b/commonstructs.go index 8d5dc70..16d59e5 100644 --- a/commonstructs.go +++ b/commonstructs.go @@ -8,7 +8,7 @@ type Video struct { Uri string `json:"uri"` } -type Artist struct { +type ArtistSource struct { Anv string `json:"anv"` Id int `json:"id"` Join string `json:"join"` @@ -28,21 +28,11 @@ type Image struct { } 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"` + Duration string `json:"duration"` + Position string `json:"position"` + Title string `json:"title"` + Type string `json:"type_"` + Extraartists []ArtistSource `json:"extraartists"` } type Label struct { @@ -123,3 +113,10 @@ type Version struct { Thumb string `json:"thumb"` Title string `json:"title"` } + +type Member struct { + Active bool `json:"active"` + Id int `json:"id"` + Name string `json:"name"` + Resource_url string `json:"resource_url"` +} diff --git a/discogs.go b/discogs.go index 3a1cd39..e3f4275 100644 --- a/discogs.go +++ b/discogs.go @@ -15,6 +15,7 @@ type Client struct { api *apirequest.API Release *ReleaseService Master *MasterService + Artist *ArtistService } // NewClient returns a new Client. @@ -25,6 +26,7 @@ func NewClient(httpClient *http.Client) *Client { api: base, Release: newReleaseService(base.New()), Master: newMasterService(base.New()), + Artist: newArtistService(base.New()), } } diff --git a/examples/discogs_example.go b/examples/discogs_example.go index e8dcf29..722e12c 100644 --- a/examples/discogs_example.go +++ b/examples/discogs_example.go @@ -14,14 +14,14 @@ func main() { params := &discogs.ReleaseParams{Release_id: "8138518"} release, _, err := d.Release.Release(params) */ - params := &discogs.MasterVersionParams{Master_id: "1000", Page: 2, Per_page: 1} - master, _, err := d.Master.Versions(params) + params := &discogs.ArtistParams{Artist_id: "1000"} + artist, _, err := d.Artist.Artist(params) if err != nil { fmt.Println(err) } else { //fmt.Println(release.Title) - fmt.Println(master) + fmt.Println(artist.Id) } //fmt.Println(resp) } diff --git a/releases.go b/releases.go index 1e95e82..00188e1 100644 --- a/releases.go +++ b/releases.go @@ -14,36 +14,36 @@ type ReleaseParams struct { } type Release struct { - Title string `json:"title"` - Id int `json:"id"` - Artists []Artist `json:"artists"` - Data_quality string `json:"data_quality"` - Thumb string `json:"thumb"` - Community Community `json:"community"` - Companies []Company `json:"companies"` - Country string `json:"country"` - Date_added string `json:"date_added"` - Date_changed string `json:"date_changed"` - Estimated_weight int `json:"estimated_weight"` - Extraartists []Extraartist `json:"extraartists"` - Format_quantity int `json:"format_quantity"` - Formats []Format `json:"formats"` - Genres []string `json:"genres"` - Identifiers []Identifier `json:"identifiers"` - Images []Image `json:"images"` - Labels []Label `json:"labels"` - Master_id int `json:"master_id"` - Master_url string `json:"master_url"` - Notes string `josn:"notes"` - Released string `json:"released"` - Released_formatted string `json:"released_formatted"` - Resource_url string `json:"resource_url"` - Status string `json:"status"` - Styles []string `json:"styles"` - Tracklist []Track `json:"tracklist"` - Uri string `json:"uri"` - Videos []Video `json:"videos"` - Year int `json:"year"` + Title string `json:"title"` + Id int `json:"id"` + Artists []ArtistSource `json:"artists"` + Data_quality string `json:"data_quality"` + Thumb string `json:"thumb"` + Community Community `json:"community"` + Companies []Company `json:"companies"` + Country string `json:"country"` + Date_added string `json:"date_added"` + Date_changed string `json:"date_changed"` + Estimated_weight int `json:"estimated_weight"` + Extraartists []ArtistSource `json:"extraartists"` + Format_quantity int `json:"format_quantity"` + Formats []Format `json:"formats"` + Genres []string `json:"genres"` + Identifiers []Identifier `json:"identifiers"` + Images []Image `json:"images"` + Labels []Label `json:"labels"` + Master_id int `json:"master_id"` + Master_url string `json:"master_url"` + Notes string `josn:"notes"` + Released string `json:"released"` + Released_formatted string `json:"released_formatted"` + Resource_url string `json:"resource_url"` + Status string `json:"status"` + Styles []string `json:"styles"` + Tracklist []Track `json:"tracklist"` + Uri string `json:"uri"` + Videos []Video `json:"videos"` + Year int `json:"year"` } func newReleaseService(api *apirequest.API) *ReleaseService {