Skip to content

Commit

Permalink
Merge pull request #4 from fhasanaj/RCB_265
Browse files Browse the repository at this point in the history
The shell script now checks if the Rosette API key is valid before ru…
  • Loading branch information
cp2boston committed Feb 5, 2016
2 parents bc59f78 + dc86793 commit 5c66614
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions examples/docker/run_ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#Gets called when the user doesn't provide any args
function HELP {
echo -e "\nusage: source_file.rb API_KEY [ALT_URL]"
echo -e "\nusage: source_file.rb API_KEY [ALT_URL]"
echo " API_KEY - Rosette API key (required)"
echo " FILENAME - Ruby source file (optional)"
echo " ALT_URL - Alternate service URL (optional)"
Expand All @@ -27,25 +27,33 @@ while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
esac
done

# reference the API
curl "https://api.rosette.com/rest/v1/ping" -H "user_key: $1"
#Checks if Rosette API key is valid
function checkAPI {
match=$(curl "https://api.rosette.com/rest/v1/ping" -H "user_key: ${API_KEY}" | grep -o "forbidden")
if [ ! -z $match ]; then
echo -e "\nInvalid Rosette API Key"
exit 1
fi
}


#Copy the mounted content in /source to current WORKDIR
cp /source/*.* .

#Run the examples
if [ ! -z ${API_KEY} ]; then
if [ ! -z ${FILENAME} ]; then
if [ ! -z ${ALT_URL} ]; then
ruby ${FILENAME} ${API_KEY} ${ALT_URL}
else
ruby ${FILENAME} ${API_KEY}
fi
elif [ ! -z ${ALT_URL} ]; then
find -maxdepth 1 -name '*.rb' -print -exec ruby {} ${API_KEY} ${ALT_URL} \;
checkAPI
if [ ! -z ${FILENAME} ]; then
if [ ! -z ${ALT_URL} ]; then
ruby ${FILENAME} ${API_KEY} ${ALT_URL}
else
find -maxdepth 1 -name '*.rb' -print -exec ruby {} ${API_KEY} \;
ruby ${FILENAME} ${API_KEY}
fi
elif [ ! -z ${ALT_URL} ]; then
find -maxdepth 1 -name '*.rb' -print -exec ruby {} ${API_KEY} ${ALT_URL} \;
else
find -maxdepth 1 -name '*.rb' -print -exec ruby {} ${API_KEY} \;
fi
else
HELP
fi
HELP
fi

0 comments on commit 5c66614

Please sign in to comment.