diff --git a/CHANGES.txt b/CHANGES.txt deleted file mode 100644 index 62585a3..0000000 --- a/CHANGES.txt +++ /dev/null @@ -1,4 +0,0 @@ -0.5.1: first published version. -0.5.2: refactored code and tests. -0.5.3: change github repo for beta -0.8.0: migration to github, added docker images for testing diff --git a/MANIFEST.in b/MANIFEST.in index e4e583a..dfaf6c1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ -include README.md CHANGES.txt LICENSE.txt +include README.md LICENSE.txt exclude MANIFEST.in diff --git a/docker/run_python.sh b/docker/run_python.sh index 6ad7095..39096ce 100644 --- a/docker/run_python.sh +++ b/docker/run_python.sh @@ -1,8 +1,12 @@ #!/bin/bash +retcode=0 +ping_url="https://api.rosette.com/rest/v1" + +#------------------ Functions ---------------------------------------------------- #Gets called when the user doesn't provide any args function HELP { - echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]" + echo -e "\nusage: --key API_KEY [--FILENAME filename] [--url ALT_URL]" echo " API_KEY - Rosette API key (required)" echo " FILENAME - Python source file (optional)" echo " ALT_URL - Alternate service URL (optional)" @@ -12,6 +16,58 @@ function HELP { exit 1 } +#Checks if Rosette API key is valid +function checkAPI { + match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden") + if [ ! -z $match ]; then + echo -e "\nInvalid Rosette API Key" + exit 1 + fi +} + +function cleanURL() { + # strip the trailing slash off of the alt_url if necessary + if [ ! -z "${ALT_URL}" ]; then + case ${ALT_URL} in + */) ALT_URL=${ALT_URL::-1} + echo "Slash detected" + ;; + esac + ping_url=${ALT_URL} + fi +} + +function validateURL() { + match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "Rosette API") + if [ "${match}" = "" ]; then + echo -e "\n${ping_url} server not responding\n" + exit 1 + fi +} + +function runExample() { + echo -e "\n---------- ${1} start -------------" + result="" + if [ -z ${ALT_URL} ]; then + result="$(python ${1} --key ${API_KEY} 2>&1 )" + else + result="$(python ${1} --key ${API_KEY} --url ${ALT_URL} 2>&1 )" + fi + echo "${result}" + echo -e "\n---------- ${1} end -------------" + if [[ "${result}" == *"Exception"* ]]; then + echo "Exception found" + retcode=1 + elif [[ "$result" == *"processingFailure"* ]]; then + retcode=1 + elif [[ "$result" == *"AttributeError"* ]]; then + retcode=1 + elif [[ "$result" == *"ImportError"* ]]; then + retcode=1 + fi +} +#------------------ Functions End ------------------------------------------------ + #Gets API_KEY, FILENAME and ALT_URL if present while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do case "${arg}" in @@ -37,33 +93,11 @@ while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do ;; esac done -ping_url="https://api.rosette.com/rest/v1" -# strip the trailing slash off of the alt_url if necessary -if [ ! -z "${ALT_URL}" ]; then - case ${ALT_URL} in - */) ALT_URL=${ALT_URL::-1} - echo "Slash detected" - ;; - esac - ping_url=${ALT_URL} -fi +cleanURL -#Checks for valid url -match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "Rosette API") -if [ "${match}" = "" ]; then - echo -e "\n${ping_url} server not responding\n" - exit 1 -fi +validateURL -#Checks if Rosette API key is valid -function checkAPI { - match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-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 -r -n /source/* . @@ -75,15 +109,11 @@ if [ ! -z ${API_KEY} ]; then python /python-dev/setup.py install cd /python-dev/examples if [ ! -z ${FILENAME} ]; then - if [ ! -z ${ALT_URL} ]; then - python ${FILENAME} --key ${API_KEY} --url ${ALT_URL} - else - python ${FILENAME} --key ${API_KEY} - fi + runExample ${FILENAME} elif [ ! -z ${ALT_URL} ]; then - find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} --url ${ALT_URL} \; - else - find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} \; + for file in *.py; do + runExample ${file} + done fi else HELP @@ -109,3 +139,5 @@ if [ ! -z ${GIT_USERNAME} ] && [ ! -z ${VERSION} ]; then git commit -a -m "publish python apidocs ${VERSION}" git push fi + +exit ${retcode} diff --git a/examples/docker/run_python.sh b/examples/docker/run_python.sh index ca33f6d..503443d 100644 --- a/examples/docker/run_python.sh +++ b/examples/docker/run_python.sh @@ -1,5 +1,10 @@ #!/bin/bash +retcode=0 +ping_url="https://api.rosette.com/rest/v1" + +#------------------ Functions ---------------------------------------------------- + #Gets called when the user doesn't provide any args function HELP { echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]" @@ -10,6 +15,59 @@ function HELP { exit 1 } +#Checks if Rosette API key is valid +function checkAPI() { + match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden") + if [ ! -z $match ]; then + echo -e "\nInvalid Rosette API Key" + exit 1 + fi +} + +function cleanURL() { + # strip the trailing slash off of the alt_url if necessary + if [ ! -z "${ALT_URL}" ]; then + case ${ALT_URL} in + */) ALT_URL=${ALT_URL::-1} + echo "Slash detected" + ;; + esac + ping_url=${ALT_URL} + fi +} + +function validateURL() { + match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" -H "user_key: ${API_KEY}" | grep -o "Rosette API") + if [ "${match}" = "" ]; then + echo -e "\n${ping_url} server not responding\n" + exit 1 + fi +} + +function runExample() { + echo -e "\n---------- ${1} start -------------" + result="" + if [ -z ${ALT_URL} ]; then + result="$(python ${1} --key ${API_KEY} 2>&1 )" + else + result="$(python ${1} --key ${API_KEY} --url ${ALT_URL} 2>&1 )" + fi + echo "${result}" + echo -e "\n---------- ${1} end -------------" + if [[ "${result}" == *"Exception"* ]]; then + echo "Exception found" + retcode=1 + elif [[ "$result" == *"processingFailure"* ]]; then + retcode=1 + elif [[ "$result" == *"AttributeError"* ]]; then + retcode=1 + elif [[ "$result" == *"ImportError"* ]]; then + retcode=1 + fi +} + +#------------------ Functions End ------------------------------------------------ + #Gets API_KEY, FILENAME and ALT_URL if present while getopts ":API_KEY:FILENAME:ALT_URL" arg; do case "${arg}" in @@ -27,33 +85,10 @@ while getopts ":API_KEY:FILENAME:ALT_URL" arg; do ;; esac done -ping_url="https://api.rosette.com/rest/v1" - -# strip the trailing slash off of the alt_url if necessary -if [ ! -z "${ALT_URL}" ]; then - case ${ALT_URL} in - */) ALT_URL=${ALT_URL::-1} - echo "Slash detected" - ;; - esac - ping_url=${ALT_URL} -fi -#Checks for valid url -match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "Rosette API") -if [ "${match}" = "" ]; then - echo -e "\n${ping_url} server not responding\n" - exit 1 -fi +cleanURL -#Checks if Rosette API key is valid -function checkAPI { - match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden") - if [ ! -z $match ]; then - echo -e "\nInvalid Rosette API Key" - exit 1 - fi -} +validateURL #Copy the examples from the mounted content in /source to current WORKDIR cp /source/examples/*.* . @@ -62,16 +97,14 @@ cp /source/examples/*.* . if [ ! -z ${API_KEY} ]; then checkAPI if [ ! -z ${FILENAME} ]; then - if [ ! -z ${ALT_URL} ]; then - python ${FILENAME} --key ${API_KEY} --url ${ALT_URL} - else - python ${FILENAME} --key ${API_KEY} - fi - elif [ ! -z ${ALT_URL} ]; then - find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} --url ${ALT_URL} \; + runExample ${FILENAME} else - find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} \; - fi + for file in *.py; do + runExample ${file} + done + fi else HELP fi + +exit ${retcode} diff --git a/examples/name_translation.py b/examples/name_translation.py index 020c571..c6704e4 100644 --- a/examples/name_translation.py +++ b/examples/name_translation.py @@ -21,7 +21,6 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'): params["entityType"] = "PERSON" params["targetLanguage"] = "eng" params["targetScript"] = "Latn" - params["targetScheme"] = "IC" return api.name_translation(params) diff --git a/rosette/__init__.py b/rosette/__init__.py index 1011a2a..9971311 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -16,4 +16,4 @@ limitations under the License. """ -__version__ = '0.8.0' +__version__ = '1.0' diff --git a/rosette/api.py b/rosette/api.py index 0571e49..112e82b 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -29,7 +29,7 @@ from datetime import datetime import requests -_BINDING_VERSION = "0.10" +_BINDING_VERSION = "1.0" _GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08]) N_RETRIES = 3 HTTP_CONNECTION = None diff --git a/setup.py b/setup.py index eccd1f9..597ef17 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def read(*filenames, **kwargs): buf.append(f.read()) return sep.join(buf) -long_description = read('README.md', 'CHANGES.txt') +long_description = read('README.md') setup(name=NAME, author=AUTHOR,