# This file is meant to be `source`d. function read_vars() { local key value while read -r line; do key=${line%%=*} value=${line#*=} if [[ $key = ip ]]; then bridge_ip=$value elif [[ $key = bridgeid ]]; then bridge_id=$value elif [[ $key = username ]]; then bridge_username=$value fi done &2 "functions.sh(hue_request): path required"; exit 1; } [[ $# -ge 2 ]] && method=$2 [[ $# -ge 3 ]] && body=$3 [[ $# -ge 4 ]] && { echo >&2 "functions.sh(hue_request): too many arguments"; exit 1; } local data_args=() if [[ -n $body ]]; then data_args=( -d "$body" ) fi json=$( curl -s --cacert signify_root_cert.pem \ --resolve "$bridge_id:443:$bridge_ip" -H "hue-application-key: $bridge_username" \ -X "$method" "${data_args[@]}" \ https://"$bridge_id"/clip/v2/"$path" ) errors=$(jq -r 'if has("errors") then .errors.[] | "- " + .description else empty end' <<<"$json") if [[ -n $errors ]]; then echo >&2 "Errors from Hue bridge:" echo >&2 "$errors" exit 1 fi echo "$json" }