2021-02-11 22:46:28 +01:00
|
|
|
package api
|
|
|
|
|
2021-02-11 23:21:44 +01:00
|
|
|
type AlbumOptions struct {
|
|
|
|
ParamType string
|
|
|
|
Q string
|
|
|
|
Count int
|
|
|
|
Offset int
|
|
|
|
Category string
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
DefaultAlbumOptionsParamType = "album"
|
|
|
|
DefaultAlbumOptionsQ = ""
|
|
|
|
DefaultAlbumOptionsCount = 24
|
|
|
|
DefaultAlbumOptionsOffset = 0
|
|
|
|
DefaultAlbumOptionsCategory = ""
|
|
|
|
)
|
|
|
|
|
2021-02-11 22:46:28 +01:00
|
|
|
// GET /api/v1/albums
|
2021-02-11 23:21:44 +01:00
|
|
|
//
|
|
|
|
// Example Params: http://localhost:8080/api/v1/albums?count=24&offset=0&q=&category=&type=album
|
|
|
|
func (v1 *V1Client) GetAlbums(options *AlbumOptions) ([]Album, error) {
|
|
|
|
albums := []Album{{}}
|
|
|
|
|
|
|
|
if options == nil {
|
|
|
|
|
|
|
|
// Default to sane options for query
|
|
|
|
options = &AlbumOptions{
|
|
|
|
ParamType: "album",
|
|
|
|
Q: "",
|
|
|
|
Count: 24,
|
|
|
|
Offset: 0,
|
|
|
|
Category: "",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for missing fields
|
|
|
|
if options.Count == 0 {
|
|
|
|
return albums, nil
|
|
|
|
}
|
|
|
|
if options.ParamType == "" {
|
|
|
|
options.ParamType = DefaultAlbumOptionsParamType
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Even though this method is singular GetAlbum
|
|
|
|
// if will call the "albums" plural endpoint.
|
|
|
|
err := v1.GET("/api/v1/albums?count=%d&offset=%d&q=%s&category=%s&type=%s", options.Count, options.Offset, options.Q, options.Category, options.ParamType).JSON(&albums)
|
|
|
|
return albums, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// GET /api/v1/albums/:uuid
|
2021-02-11 22:46:28 +01:00
|
|
|
func (v1 *V1Client) GetAlbum(uuid string) (Album, error) {
|
|
|
|
album := Album{}
|
|
|
|
|
|
|
|
// NOTE: Even though this method is singular GetAlbum
|
|
|
|
// if will call the "albums" plural endpoint.
|
|
|
|
err := v1.GET("/api/v1/albums/%s", uuid).JSON(&album)
|
|
|
|
return album, err
|
2021-02-11 23:21:44 +01:00
|
|
|
}
|