Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thuongnn
Created April 26, 2020 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thuongnn/139af63efdfb3e9214780cb8f3678d1c to your computer and use it in GitHub Desktop.
Save thuongnn/139af63efdfb3e9214780cb8f3678d1c to your computer and use it in GitHub Desktop.
#!/bin/sh
set +e
set -o noglob
#
# Set Colors
#
bold=$(tput bold)
underline=$(tput sgr 0 1)
reset=$(tput sgr0)
white=$(tput setaf 7)
#
# Headers and Logging
#
underline() {
printf "${underline}${bold}%s${reset}\n" "$@"
}
info() {
printf "${white}➜ %s${reset}\n" "$@"
}
underline "Enter your access token:"
read ACCESS_TOKEN
clear
while :; do
underline "Choose one of the following options:"
echo "[Option 1]. List all file
[Option 2]. Get info of token
[Option 3]. Download file
[Option 4]. Upload file
[Option 5]. Exit"
read -p "Enter your option: " option
case $option in
1)
read -p "Enter your url: " url
data=$(curl --location --request GET "$url" -H "Accept: application/json" -H "Authorization: Bearer $ACCESS_TOKEN")
info "$data"
echo
read -p "Do you want to continue? (y/n) " continue
if [ "$continue" = "n" ]; then
break
else
clear
fi
;;
2)
echo "Server Response: "
data=$(curl --location --request GET 'http://localhost:8080/token' -H "Accept: application/json" -H "Authorization: Bearer $ACCESS_TOKEN")
info "$data"
echo
read -p "Do you want to continue? (y/n) " continue
if [ "$continue" = "n" ]; then
break
else
clear
fi
;;
3)
read -p "Enter your url: " url
curl --location --request GET "$url" -O -H "Authorization: Bearer $ACCESS_TOKEN"
echo
read -p "Do you want to continue? (y/n) " continue
if [ "$continue" = "n" ]; then
break
else
clear
fi
;;
4)
read -p "Enter your url: " url
read -p "Enter your location file upload: " location
curl -F "file=@$location" "$url" -H "Authorization: Bearer $ACCESS_TOKEN"
echo
read -p "Do you want to continue? (y/n) " continue
if [ "$continue" = "n" ]; then
break
else
clear
fi
;;
5)
break
;;
*)
echo "Sorry, I don't understand !"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment