Adding GetAlbum method and unite tests

Signed-off-by: Kris Nóva <kris@nivenly.com>
This commit is contained in:
Kris Nóva 2021-02-11 13:46:28 -08:00
parent 0476727633
commit 6b742a1db4
9 changed files with 102 additions and 6 deletions

11
api/v1/album.go Normal file
View file

@ -0,0 +1,11 @@
package api
// GET /api/v1/albums
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
}

View file

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/kris-nova/logger"
"io/ioutil"
"net/http"
"net/url"
@ -40,6 +41,17 @@ type V1Response struct {
Body []byte
}
// String is used to represent the body of the response as a string.
func (r *V1Response) String() string {
if r.Error != nil {
// Handle errors from the HTTP request first
logger.Warning("during HTTP request: %v", r.Error)
return "{}"
}
return string(r.Body)
}
// JSON will unmarshal onto whatever interface is passed in.
func (r *V1Response) JSON(i interface{}) error {
if r.Error != nil {
// Handle errors from the HTTP request first