fix using default answer on install (#175)

* fix using default answer on install

* fix shortening and expanding URLs, simplifying

Replace "ki.tc" with more stable and actually working "tinyurl.com" for shortening.
Add separate service for expanding any shortened link.
Simplifying the code.
This commit is contained in:
Yaroslav Surilov 2018-09-29 20:38:09 +03:00 committed by Alex Epstein
parent b270518de8
commit cddc232e7b
3 changed files with 12 additions and 9 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
# IDE
.idea
# Meta files
.DS_Store
Thumbs.db

View File

@ -9,8 +9,9 @@ prefix="/usr/local"
askInstall()
{
echo -n "Do you wish to install $1 [Y/n]: "
read -r answer
read -p "Do you wish to install $1 [Y/n]: " answer
answer=${answer:-Y}
if [[ "$answer" == [Yy] ]]; then
cd $1 || return 1
echo -n "Installing $1: "

View File

@ -136,22 +136,21 @@ expandURL()
else
url=$1
fi
response=$(httpGet http://ki.tc/short?url=$url)
errorCheck=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['/short']['message']" 2> /dev/null )
if [[ $errorCheck == "Error in /short" ]]; then
response=$(httpGet https://unshorten.me/s/$url)
errorCheck=$(echo $response)
if [[ $errorCheck == "Invalid Short URL" ]]; then
echo "Error: 404 could not find the website"
return 1
fi
returnedURL=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['/short']['destination']" 2> /dev/null )
returnedURL=$(echo $response)
}
shortenURL()
{
newURL=$1
if [[ $(echo $1 | grep -Eo "^[h]ttp[s]?://") == "" ]]; 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)
response=$(httpGet http://tinyurl.com/api-create.php?url=$newURL)
returnedURL=$(echo $response)
}
printResults()