X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fseekat;a=blobdiff_plain;f=lib%2FAPI%2FLinks%2Ffunctions.php;fp=lib%2FAPI%2FLinks%2Ffunctions.php;h=eb9b495adedb11354d95b4b44e2cb1f1fb3f61da;hp=0000000000000000000000000000000000000000;hb=f4aa6beaf2e1f0dc9c877782cbbad5a989194517;hpb=626d8937c75f6d8fca463fa2b374f645068b2d6d;ds=sidebyside diff --git a/lib/API/Links/functions.php b/lib/API/Links/functions.php new file mode 100644 index 0000000..eb9b495 --- /dev/null +++ b/lib/API/Links/functions.php @@ -0,0 +1,61 @@ +getLinks(); + if ($links && ($first = $links->getFirst())) { + return $api->withUrl($first)->get(null, null, $cache); + } + return Future\reject($api->getFuture(), $links); +} + +/** + * Perform a GET request against the link's "prev" relation + * + * @return Promise + */ +function prev(API $api, Cache\Service $cache = null) : Promise { + $links = $api->getLinks(); + if ($links && ($prev = $links->getPrev())) { + return $api->withUrl($prev)->get(null, null, $cache); + } + return Future\reject($api->getFuture(), $links); +} + +/** + * Perform a GET request against the link's "next" relation + * + * @return Promise + */ +function next(API $api, Cache\Service $cache = null) : Promise { + $links = $api->getLinks(); + if ($links && ($next = $links->getNext())) { + return $api->withUrl($next)->get(null, null, $cache); + } + return Future\reject($api->getFuture(), $links); +} + +/** + * Perform a GET request against the link's "last" relation + * + * @return Promise + */ +function last(API $api, Cache\Service $cache = null) : Promise { + $links = $api->getLinks(); + if ($links && ($last = $links->getLast())) { + return $api->withUrl($last)->get(null, null, $cache); + } + return Future\reject($api->getFuture(), $links); +} +