Implemented the shorten URL
This commit is contained in:
parent
d8a7d8bb09
commit
bc07222cd0
10
short/short
10
short/short
|
@ -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
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue