From a3f87cec68f581b5495d8c6c0dc604b241a659b2 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 20 May 2015 19:47:54 +0200 Subject: lib/cac.sh: add _cac_get_api_v1 --- lib/cac.sh | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/cac.sh b/lib/cac.sh index 48a711cd0..83f17635f 100644 --- a/lib/cac.sh +++ b/lib/cac.sh @@ -1,3 +1,5 @@ +. ./lib/url.sh + _cac_exec() { if test -z "${cac_via-}"; then (exec "$@") @@ -6,20 +8,21 @@ _cac_exec() { fi } +_cac_get_api_v1() { + _cac_exec curl -fsS \ + $(shift + set -- "$@" login="$cac_login" key="$cac_key" + for arg; do + echo -d $(printf '%s' "$arg" | url_encode) + done + ) \ + -G "https://panel.cloudatcost.com/api/v1/$1.php" +} + cac_listservers() { - _cac_exec \ - curl -fsS \ - -G \ - --data-urlencode key="$cac_key" \ - --data-urlencode login="$cac_login" \ - 'https://panel.cloudatcost.com/api/v1/listservers.php' + _cac_get_api_v1 listservers } cac_listtasks() { - _cac_exec \ - curl -fsS \ - -G \ - --data-urlencode key="$cac_key" \ - --data-urlencode login="$cac_login" \ - 'https://panel.cloudatcost.com/api/v1/listtasks.php' + _cac_get_api_v1 listtasks } -- cgit v1.2.3