-
Notifications
You must be signed in to change notification settings - Fork 0
/
runrun.sh
executable file
·64 lines (52 loc) · 1.36 KB
/
runrun.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash -e
MYSELF="$(readlink -f "$0")"
MYDIR="${MYSELF%/*}"
ME=$(basename $MYSELF)
source $MYDIR/env
[[ -f $LOCAL_ENV ]] && source $LOCAL_ENV
source $MYDIR/log.sh
function runrun() {
method="$1"; shift
endpoint="$1"; shift
body="$1"; shift
#[[ -n "$body" ]] && body=" -d '${body//\"/\\\"}'"
curl_opts="--progress-bar"
if [[ $(debugging) == on ]]; then
curl_opts='-v'
fi
debug "$curl_opts -X $method $RR_API/$endpoint"
debug "$(rr_header_app_key)"
debug "$(rr_header_usr_token)"
debug "body: $body"
request_cache="$CACHE/$1-$2.request.json"
if [[ -f "$body" ]]; then
cp "$body" $request_cache
curl $curl_opts -X $method "$RR_API/$endpoint"\
-d "@$body"\
-H "Content-Type: application/json"\
-H "$(rr_header_app_key)"\
-H "$(rr_header_usr_token)"
elif [[ -n "$body" ]]; then
echo "$body" > $request_cache
curl $curl_opts -X $method "$RR_API/$endpoint"\
-d "$body"\
-H "Content-Type: application/json"\
-H "$(rr_header_app_key)"\
-H "$(rr_header_usr_token)"
else
curl $curl_opts -X $method "$RR_API/$endpoint"\
-H "$(rr_header_app_key)"\
-H "$(rr_header_usr_token)"
fi
}
## TODO
# cache responses
response=$(runrun "$@")
out="$CACHE/$1-$2.response.json"
mkdir -p $(dirname "$out")
echo "$response" > "$out"
debug "response cached to $out"
if [[ "$response" == *html* ]]; then
err "$response"
fi
echo "$response"