1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00

REST APIv1 now uses lowercase JSON property names

- Updated rest-apiv1.sh to pretty print JSON with jq if available
- Fixed some missing checks on JSON testutils
This commit is contained in:
James Hillyerd
2016-02-25 19:21:47 -08:00
parent 5da5d3e509
commit f36e21a65c
4 changed files with 76 additions and 58 deletions

View File

@@ -36,6 +36,7 @@ arg_check() {
main() {
# Process options
local curl_opts=""
local pretty="true"
for arg in $*; do
if [[ $arg == -* ]]; then
case "$arg" in
@@ -45,6 +46,7 @@ main() {
;;
-i)
curl_opts="$curl_opts -i"
pretty=""
;;
**)
echo "Unknown option: $arg" >&2
@@ -65,11 +67,13 @@ main() {
local url=""
local method="GET"
local is_json=""
case "$command" in
body)
arg_check "$command" 2 $#
url="$URL_ROOT/mailbox/$1/$2"
is_json="true"
;;
delete)
arg_check "$command" 2 $#
@@ -79,6 +83,7 @@ main() {
list)
arg_check "$command" 1 $#
url="$URL_ROOT/mailbox/$1"
is_json="true"
;;
purge)
arg_check "$command" 1 $#
@@ -97,7 +102,12 @@ main() {
;;
esac
curl $curl_opts -H "Accept: application/json" --noproxy "$API_HOST" -X "$method" "$url"
# Use jq to pretty-print if installed and we are expecting JSON output
if [ $pretty ] && [ $is_json ] && type -P jq; then
curl -s $curl_opts -H "Accept: application/json" --noproxy "$API_HOST" -X "$method" "$url" | jq .
else
curl -s $curl_opts -H "Accept: application/json" --noproxy "$API_HOST" -X "$method" "$url"
fi
}
if [ $# -lt 1 ]; then