Check-in [c0f939a115]
Overview
Comment:Added a simple API client
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c0f939a1153a1242c19bd90fbe5236929a470df8
User & Date: rkeene on 2019-02-28 08:55:39
Other Links: manifest | tags
Context
2019-02-28
08:55
Better formatting of results check-in: 5445a8ff26 user: rkeene tags: trunk
08:55
Added a simple API client check-in: c0f939a115 user: rkeene tags: trunk
07:41
Better handling to the kit_url check-in: 01ff48e506 user: rkeene tags: trunk
Changes

Added build/utils/download-api-client version [5f112c56ea].

            1  +#! /usr/bin/env bash
            2  +
            3  +# Define endpoint
            4  +endpoint_url="https://kitcreator.rkeene.org/kitcreator"
            5  +
            6  +# Set arguments
            7  +declare -A jsonArgs
            8  +jsonArgs["platform"]="$(uname -s)-$(uname -m)"
            9  +
           10  +nextArg=''
           11  +kit_filename=''
           12  +for arg in "$@"; do
           13  +	if [ -n "${nextArg}" ]; then
           14  +		jsonArgs["${nextArg}"]="${arg}"
           15  +		nextArg=''
           16  +		continue
           17  +	fi
           18  +
           19  +	case "${arg}" in
           20  +		--platform|--tcl-version|--kitcreator-version)
           21  +			nextArg="${arg:2}"
           22  +			nextArg="${nextArg//-/_}"
           23  +			;;
           24  +	esac
           25  +done
           26  +
           27  +# Convert arguments into a request
           28  +jqArgs=()
           29  +jqSettings=''
           30  +for jsonArg in "${!jsonArgs[@]}"; do
           31  +	jqArgs+=(--arg "${jsonArg}" "${jsonArgs[${jsonArg}]}")
           32  +	jqSettings="${jqSettings} | .${jsonArg} = \$${jsonArg}"
           33  +done
           34  +jqArgs+=("${jqSettings:3}")
           35  +
           36  +jsonRequest="$(jq -crM "${jqArgs[@]}" <<<'{"action":"build"}')"
           37  +
           38  +# Make the request
           39  +results="$(curl -sSL -d "json=${jsonRequest}" "${endpoint_url}")"
           40  +url="$(jq -crM .url <<<"${results}")"
           41  +while true; do
           42  +	info="$(curl -sSL "${url}")"
           43  +	terminal="$(jq -crM .terminal <<<"${info}")"
           44  +
           45  +	if [ "${terminal}" = 'true' ]; then
           46  +		break
           47  +	fi
           48  +
           49  +	sleep 30
           50  +done
           51  +
           52  +status="$(jq -crM .status <<<"${info}")"
           53  +if [ "${status}" != "complete" ]; then
           54  +	echo "failed: ${status}" >&2
           55  +
           56  +	exit 1
           57  +fi
           58  +
           59  +kit_url="$(jq -crM .kit_url <<<"${info}")"
           60  +if [ -z "${kit_filename}" ]; then
           61  +	kit_filename="${kit_url//*\//}"
           62  +fi
           63  +
           64  +curl -sSL "${kit_url}" > "${kit_filename}"
           65  +chmod 755 "${kit_filename}"
           66  +
           67  +echo "Wrote: ${kit_filename}"
           68  +exit 0