Skip to content

Instantly share code, notes, and snippets.

@zaydek-old
Last active March 8, 2017 17:08
Show Gist options
  • Save zaydek-old/2f6044a9a28c5675f221241f7b018127 to your computer and use it in GitHub Desktop.
Save zaydek-old/2f6044a9a28c5675f221241f7b018127 to your computer and use it in GitHub Desktop.
#!/bin/bash
function robinhood
{
echo
echo " >_ robinhood:function"
echo " >_ robinhood:function:usage"
echo
}
function robinhood:usage
{
echo
echo " >_ robinhood:login"
echo " >_ robinhood:logout"
echo
}
function robinhood:connx
{
sleep 1 && printf "."
}
function robinhood:login:usage
{
echo
echo " >_ robinhood:login username:'username' password:'password'"
echo " ^ ^"
}
function robinhood:login
{
# robinhood:login:usage
if [ $# != 2 ] || [ ${1:0:9} != "username:" ] || [ ${2:0:9} != "password:" ]
then
robinhood:login:usage
return
fi
robinhood_token=$(curl -s https://api.robinhood.com/api-token-auth/ -d "username=${1:9}&password=${2:9}")
# robinhood:connx
if [ $? != 0 ]
then
robinhood:connx robinhood.login $@
return
# robinhood:login:usage
elif [ "${robinhood_token:2:5}" != "token" ]
then
robinhood:login:usage
return
fi
robinhood_token=${robinhood_token:10:40}
echo
echo " >_ token:'$robinhood_token'"
echo
}
function robinhood:logout:usage
{
echo
echo " >_ robinhood:logout:usage"
echo
}
function robinhood:logout
{
# robinhood:logout:usage
if [ $# != 0 ]
then
robinhood:logout:usage
return
fi
robinhood_token=$(curl -s https://api.robinhood.com/api-token-logout/ -H "Authorization: Token $robinhood_token" -d "")
# robinhood:connx
if [ $? != 0 ]
then
robinhood:connx robinhood:logout
return
# robinhood:logout:usage
elif [ "$robinhood_token" != "" ]
then
robinhood:login:usage
return
fi
echo
echo " >_ token:"
echo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment