Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions bs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ main () {
curl=$(find_tool "curl")
jq=$(find_tool "jq")

# curl/jq options
curl_options=("-s" "--http1.1" "--header" "Authorization: Token $token")
jq_json_escape_options=("-Rsa")

while getopts "hH:U:" OPTION $1 $2 $3 $4
do
case "$OPTION" in
Expand Down Expand Up @@ -56,6 +52,10 @@ main () {
esac
done

# curl/jq options
curl_options=("-s" "--http1.1" "--header" "Authorization: Token $token")
jq_json_escape_options=("-Rsa")

if [ $OPTIND -gt 1 ]; then
shift $((OPTIND-1))
OPTIND=1
Expand Down Expand Up @@ -176,16 +176,16 @@ search () {
do
case "$OPTION" in
q)
query="${query:-?}${query:+&}query=$(urlencode "$OPTARG")"
query="${query}${query:+&}query=$(urlencode "$OPTARG")"
requirement "query"
;;

p)
query="${query:-?}${query:+&}page=$OPTARG"
query="${query}${query:+&}page=$OPTARG"
;;

c)
query="${query:-?}${query:+&}count=$OPTARG"
query="${query}${query:+&}count=$OPTARG"
;;

*)
Expand All @@ -198,7 +198,7 @@ search () {
exit_with_error "required parameter(s) missing: ${required[*]}"
fi

get $branch "$query"
get $branch "" "" "$query"
}

recycle-bin () {
Expand All @@ -214,7 +214,7 @@ recycle-bin () {
;;

c)
query="${query:-?}${query:+&}count=$OPTARG"
query="${query}${query:+&}count=$OPTARG"
;;

*)
Expand All @@ -225,7 +225,7 @@ recycle-bin () {

case "$endpoint" in
list)
get $branch "$query"
get $branch "" "" "$query"
;;

restore)
Expand Down Expand Up @@ -254,19 +254,19 @@ list () {
do
case "$OPTION" in
c)
query="${query:-?}${query:+&}count=$OPTARG"
query="${query}${query:+&}count=$OPTARG"
;;

o)
query="${query:-?}${query:+&}offset=$OPTARG"
query="${query}${query:+&}offset=$OPTARG"
;;

s)
query="${query:-?}${query:+&}sort=$OPTARG"
query="${query}${query:+&}sort=$OPTARG"
;;

f)
query="${query:-?}${query:+&}filter=$OPTARG"
query="${query}${query:+&}filter=$OPTARG"
;;

*)
Expand All @@ -275,7 +275,7 @@ list () {
esac
done

get $branch "$query"
get $branch "" "" "$query"

}

Expand Down Expand Up @@ -523,9 +523,10 @@ get () {
endpoint="$1"
id="$2"
target="$3"
opts="$4"
shift 3

"$curl" "${curl_options[@]}" --request GET --url "$url/api/$endpoint${id:+/}$id${target:+/}$target"
"$curl" "${curl_options[@]}" --request GET --url "$url/api/$endpoint${id:+/}$id${target:+/}$target${opts:+?}$opts"
}

put () {
Expand Down