DSCGS-10 Rewrite LabelService
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								.discogs.go.swp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								.discogs.go.swp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								.models.go.swp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								.models.go.swp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -62,7 +62,7 @@ func NewClient(o *Options) (*Client, error) {
 | 
				
			|||||||
	return &Client{
 | 
						return &Client{
 | 
				
			||||||
		Release: newReleaseService(o.URL+"/releases/", cur),
 | 
							Release: newReleaseService(o.URL+"/releases/", cur),
 | 
				
			||||||
		Artist:  newArtistService(o.URL + "/artists/"),
 | 
							Artist:  newArtistService(o.URL + "/artists/"),
 | 
				
			||||||
		Label:   newLabelService(base.New()),
 | 
							Label:   newLabelService(o.URL + "/labels/"),
 | 
				
			||||||
		Master:  newMasterService(o.URL + "/masters/"),
 | 
							Master:  newMasterService(o.URL + "/masters/"),
 | 
				
			||||||
		Search:  newSearchService(base.New()),
 | 
							Search:  newSearchService(base.New()),
 | 
				
			||||||
	}, nil
 | 
						}, nil
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										74
									
								
								labels.go
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								labels.go
									
									
									
									
									
								
							@@ -1,58 +1,56 @@
 | 
				
			|||||||
package discogs
 | 
					package discogs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"net/http"
 | 
						"strconv"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/irlndts/go-apirequest"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// LabelService ...
 | 
				
			||||||
type LabelService struct {
 | 
					type LabelService struct {
 | 
				
			||||||
	api *apirequest.API
 | 
						url string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type LabelParams struct {
 | 
					func newLabelService(url string) *LabelService {
 | 
				
			||||||
	Label_id string
 | 
						return &LabelService{
 | 
				
			||||||
	Page     int
 | 
							url: url,
 | 
				
			||||||
	Per_Page int
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Label resource represents a label, company, recording studio, location,
 | 
				
			||||||
 | 
					// or other entity involved with artists and releases.
 | 
				
			||||||
type Label struct {
 | 
					type Label struct {
 | 
				
			||||||
	Profile      string     `json:"profile"`
 | 
						Profile     string     `json:"profile"`
 | 
				
			||||||
	Releases_url string     `json:"releases_url"`
 | 
						ReleasesURL string     `json:"releases_url"`
 | 
				
			||||||
	Name         string     `json:"name"`
 | 
						Name        string     `json:"name"`
 | 
				
			||||||
	Contact_info string     `json:"contact_info"`
 | 
						ContactInfo string     `json:"contact_info"`
 | 
				
			||||||
	Uri          string     `json:"uri"`
 | 
						URI         string     `json:"uri"`
 | 
				
			||||||
	Sublabels    []Sublable `json:"sublabels"`
 | 
						Sublabels   []Sublable `json:"sublabels"`
 | 
				
			||||||
	Urls         []string   `json:"urls"`
 | 
						URLs        []string   `json:"urls"`
 | 
				
			||||||
	Images       []Image    `json:"images"`
 | 
						Images      []Image    `json:"images"`
 | 
				
			||||||
	Resource_url string     `json:"resource_url"`
 | 
						ResourceURL string     `json:"resource_url"`
 | 
				
			||||||
	Id           int        `json:"id"`
 | 
						ID          int        `json:"id"`
 | 
				
			||||||
	Data_quality string     `json:"data_quality"`
 | 
						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 {
 | 
					type LabelReleases struct {
 | 
				
			||||||
	Pagination Page            `json:"pagination"`
 | 
						Pagination Page            `json:"pagination"`
 | 
				
			||||||
	Releases   []ReleaseSource `json:"releases"`
 | 
						Releases   []ReleaseSource `json:"releases"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func newLabelService(api *apirequest.API) *LabelService {
 | 
					// Releases returns a list of Releases associated with the label.
 | 
				
			||||||
	return &LabelService{
 | 
					func (s *LabelService) Releases(labelID int, pagination *Pagination) (*LabelReleases, error) {
 | 
				
			||||||
		api: api.Path("labels/"),
 | 
						var releases *LabelReleases
 | 
				
			||||||
 | 
						if err := request(s.url+strconv.Itoa(labelID)+"/releases", pagination.toParams(), &releases); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
						return releases, nil
 | 
				
			||||||
 | 
					 | 
				
			||||||
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)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										148
									
								
								models.go
									
									
									
									
									
								
							
							
						
						
									
										148
									
								
								models.go
									
									
									
									
									
								
							@@ -5,33 +5,37 @@ import (
 | 
				
			|||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Video ...
 | 
				
			||||||
type Video struct {
 | 
					type Video struct {
 | 
				
			||||||
	Description string `json:"description"`
 | 
						Description string `json:"description"`
 | 
				
			||||||
	Duration    int    `json:"duration"`
 | 
						Duration    int    `json:"duration"`
 | 
				
			||||||
	Embed       bool   `json:"embed"`
 | 
						Embed       bool   `json:"embed"`
 | 
				
			||||||
	Title       string `json:"title"`
 | 
						Title       string `json:"title"`
 | 
				
			||||||
	Uri         string `json:"uri"`
 | 
						URI         string `json:"uri"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ArtistSource ...
 | 
				
			||||||
type ArtistSource struct {
 | 
					type ArtistSource struct {
 | 
				
			||||||
	Anv          string `json:"anv"`
 | 
						Anv         string `json:"anv"`
 | 
				
			||||||
	Id           int    `json:"id"`
 | 
						ID          int    `json:"id"`
 | 
				
			||||||
	Join         string `json:"join"`
 | 
						Join        string `json:"join"`
 | 
				
			||||||
	Name         string `json:"name:`
 | 
						Name        string `json:"name:`
 | 
				
			||||||
	Resource_url string `json:"resource_url"`
 | 
						ResourceURL string `json:"resource_url"`
 | 
				
			||||||
	Role         string `json:"role"`
 | 
						Role        string `json:"role"`
 | 
				
			||||||
	Tracks       string `json:"tracks"`
 | 
						Tracks      string `json:"tracks"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Image ...
 | 
				
			||||||
type Image struct {
 | 
					type Image struct {
 | 
				
			||||||
	Height       int    `json:"height"`
 | 
						Height      int    `json:"height"`
 | 
				
			||||||
	Width        int    `json:"width"`
 | 
						Width       int    `json:"width"`
 | 
				
			||||||
	Resource_url string `json:"resource_url"`
 | 
						ResourceURL string `json:"resource_url"`
 | 
				
			||||||
	Type         string `json:"type"`
 | 
						Type        string `json:"type"`
 | 
				
			||||||
	Uri          string `json:"uri"`
 | 
						URI         string `json:"uri"`
 | 
				
			||||||
	Uri150       string `json:"uri150"`
 | 
						URI150      string `json:"uri150"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Track ...
 | 
				
			||||||
type Track struct {
 | 
					type Track struct {
 | 
				
			||||||
	Duration     string         `json:"duration"`
 | 
						Duration     string         `json:"duration"`
 | 
				
			||||||
	Position     string         `json:"position"`
 | 
						Position     string         `json:"position"`
 | 
				
			||||||
@@ -40,37 +44,42 @@ type Track struct {
 | 
				
			|||||||
	Extraartists []ArtistSource `json:"extraartists"`
 | 
						Extraartists []ArtistSource `json:"extraartists"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// LabelSource ...
 | 
				
			||||||
type LabelSource struct {
 | 
					type LabelSource struct {
 | 
				
			||||||
	Catno        string `json:"catno"`
 | 
						Catno       string `json:"catno"`
 | 
				
			||||||
	Entity_type  string `json:"entity_type"`
 | 
						EntityType  string `json:"entity_type"`
 | 
				
			||||||
	Id           int    `json:"id"`
 | 
						ID          int    `json:"id"`
 | 
				
			||||||
	Name         string `json:"name"`
 | 
						Name        string `json:"name"`
 | 
				
			||||||
	Resource_url string `json:"resource_url"`
 | 
						ResourceURL string `json:"resource_url"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Itentifier ...
 | 
				
			||||||
type Identifier struct {
 | 
					type Identifier struct {
 | 
				
			||||||
	Type  string `json:"type"`
 | 
						Type  string `json:"type"`
 | 
				
			||||||
	Value string `json:"value"`
 | 
						Value string `json:"value"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Format ...
 | 
				
			||||||
type Format struct {
 | 
					type Format struct {
 | 
				
			||||||
	Descriptions []string `json:"descriptions"`
 | 
						Descriptions []string `json:"descriptions"`
 | 
				
			||||||
	Name         string   `json:"name"`
 | 
						Name         string   `json:"name"`
 | 
				
			||||||
	Qty          string   `json:"qty"`
 | 
						Qty          string   `json:"qty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Company ...
 | 
				
			||||||
type Company struct {
 | 
					type Company struct {
 | 
				
			||||||
	Catno            string `json:"catno"`
 | 
						Catno          string `json:"catno"`
 | 
				
			||||||
	Entity_type      string `json:"entity_type"`
 | 
						EntityType     string `json:"entity_type"`
 | 
				
			||||||
	Entity_type_name string `json:"entity_type_name"`
 | 
						EntityTypeName string `json:"entity_type_name"`
 | 
				
			||||||
	Id               int    `json:"id"`
 | 
						ID             int    `json:"id"`
 | 
				
			||||||
	Name             string `json:"name"`
 | 
						Name           string `json:"name"`
 | 
				
			||||||
	Resource_url     string `json:"resource_url"`
 | 
						ResourceURL    string `json:"resource_url"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Community ...
 | 
				
			||||||
type Community struct {
 | 
					type Community struct {
 | 
				
			||||||
	Contributors []Contributor `json:"contributors"`
 | 
						Contributors []Contributor `json:"contributors"`
 | 
				
			||||||
	Data_quality string        `json:"string"`
 | 
						DataQuality  string        `json:"string"`
 | 
				
			||||||
	Have         int           `json:"have"`
 | 
						Have         int           `json:"have"`
 | 
				
			||||||
	Rating       Rating        `json:"rating"`
 | 
						Rating       Rating        `json:"rating"`
 | 
				
			||||||
	Status       string        `json:"status"`
 | 
						Status       string        `json:"status"`
 | 
				
			||||||
@@ -78,73 +87,82 @@ type Community struct {
 | 
				
			|||||||
	Want         int           `json:"want"`
 | 
						Want         int           `json:"want"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Submitter ...
 | 
				
			||||||
type Submitter struct {
 | 
					type Submitter struct {
 | 
				
			||||||
	Resource_url string `json:"resource_url"`
 | 
						ResourceURL string `json:"resource_url"`
 | 
				
			||||||
	Username     string `json:"username"`
 | 
						Username    string `json:"username"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Rating ...
 | 
				
			||||||
type Rating struct {
 | 
					type Rating struct {
 | 
				
			||||||
	Average float32 `json:"average"`
 | 
						Average float32 `json:"average"`
 | 
				
			||||||
	Count   int     `json:"count"`
 | 
						Count   int     `json:"count"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Contributor ...
 | 
				
			||||||
type Contributor struct {
 | 
					type Contributor struct {
 | 
				
			||||||
	Resource_url string `json:"resource_url"`
 | 
						ResourceURL string `json:"resource_url"`
 | 
				
			||||||
	Username     string `json:"username"`
 | 
						Username    string `json:"username"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Page ...
 | 
				
			||||||
type Page struct {
 | 
					type Page struct {
 | 
				
			||||||
	Per_page int  `json:"per_page"`
 | 
						PerPage int      `json:"per_page"`
 | 
				
			||||||
	Items    int  `json:"items"`
 | 
						Items   int      `json:"items"`
 | 
				
			||||||
	Page     int  `json:"page"`
 | 
						Page    int      `json:"page"`
 | 
				
			||||||
	Urls     URLS `json:"urls"`
 | 
						URLs    URLsList `json:"urls"`
 | 
				
			||||||
	Pages    int  `json:"pages"`
 | 
						Pages   int      `json:"pages"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type URLS struct {
 | 
					// URLsList ...
 | 
				
			||||||
 | 
					type URLsList struct {
 | 
				
			||||||
	Last string `json:"last"`
 | 
						Last string `json:"last"`
 | 
				
			||||||
	Next string `json:"next"`
 | 
						Next string `json:"next"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Version ...
 | 
				
			||||||
type Version struct {
 | 
					type Version struct {
 | 
				
			||||||
	Catno        string `json:"catno"`
 | 
						Catno       string `json:"catno"`
 | 
				
			||||||
	Country      string `json:"country"`
 | 
						Country     string `json:"country"`
 | 
				
			||||||
	Format       string `json:"format"`
 | 
						Format      string `json:"format"`
 | 
				
			||||||
	Id           int    `json:"id"`
 | 
						ID          int    `json:"id"`
 | 
				
			||||||
	Label        string `json:"label"`
 | 
						Label       string `json:"label"`
 | 
				
			||||||
	Released     string `json:"released"`
 | 
						Released    string `json:"released"`
 | 
				
			||||||
	Resource_url string `json:"resource_url"`
 | 
						ResourceURL string `json:"resource_url"`
 | 
				
			||||||
	Status       string `json:"status"`
 | 
						Status      string `json:"status"`
 | 
				
			||||||
	Thumb        string `json:"thumb"`
 | 
						Thumb       string `json:"thumb"`
 | 
				
			||||||
	Title        string `json:"title"`
 | 
						Title       string `json:"title"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Member ...
 | 
				
			||||||
type Member struct {
 | 
					type Member struct {
 | 
				
			||||||
	Active       bool   `json:"active"`
 | 
						Active      bool   `json:"active"`
 | 
				
			||||||
	Id           int    `json:"id"`
 | 
						ID          int    `json:"id"`
 | 
				
			||||||
	Name         string `json:"name"`
 | 
						Name        string `json:"name"`
 | 
				
			||||||
	Resource_url string `json:"resource_url"`
 | 
						ResourceURL string `json:"resource_url"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Sublable ...
 | 
				
			||||||
type Sublable struct {
 | 
					type Sublable struct {
 | 
				
			||||||
	Resource_url string `json:"url"`
 | 
						ResourceURL string `json:"url"`
 | 
				
			||||||
	Id           int    `json:"id"`
 | 
						ID          int    `json:"id"`
 | 
				
			||||||
	Name         string `json:"name"`
 | 
						Name        string `json:"name"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ReleaseSource ...
 | 
				
			||||||
type ReleaseSource struct {
 | 
					type ReleaseSource struct {
 | 
				
			||||||
	Artist       string `json:"artist"`
 | 
						Artist      string `json:"artist"`
 | 
				
			||||||
	Catno        string `json:"catno"`
 | 
						Catno       string `json:"catno"`
 | 
				
			||||||
	Format       string `json:"format"`
 | 
						Format      string `json:"format"`
 | 
				
			||||||
	Id           int    `json:"id"`
 | 
						ID          int    `json:"id"`
 | 
				
			||||||
	Resource_url string `json:"resource_url"`
 | 
						ResourceURL string `json:"resource_url"`
 | 
				
			||||||
	Status       string `json:"status"`
 | 
						Status      string `json:"status"`
 | 
				
			||||||
	Thumb        string `json:"thumb"`
 | 
						Thumb       string `json:"thumb"`
 | 
				
			||||||
	Title        string `json:"title"`
 | 
						Title       string `json:"title"`
 | 
				
			||||||
	Year         int    `json:"year"`
 | 
						Year        int    `json:"year"`
 | 
				
			||||||
	Main_release int    `json:"main_release"`
 | 
						MainRelease int    `json:"main_release"`
 | 
				
			||||||
	Role         string `json:"role"`
 | 
						Role        string `json:"role"`
 | 
				
			||||||
	Type         string `json:"type"`
 | 
						Type        string `json:"type"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Pagination ...
 | 
					// Pagination ...
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user