Implemented the shorten URL

This commit is contained in:
Alex Epstein 2017-11-09 08:58:30 -05:00
parent d8a7d8bb09
commit bc07222cd0
1 changed files with 5 additions and 5 deletions

View File

@ -146,9 +146,10 @@ fi
shortenURL()
{
response=$(curl -A curl -s -i -H "Content-Type: application/json" -X POST -d "{\"url\": \"$1\"}" http://ki.tc/ || exit 1)
returnedURL=$(echo $response | head -n 5 | tail -n 1 | grep -Eo "/[a-Z 0-9]*" | tail -n 1 2> /dev/null)
returnedURL="http://ki.tc"$returnedURL
newURL=$(echo $1 | grep -Eo "^[h]ttp[s]?://")
if [[ $newURL == "" ]]; then newURL="http://"$1; fi
response=$(curl -A curl -s -i -H "Content-Type: application/json" -X POST -d "{\"url\": \"$newURL\"}" http://ki.tc/ || exit 1)
returnedURL=$(echo $response | grep -Eo "http://ki.tc/[0-9a-zA-Z]*" | tail -n 1)
}
printResults()
@ -165,7 +166,7 @@ printShortenedResults()
{
cat <<EOF
=====================================================================
Original URL: $inputURL
Original URL: $newURL
Shortened URL: $returnedURL
=====================================================================
EOF
@ -185,7 +186,6 @@ while getopts "e:s:uvh" opt; do
inputURL=$OPTARG
;;
s)
echo "The shorten feature not been implemented yet." && exit 0
shorten="true"
inputURL=$OPTARG
;;