2021-02-11 22:46:28 +01:00
|
|
|
package api
|
|
|
|
|
2021-02-12 00:32:03 +01:00
|
|
|
import "fmt"
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// AlbumOptions are the parameters passed to get
|
|
|
|
// albums by various fields. Populate these as needed
|
|
|
|
// to pass to the SDK
|
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-12 03:04:53 +01:00
|
|
|
// GetAlbums is used to list albums by query fields.
|
|
|
|
//
|
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{
|
2021-02-12 03:04:53 +01:00
|
|
|
ParamType: DefaultAlbumOptionsParamType,
|
|
|
|
Q: DefaultAlbumOptionsQ,
|
|
|
|
Count: DefaultAlbumOptionsCount,
|
|
|
|
Offset: DefaultAlbumOptionsOffset,
|
|
|
|
Category: DefaultAlbumOptionsCategory,
|
2021-02-11 23:21:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// GetAlbum is used to get an album by an UUID.
|
|
|
|
//
|
2021-02-11 23:21:44 +01:00
|
|
|
// 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
|
|
|
}
|
2021-02-12 00:32:03 +01:00
|
|
|
|
|
|
|
// CreateAlbum is used to create a new Album.
|
|
|
|
//
|
|
|
|
// CreateAlbum will default to sane values
|
|
|
|
// such that an empty Album{} object will still
|
|
|
|
// create a new album.
|
|
|
|
//
|
2021-02-12 03:04:53 +01:00
|
|
|
// POST /api/v1/albums
|
|
|
|
func (v1 *V1Client) CreateAlbum(album Album) (Album, error) {
|
|
|
|
err := v1.POST(&album, "/api/v1/albums").JSON(&album)
|
|
|
|
return album, err
|
2021-02-12 00:32:03 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// UpdateAlbum will update meta information about an album.
|
|
|
|
//
|
2021-02-12 00:32:03 +01:00
|
|
|
// PUT /api/v1/albums/:uid
|
2021-02-12 03:04:53 +01:00
|
|
|
func (v1 *V1Client) UpdateAlbum(album Album) (Album, error) {
|
|
|
|
if album.AlbumUID == "" {
|
|
|
|
return album, fmt.Errorf("missing album.AlbumUID in album")
|
2021-02-12 00:32:03 +01:00
|
|
|
}
|
2021-02-12 03:04:53 +01:00
|
|
|
err := v1.PUT(&album, "/api/v1/albums/%s", album.AlbumUID).JSON(&album)
|
|
|
|
return album, err
|
2021-02-12 00:32:03 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// DeleteAlbums will batch delete a set of albums by ID.
|
|
|
|
//
|
2021-02-12 00:32:03 +01:00
|
|
|
// POST /api/v1/batch/albums/delete
|
2021-02-12 03:04:53 +01:00
|
|
|
func (v1 *V1Client) DeleteAlbums(albumUUIDs []string) error {
|
2021-02-12 00:32:03 +01:00
|
|
|
payload := struct {
|
|
|
|
Albums []string `json:"albums"`
|
|
|
|
}{
|
2021-02-12 03:04:53 +01:00
|
|
|
Albums: albumUUIDs,
|
2021-02-12 00:32:03 +01:00
|
|
|
}
|
|
|
|
resp := v1.POST(payload, "/api/v1/batch/albums/delete")
|
|
|
|
return resp.Error
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// LikeAlbum can be used to like an album.
|
|
|
|
//
|
2021-02-12 00:32:03 +01:00
|
|
|
// POST /api/v1/albums/:uid/like
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// uid: string Album UID
|
|
|
|
func (v1 *V1Client) LikeAlbum(uuid string) error {
|
|
|
|
resp := v1.POST(nil, "/api/v1/albums/%s/like", uuid)
|
|
|
|
return resp.Error
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// DislikeAlbum can be used to dislike an album.
|
|
|
|
//
|
2021-02-12 00:32:03 +01:00
|
|
|
// DELETE /api/v1/albums/:uid/like
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// uid: string Album UID
|
|
|
|
func (v1 *V1Client) DislikeAlbum(uuid string) error {
|
|
|
|
resp := v1.DELETE(nil, "/api/v1/albums/%s/like", uuid)
|
|
|
|
return resp.Error
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// CloneAlbum can be used to clone an album and will
|
|
|
|
// return the newly cloned album on success.
|
|
|
|
//
|
2021-02-12 00:32:03 +01:00
|
|
|
// POST /api/v1/albums/:uid/clone
|
2021-02-12 03:04:53 +01:00
|
|
|
func (v1 *V1Client) CloneAlbum(album Album) (Album, error) {
|
|
|
|
if album.AlbumUID == "" {
|
|
|
|
return album, fmt.Errorf("missing album.AlbumUID in album")
|
2021-02-12 00:32:03 +01:00
|
|
|
}
|
|
|
|
newAlbum := Album{}
|
2021-02-12 03:04:53 +01:00
|
|
|
err := v1.POST(&album, "/api/v1/albums/%s/clone", album.AlbumUID).JSON(&newAlbum)
|
2021-02-12 00:32:03 +01:00
|
|
|
return newAlbum, err
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// AddPhotosToAlbum will associate a set of photos by UUID with an album by UUID
|
|
|
|
//
|
2021-02-12 00:32:03 +01:00
|
|
|
// POST /api/v1/albums/:uid/photos
|
2021-02-12 02:16:37 +01:00
|
|
|
func (v1 *V1Client) AddPhotosToAlbum(albumUUID string, photoIDs []string) error {
|
|
|
|
payload := struct {
|
|
|
|
Photos []string `json:"photos"`
|
|
|
|
}{
|
|
|
|
Photos: photoIDs,
|
|
|
|
}
|
|
|
|
resp := v1.POST(&payload, "/api/v1/albums/%s/photos", albumUUID)
|
2021-02-12 00:32:03 +01:00
|
|
|
return resp.Error
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// DeletePhotosFromAlbum will disassociate a set of photos by UUID from an album by UUID
|
|
|
|
//
|
2021-02-12 00:32:03 +01:00
|
|
|
// DELETE /api/v1/albums/:uid/photos
|
2021-02-12 02:16:37 +01:00
|
|
|
func (v1 *V1Client) DeletePhotosFromAlbum(albumUUID string, photoIDs []string) error {
|
|
|
|
payload := struct {
|
|
|
|
Photos []string `json:"photos"`
|
|
|
|
}{
|
|
|
|
Photos: photoIDs,
|
|
|
|
}
|
|
|
|
resp := v1.DELETE(&payload, "/api/v1/albums/%s/photos", albumUUID)
|
2021-02-12 00:32:03 +01:00
|
|
|
return resp.Error
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:04:53 +01:00
|
|
|
// GetAlbumDownload will return a .zip file of the album's content
|
|
|
|
// and can be used to download an album from the API.
|
|
|
|
//
|
2021-02-12 00:32:03 +01:00
|
|
|
// GET /api/v1/albums/:uid/dl
|
|
|
|
func (v1 *V1Client) GetAlbumDownload(uuid string) ([]byte, error) {
|
|
|
|
// NOTE: Even though this method is singular GetAlbum
|
|
|
|
// if will call the "albums" plural endpoint.
|
2021-02-12 02:25:03 +01:00
|
|
|
resp := v1.GET("/api/v1/albums/%s?t=%s", uuid, v1.downloadToken)
|
2021-02-12 00:32:03 +01:00
|
|
|
return resp.Body, resp.Error
|
|
|
|
}
|