diff --git a/api/v1/album.go b/api/v1/album.go new file mode 100644 index 0000000..74d4cbc --- /dev/null +++ b/api/v1/album.go @@ -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 +} \ No newline at end of file diff --git a/api/v1/client.go b/api/v1/client.go index a2dd454..49d1d15 100644 --- a/api/v1/client.go +++ b/api/v1/client.go @@ -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 diff --git a/examples/list.go b/examples/album.go similarity index 83% rename from examples/list.go rename to examples/album.go index 43076b5..6457136 100644 --- a/examples/list.go +++ b/examples/album.go @@ -1,6 +1,7 @@ package main import ( + "fmt" photoprism "github.com/kris-nova/client-go" "github.com/kris-nova/logger" ) @@ -16,6 +17,7 @@ func main() { logger.Level = 4 // // --- + uuid := "aqnzih81icziiyae" client := photoprism.New("http://localhost:8080") err := client.Auth(photoprism.NewClientAuthLogin("admin", "missy")) @@ -24,6 +26,7 @@ func main() { } logger.Always("Logged in...") - + album, err := client.V1().GetAlbum(uuid) + fmt.Println(album) } diff --git a/internal/api/album.go b/internal/api/album.go index 02abd18..5ae3f86 100644 --- a/internal/api/album.go +++ b/internal/api/album.go @@ -40,7 +40,7 @@ func SaveAlbumAsYaml(a entity.Album) { } } -// GET /api/v1/albums +// GET /api/v1/albums/:uuid func GetAlbums(router *gin.RouterGroup) { router.GET("/albums", func(c *gin.Context) { s := Auth(SessionID(c), acl.ResourceAlbums, acl.ActionSearch) diff --git a/sample-app/photoprism/storage/cache/sessions.json b/sample-app/photoprism/storage/cache/sessions.json index 04a62a2..3de5ce1 100644 --- a/sample-app/photoprism/storage/cache/sessions.json +++ b/sample-app/photoprism/storage/cache/sessions.json @@ -39,6 +39,11 @@ "tokens": null, "expiration": 1613501612939596202 }, + "0f257f1b73a31dbb0cf7209bfdf46c02094f99da64e21e05": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613684753597482209 + }, "0f58fcf81fdef7038db70a777b7eef0eee21ec715fdd3eb2": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -59,6 +64,11 @@ "tokens": null, "expiration": 1613522078076464014 }, + "1df4c9db0a9092076596fb78727d069689c4b3083372a1fe": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613683482108919987 + }, "21a2853a53625574889c1b0d653170efaf3ba51489c3da85": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -164,6 +174,11 @@ "tokens": null, "expiration": 1613509579377741749 }, + "4b390db50d53378cfd6e3e3b08aa2a02b1df8fdcf1bda5c5": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613683106227931942 + }, "5225f5600acaefec701d3ab1f3cfe2cf4b10ad025f2bf58e": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -209,6 +224,11 @@ "tokens": null, "expiration": 1613502943460686773 }, + "7a22f182d99dad428cc639c1c132060a7aaedb2dfdadf260": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613684752546409992 + }, "7a82ce501006461a4fe1f69fca24f0a4ccdb716b47fe735e": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -259,6 +279,11 @@ "tokens": null, "expiration": 1613513997238837821 }, + "8df748d6cb902b922dbd7c86dfe1a176ed5ab77d8f6f6397": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613682894304104797 + }, "910c4f6a3943e402e338511b235f43f8728d6f7e18b2c1b3": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -294,6 +319,11 @@ "tokens": null, "expiration": 1613526336803063121 }, + "961077032ebb89103c4e200be0e7517242cbfd0cbb989afc": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613683429612623757 + }, "988de1401f8dfe14a3766ea883ac54fa14dfd3149cefff6d": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -344,11 +374,21 @@ "tokens": null, "expiration": 1613529105851594272 }, + "b03c0a0ffd4568804db70522319c1958aed2f46af39d1b5c": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613683163586189931 + }, "b12bcc8e03f51a00b17584596a213e41f3cddb5b4b14a29a": { "user": "uqnzie01i1nypnt9", "tokens": null, "expiration": 1613502660685792657 }, + "b68ba2f95b38fcef5ccb7307406eef6e68b49ec779240e8d": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613683356092862862 + }, "b796ead30cc71b1a7dc3865f5271f00061a7c81bf7805f5a": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -454,6 +494,11 @@ "tokens": null, "expiration": 1613525903142014501 }, + "fdbeb275182730c03ee00fc84da57dc080e60fb9d1dc587e": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613682948079600558 + }, "ff3f257a8a8d59834194117ec388228a6c2c4c799ffee9c6": { "user": "uqnzie01i1nypnt9", "tokens": null, diff --git a/sample-app/photoprism/storage/index.db b/sample-app/photoprism/storage/index.db index 47fb180..eaab8c4 100644 Binary files a/sample-app/photoprism/storage/index.db and b/sample-app/photoprism/storage/index.db differ diff --git a/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml b/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml index ba693e5..17d29b5 100755 --- a/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml +++ b/sample-app/photoprism/storage/sidecar/2021/02/20210204_031706_5B740007.yml @@ -3,7 +3,7 @@ UID: pqnzigq351j2fqgn Type: image Title: A really great photo! TitleSrc: manual -Description: 'Sample App Description: 2021-02-11 11:24:13.252619614 -0800 PST m=+6.238053352' +Description: 'Sample App Description: 2021-02-11 13:45:52.564527024 -0800 PST m=+1.150507976' DescriptionSrc: manual OriginalName: IMG_3044 Year: -1 @@ -13,5 +13,5 @@ Details: Keywords: green, tambourine KeywordsSrc: manual CreatedAt: 2021-02-04T03:17:14.613092062Z -UpdatedAt: 2021-02-11T19:46:41.863716035Z -EditedAt: 2021-02-11T19:24:13Z +UpdatedAt: 2021-02-11T21:45:52.568675691Z +EditedAt: 2021-02-11T21:45:53Z diff --git a/test/album_test.go b/test/album_test.go new file mode 100644 index 0000000..82d460f --- /dev/null +++ b/test/album_test.go @@ -0,0 +1,23 @@ +package test + +import ( + "testing" +) + +func TestHappyGetAlbum(t *testing.T) { + _, err := Client.V1().GetAlbum(WellKnownAlbumID) + if err != nil { + t.Errorf("expected success getting well known album: %v", err) + t.FailNow() + } +} + +func TestSadGetAlbum(t *testing.T) { + album, err := Client.V1().GetAlbum(UnknownAlbumID) + if err != nil { + t.Logf("success returning error for unknown album: %v", err) + return + } + t.Errorf("expected error for unknown album: %d", album.ID) + t.FailNow() +} diff --git a/test/main_test.go b/test/main_test.go index d349707..c8ca89f 100644 --- a/test/main_test.go +++ b/test/main_test.go @@ -18,6 +18,8 @@ const ( BadPassword = "charlie" WellKnownPhotoID = "pqnzigq351j2fqgn" // This is a photo in the persistent sample app UnknownPhotoID = "1234567890" + WellKnownAlbumID = "aqnzih81icziiyae" + UnknownAlbumID = "1234567890" WellKnownSampleAppConnectionString = "http://localhost:8080" ) @@ -51,7 +53,7 @@ func TestMain(m *testing.M) { logger.Always("Success!") os.Exit(0) }() - }else { + } else { logger.Always("Photoprism already running...") }