Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 55fccc497f8b65f23f11e3ac1ef90c4c612fc71f 0 parents
Shawn Smith shawnps authored
Showing with 2,304 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +19 −0 .travis.yml
  3. +18 −0 LICENSE.txt
  4. +3 −0  MANIFEST.in
  5. +72 −0 README.md
  6. +46 −0 examples/deleteTranslationJob.py
  7. +76 −0 examples/determineTranslationCost.py
  8. +47 −0 examples/getAccountBalance.py
  9. +46 −0 examples/getAccountStats.py
  10. +48 −0 examples/getServiceLanguagePairs.py
  11. +46 −0 examples/getServiceLanguages.py
  12. +47 −0 examples/getTranslationJob.py
  13. +47 −0 examples/getTranslationJobBatch.py
  14. +48 −0 examples/getTranslationJobComments.py
  15. +47 −0 examples/getTranslationJobFeedback.py
  16. +47 −0 examples/getTranslationJobGroup.py
  17. +47 −0 examples/getTranslationJobPreviewImage.py
  18. +47 −0 examples/getTranslationJobRevision.py
  19. +46 −0 examples/getTranslationJobRevisions.py
  20. +47 −0 examples/getTranslationJobs.py
  21. +58 −0 examples/postTranslationJob.py
  22. +49 −0 examples/postTranslationJobComment.py
  23. +81 −0 examples/postTranslationJobs.py
  24. +1 −0  examples/testfiles/test_file1.txt
  25. +1 −0  examples/testfiles/test_file2.txt
  26. +43 −0 examples/unicode2utf8.py
  27. +53 −0 examples/updateTranslationJob.py
  28. +36 −0 gengo/__init__.py
  29. +343 −0 gengo/gengo.py
  30. +177 −0 gengo/mockdb.py
  31. +510 −0 gengo/tests.py
  32. +2 −0  requirements.txt
  33. +100 −0 setup.py
6 .gitignore
@@ -0,0 +1,6 @@
+*.pyc
+build
+dist
+*.swp
+gengo.egg-info
+gengo/test_keys.py
19 .travis.yml
@@ -0,0 +1,19 @@
+language: python
+python:
+ - "2.6"
+ - "2.7"
+
+env:
+ global:
+ - secure: "d416hNc96tFt33zvBi/pb2Y+0fsjknNuaYFjTmZ27muYRQRo90aL8n7weLaM\nK8WMtR0+BxFCKaIpaTWleXRzAUHvpmfV1Ofp9ZQ3OBSKryIhm64rd5EGJNvX\njEnYfINlGRdjXMAdaBvQIjKuJdqMB1Z83N3Ci9P3a/nN4NB2oOg="
+ - GENGO_PUBKEY='pubkeyfortests'
+
+# command to install dependencies
+install: "pip install -r requirements.txt --use-mirrors"
+# command to run pep8
+before_script: python setup.py pep8
+# command to run tests
+script: python gengo/tests.py
+
+notifications:
+ irc: "irc.freenode.net#Gengo"
18 LICENSE.txt
@@ -0,0 +1,18 @@
+All code provided from the http://gengo.com site, such as API example code and libraries, is provided under the New BSD license unless otherwise noted. Details are below.
+
+New BSD License
+Copyright (c) 2009-2012, myGengo, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+Neither the name of myGengo, Inc. nor the names of its contributors may
+be used to endorse or promote products derived from this software
+without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3  MANIFEST.in
@@ -0,0 +1,3 @@
+include LICENSE.txt README.md
+recursive-include *
+recursive-exclude *.pyc test_keys.py
72 README.md
@@ -0,0 +1,72 @@
+[![Build Status](https://secure.travis-ci.org/myGengo/mygengo-python.png)](http://travis-ci.org/myGengo/mygengo-python)
+
+Gengo Python Library (for the [Gengo API](http://gengo.com/))
+========================================================================================================
+Translating your tools and products helps people all over the world access them; this is, of course, a
+somewhat tricky problem to solve. **[Gengo](http://gengo.com/)** is a service that offers human-translation
+(which is often a higher quality than machine translation), and an API to manage sending in work and watching
+jobs. This is a Python interface to make using the API simpler.
+
+Installation & Requirements
+-------------------------------------------------------------------------------------------------------
+Installing the library is fairly simple:
+
+Get the repo:
+
+ git clone git://github.com/myGengo/mygengo-python.git
+
+And then install the library:
+
+ sudo python setup.py install
+
+This will also install the `requests` package. If you're running on a version of Python prior to 2.6, you'll need to install simplejson as well:
+
+ sudo pip install simplejson
+
+
+Tests - Running Them, etc
+------------------------------------------------------------------------------------------------------
+Gengo has a full suite of unit tests. To run them, export your public and private keys in the shell like so:
+
+```shell
+export GENGO_PUBKEY='your public key here'
+export GENGO_PRIVKEY='your private key here'
+```
+
+Then grab the source, head into the gengo directory, and execute the tests file like so:
+
+ python tests.py
+
+Note that some of the tests rely on some deferred actions so there are timeouts (sleep) which you might have to adjust.
+
+Question, Comments, Complaints, Praise?
+------------------------------------------------------------------------------------------------------
+If you have questions or comments and would like to reach us directly, please feel free to do
+so at the following outlets. We love hearing from developers!
+
+Email: api [at] gengo dot com
+Twitter: **[@gengoit](https://twitter.com/gengoit)**
+
+If you come across any issues, please file them on the **[Github project issue tracker](https://github.com/myGengo/mygengo-python/issues)**. Thanks!
+
+
+Documentation
+-----------------------------------------------------------------------------------------------------
+Full documentation can be found **[here](http://developers.gengo.com)**, but anyone should be able to
+get a working script with the following:
+
+``` python
+from gengo import Gengo
+
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+print gengo.getAccountBalance()
+```
+
+All function definitions can be found inside gengo/mockdb.py as a dictionary: the
+key of the dictionary entry is the function name, and the parameters are exactly the same as specified
+over on the **[Gengo API docs](http://developers.gengo.com)**.
46 examples/deleteTranslationJob.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Delete a job!
+gengo.deleteTranslationJob(id=42)
76 examples/determineTranslationCost.py
@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Exhaustive view, chances are your code will never be quite this verbose (programatically build this).
+jobs_data = {
+ 'job_1': {
+ 'type': 'text', # REQUIRED. Type to translate, you'll probably always put 'text' here. ;P
+ 'slug': 'Single :: English to Japanese', # REQUIRED. Slug for internally storing, can be generic.
+ 'body_src': 'Testing Gengo API library calls.', # REQUIRED. The text you're translating. ;P
+ 'lc_src': 'en', # REQUIRED. source_language_code (see getServiceLanguages() for a list of codes)
+ 'lc_tgt': 'ja', # REQUIRED. target_language_code (see getServiceLanguages() for a list of codes)
+ 'tier': 'standard', # REQUIRED. tier type ("machine", "standard", "pro", or "ultra")
+
+ 'auto_approve': 0, # OPTIONAL. Hopefully self explanatory (1 = yes, 0 = no),
+ 'comment': 'HEY THERE TRANSLATOR', # OPTIONAL. Comment to leave for translator.
+ 'callback_url': 'http://...', # OPTIONAL. Callback URL that updates are sent to.
+ 'custom_data': 'your optional custom data, limited to 1kb.' # OPTIONAL
+ },
+ 'job_2': {
+ 'type': 'text', # REQUIRED. Type to translate, you'll probably always put 'text' here. ;P
+ 'slug': 'Single :: English to Japanese', # REQUIRED. Slug for internally storing, can be generic.
+ 'body_src': 'Testing Gengo API library calls.', # REQUIRED. The text you're translating. ;P
+ 'lc_src': 'en', # REQUIRED. source_language_code (see getServiceLanguages() for a list of codes)
+ 'lc_tgt': 'ja', # REQUIRED. target_language_code (see getServiceLanguages() for a list of codes)
+ 'tier': 'standard', # REQUIRED. tier type ("machine", "standard", "pro", or "ultra")
+
+ 'auto_approve': 0, # OPTIONAL. Hopefully self explanatory (1 = yes, 0 = no),
+ 'comment': 'HEY THERE TRANSLATOR', # OPTIONAL. Comment to leave for translator.
+ 'callback_url': 'http://...', # OPTIONAL. Callback URL that updates are sent to.
+ 'custom_data': 'your optional custom data, limited to 1kb.' # OPTIONAL
+ },
+}
+
+# Post over our two jobs, use the same translator for both, don't pay for them
+gengo.determineTranslationCost(jobs=jobs_data)
47 examples/getAccountBalance.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=False,
+ debug=True
+)
+
+# Retrieve and print the account balance.
+print gengo.getAccountBalance()
46 examples/getAccountStats.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=False,
+)
+
+# Print the account stats...
+print gengo.getAccountStats()
48 examples/getServiceLanguagePairs.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=False,
+ debug=True
+)
+# Useful for figuring out what language paths are supported - e.g, if
+# we use 'en' below, we'll see what languages we can translate TO from 'en'.
+print gengo.getServiceLanguagePairs(lc_src='en')
46 examples/getServiceLanguages.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+from pprint import pprint
+
+gengo = Gengo(
+ public_key='your public key',
+ private_key='your private key',
+ sandbox=False,
+)
+
+# Pretty-print a list of every supported language
+pprint(gengo.getServiceLanguages())
47 examples/getTranslationJob.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Get the job in question; pre_mt set to 1 will give you a machine translation
+# if the human translation isn't available yet. ;)
+gengo.getTranslationJob(id=42, pre_mt=1)
47 examples/getTranslationJobBatch.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# If you have one job id, but want to get the id of every other job that
+# was submitted with it, you can do this.
+print gengo.getTranslationJobBatch(id=42)
48 examples/getTranslationJobComments.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Get all the comments on a specific job.
+# Note that this returns a data set, so while we just print it below, you'll
+# inevitably want to iterate over it and such.
+print gengo.getTranslationJobComments(id=42)
47 examples/getTranslationJobFeedback.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Very much like grabbing a comment history. Returns a data set, iterate
+# if you want specifics!
+print gengo.getTranslationJobFeedback(id=42)
47 examples/getTranslationJobGroup.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+ debug=True
+)
+
+# Get the job group in question
+print gengo.getTranslationJobGroup(id=16973)
47 examples/getTranslationJobPreviewImage.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# This method is a bit tricky; you can call it like below, but how you treat
+# the returned data is very much up to you.
+gengo.getTranslationJobPreviewImage(id=42)
47 examples/getTranslationJobRevision.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Grab a specific revision - you could liken this to querying version control
+# on the Gengo side. :)
+print gengo.getTranslationJobRevision(id=42, revision_id=1)
46 examples/getTranslationJobRevisions.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Get every revision on a job. Returns a data set, iterate if need be!
+print gengo.getTranslationJobRevisions(id=42)
47 examples/getTranslationJobs.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Think of this as a "search my jobs" method, and it becomes very
+# self-explanatory.
+print gengo.getTranslationJobs(status="accepted", count=15)
58 examples/postTranslationJob.py
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Post over a job for translation.
+gengo.postTranslationJob(job={
+ 'type': 'text', # REQUIRED. Type to translate, you'll probably always put 'text' here. ;P
+ 'slug': 'Single :: English to Japanese', # REQUIRED. Slug for internally storing, can be generic.
+ 'body_src': 'Testing Gengo API library calls.', # REQUIRED. The text you're translating. ;P
+ 'lc_src': 'en', # REQUIRED. source_language_code (see getServiceLanguages() for a list of codes)
+ 'lc_tgt': 'ja', # REQUIRED. target_language_code (see getServiceLanguages() for a list of codes)
+ 'tier': 'standard', # REQUIRED. tier type ("machine", "standard", "pro", or "ultra")
+
+ 'auto_approve': 0, # OPTIONAL. Hopefully self explanatory (1 = yes, 0 = no),
+ 'comment': 'HEY THERE TRANSLATOR', # OPTIONAL. Comment to leave for translator.
+ 'callback_url': 'http://...', # OPTIONAL. Callback URL that updates are sent to.
+ 'custom_data': 'your optional custom data, limited to 1kb.' # OPTIONAL
+})
49 examples/postTranslationJobComment.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Post a comment on a specific job; perhaps you have an update for the
+# translator or something of the sort.
+gengo.postTranslationJobComment(id=42, comment={
+ 'body': 'I love lamp!',
+})
81 examples/postTranslationJobs.py
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# This is an exhaustive view of this object; chances are your code will never
+# have to be this verbose because you'd want to build it up programmatically.
+data = {
+ 'jobs': {
+ 'job_1': {
+ 'type': 'text', # REQUIRED. Type to translate, you'll probably always put 'text' here. ;P
+ 'slug': 'Single :: English to Japanese', # REQUIRED. Slug for internally storing, can be generic.
+ 'body_src': 'Testing Gengo API library calls.', # REQUIRED. The text you're translating. ;P
+ 'lc_src': 'en', # REQUIRED. source_language_code (see getServiceLanguages() for a list of codes)
+ 'lc_tgt': 'ja', # REQUIRED. target_language_code (see getServiceLanguages() for a list of codes)
+ 'tier': 'standard', # REQUIRED. tier type ("machine", "standard", "pro", or "ultra")
+
+ 'auto_approve': 0, # OPTIONAL. Hopefully self explanatory (1 = yes, 0 = no),
+ 'comment': 'HEY THERE TRANSLATOR', # OPTIONAL. Comment to leave for translator.
+ 'callback_url': 'http://...', # OPTIONAL. Callback URL that updates are sent to.
+ 'custom_data': 'your optional custom data, limited to 1kb.' # OPTIONAL
+ },
+ 'job_2': {
+ 'type': 'text', # REQUIRED. Type to translate, you'll probably always put 'text' here. ;P
+ 'slug': 'Single :: English to Japanese', # REQUIRED. Slug for internally storing, can be generic.
+ 'body_src': 'Testing Gengo API library calls.', # REQUIRED. The text you're translating. ;P
+ 'lc_src': 'en', # REQUIRED. source_language_code (see getServiceLanguages() for a list of codes)
+ 'lc_tgt': 'ja', # REQUIRED. target_language_code (see getServiceLanguages() for a list of codes)
+ 'tier': 'standard', # REQUIRED. tier type ("machine", "standard", "pro", or "ultra")
+
+ 'auto_approve': 0, # OPTIONAL. Hopefully self explanatory (1 = yes, 0 = no),
+ 'comment': 'HEY THERE TRANSLATOR', # OPTIONAL. Comment to leave for translator.
+ 'callback_url': 'http://...', # OPTIONAL. Callback URL that updates are sent to.
+ 'custom_data': 'your optional custom data, limited to 1kb.' # OPTIONAL
+ },
+ },
+ 'process': 1, # OPTIONAL. 1 (true, default) / 0 (false). Whether to pay for the job(s) and make them available for translation.
+ 'as_group': 1, # OPTIONAL. 1 (true) / 0 (false, default). Whether all jobs in this group should be done by one translator.
+}
+
+# And now we post them over...
+gengo.postTranslationJobs(jobs=data)
1  examples/testfiles/test_file1.txt
@@ -0,0 +1 @@
+This is a first test text from a file.
1  examples/testfiles/test_file2.txt
@@ -0,0 +1 @@
+This is a second text.
43 examples/unicode2utf8.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# This method doesn't require an instance of Gengo, it's
+# purely utility. You'll possibly end up using it to ensure
+# that your data is utf-8 encoded before submitting it to Gengo;
+# if your method calls fail, this is probably the first thing you should
+# check!
+Gengo.unicode2utf8("私は")
53 examples/updateTranslationJob.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo
+
+# Get an instance of Gengo to work with...
+gengo = Gengo(
+ public_key='your_public_key',
+ private_key='your_private_key',
+ sandbox=True,
+)
+
+# Update a job that has an id of 42, and reject it, cite the reason,
+# add a comment, and throw up some captcha stuff. See the docs for
+# more information pertaining to this method, it can do quite a bit. :)
+gengo.updateTranslationJob(id=42, action={
+ 'action': 'reject',
+ 'reason': 'quality',
+ 'comment': 'My grandmother does better.',
+ 'captcha': 'bert'
+})
36 gengo/__init__.py
@@ -0,0 +1,36 @@
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from gengo import Gengo, GengoError, GengoAuthError
+
+__all__ = ['Gengo', 'GengoError', 'GengoAuthError']
343 gengo/gengo.py
@@ -0,0 +1,343 @@
+#!/usr/bin/python
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""
+Official Python library for interfacing with the Gengo API.
+"""
+
+__author__ = 'Shawn Smith <shawn.smith@gengo.com>'
+__version__ = '1.3.4'
+
+import re
+import hmac
+import requests
+
+from hashlib import sha1
+from urllib import urlencode, quote
+from time import time
+from operator import itemgetter
+from string import lower
+
+# mockdb is a file with a dictionary of every API endpoint for Gengo.
+from mockdb import api_urls, apihash
+
+# There are some special setups (like a Django application) where
+# simplejson exists. Past Python 2.6, this should never
+# cause any problems.
+try:
+ # Python 2.6 and up
+ import json
+ json # silence pyflakes
+except ImportError:
+ try:
+ # Python 2.6 and below (2.4/2.5, 2.3 is not guranteed to work with
+ # this library to begin with)
+ import simplejson as json
+ json # silence pyflakes
+ except ImportError:
+ try:
+ # This case gets rarer by the day, but if we need to, we can
+ # pull it from Django provided it's there.
+ from django.utils import simplejson as json
+ json # silence pyflakes
+ except:
+ raise Exception("gengo requires the simplejson library (or " +
+ "Python 2.6+) to work. " +
+ "http://www.undefined.org/python/")
+
+
+class GengoError(Exception):
+ """
+ Generic error class, catch-all for most Gengo issues.
+ Special cases are handled by APILimit and AuthError.
+
+ Note: You need to explicitly import them into your code, e.g:
+
+ from gengo import GengoError, GengoAuthError
+ """
+ def __init__(self, msg, error_code=None):
+ self.msg = msg
+ if error_code == 1000:
+ # Auth errors tend to be the most requested for their own
+ # Exception instances, so give it to the masses, yo.
+ raise GengoAuthError(msg)
+
+ def __str__(self):
+ return repr(self.msg)
+
+
+class GengoAuthError(GengoError):
+ """
+ Raised when you try to access a protected resource and it fails due
+ to some issue with your authentication.
+ """
+ def __init__(self, msg):
+ self.msg = msg
+
+ def __str__(self):
+ return repr(self.msg)
+
+
+class Gengo(object):
+ def __init__(self, public_key=None, private_key=None, sandbox=False,
+ api_version='2', headers=None, debug=False):
+ """
+ Gengo(public_key = None, private_key = None, sandbox = False,
+ headers = None)
+
+ Instantiates an instance of Gengo.
+
+ Parameters:
+ public_key - Your 'public' key for Gengo. Retrieve this from your
+ account information if you want to do authenticated calls.
+ private_key - Your 'private' key for Gengo. Retrieve this from your
+ account information if you want to do authenticated calls.
+ sandbox - Whether to use the Gengo sandbox.
+ api_version - version 2 and 1.1 are supported. defaults to 2
+ headers - User agent header, dictionary style ala {'User-Agent':
+ 'Bert'}
+ debug - a flag (True/False) which will cause the library to print
+ useful debugging info.
+ """
+ self.api_url = \
+ api_urls['sandbox'] if sandbox is True else api_urls['base']
+ self.api_version = str(api_version)
+ if self.api_version not in ('1.1', '2'):
+ raise Exception("gengo-python library only supports " +
+ " versions 1.1 and 2 at the moment, please " +
+ " keep api_version to 1.1 or 2")
+ self.public_key = public_key
+ self.private_key = private_key
+ self.headers = headers
+ if self.headers is None:
+ self.headers = \
+ {'User-agent': 'Gengo Python Library;' +
+ 'Version %s; http://gengo.com/' % __version__}
+ self.headers['Accept'] = 'application/json'
+ self.debug = debug
+
+ def __getattr__(self, api_call):
+ """
+ The most magically awesome block of code you'll ever see.
+
+ Rather than list out 9 million methods for this API, we just
+ keep a table (see above) of every API endpoint and their
+ corresponding function id for this library. This pretty much
+ gives unlimited flexibility in API support - there's a slight
+ chance of a performance hit here, but if this is
+ going to be your bottleneck... well, don't use Python. ;P
+
+ For those who don't get what's going on here, Python classes
+ have this great feature known as __getattr__().
+ It's called when an attribute that was called on an object
+ doesn't seem to exist - since it doesn't exist,
+ we can take over and find the API method in our table. We then
+ return a function that downloads and parses
+ what we're looking for, based on the key/values passed in.
+
+ I'll hate myself for saying this, but this is heavily inspired
+ by Ruby's "method_missing".
+
+ Note: I'm largely borrowing this technique from another API
+ library/wrapper I've written in the past (Twython).
+ If you happen to read both sources and find the same text...
+ well, that's why. ;)
+ """
+ def get(self, **kwargs):
+ # Grab the (hopefully) existing method 'definition' to fire off
+ # from our api hash table.
+ fn = apihash[api_call]
+
+ # Do a check here for specific job sets - we need to support
+ # posting multiple jobs
+ # at once, so see if there's an dictionary of jobs passed in,
+ # pop it out, let things go on as normal,
+ # then pick this chain back up below...
+ post_data = {}
+ if 'job' in kwargs:
+ post_data['job'] = {'job': kwargs.pop('job')}
+ if 'jobs' in kwargs:
+ post_data['jobs'] = kwargs.pop('jobs')
+ if 'comment' in kwargs:
+ post_data['comment'] = kwargs.pop('comment')
+ if 'action' in kwargs:
+ post_data['action'] = kwargs.pop('action')
+ if 'job_ids' in kwargs:
+ post_data['job_ids'] = kwargs.pop('job_ids')
+
+ # Set up a true base URL, abstracting away the need to care
+ # about the sandbox mode or API versioning at this stage.
+ base_url = self.api_url % {'version':
+ 'v%s' % self.api_version}
+
+ # Go through and replace any mustaches that are in our API url
+ # with their appropriate key/value pairs...
+ # NOTE: We pop() here because we don't want the extra data
+ # included and messing up our hash down the road.
+ base = re.sub(
+ '\{\{(?P<m>[a-zA-Z_]+)\}\}',
+ lambda m: "%s" % kwargs.pop(m.group(1),
+ # In case of debugging needs
+ 'no_argument_specified'),
+ base_url + fn['url']
+ )
+
+ # Build up a proper 'authenticated' url...
+ #
+ # Note: for further information on what's going on here, it's
+ # best to familiarize yourself with the Gengo authentication
+ # API. (http://gengo.com/services/api/dev-docs/authentication)
+ query_params = dict([k, quote(str(v).encode('utf-8'))] for k, v
+ in kwargs.items())
+ if self.public_key is not None:
+ query_params['api_key'] = self.public_key
+ query_params['ts'] = str(int(time()))
+
+ # check whether the endpoint supports file uploads and check the
+ # params for file_path and modify the query_params accordingly
+ # needs to be refactored to a more general handling once we
+ # also want to support ie glossary upload. for now it's tied to
+ # jobs payloads
+ if 'upload' in fn:
+ file_data = {}
+ for k, j in post_data['jobs']['jobs'].iteritems():
+ if j['type'] == 'file' and 'file_path' in j:
+ file_data['file_' + k] = open(j['file_path'], 'rb')
+ j['file_key'] = 'file_' + k
+ del j['file_path']
+ else:
+ file_data = False
+
+ # If any further APIs require their own special signing needs,
+ # fork here...
+ response = self.signAndRequestAPILatest(fn, base, query_params,
+ post_data, file_data)
+ results = response.json
+
+ # See if we got any errors back that we can cleanly raise on
+ if 'opstat' in results and results['opstat'] != 'ok':
+ # In cases of multiple errors, the keys for results['err']
+ # will be the job IDs.
+ if not 'msg' and 'code' in results['err']:
+ concatted_msg = ''
+ for job_key, msg_code_list in results['err'].iteritems():
+ concatted_msg += '<%s: %s> ' % \
+ (job_key, msg_code_list[0]['msg'])
+ raise GengoError(concatted_msg,
+ results['err'].itervalues().
+ next()[0]['code'])
+ raise GengoError(results['err']['msg'],
+ results['err']['code'])
+
+ # If not, return the results
+ return results
+
+ if api_call in apihash:
+ return get.__get__(self)
+ else:
+ raise AttributeError
+
+ def signAndRequestAPILatest(self, fn, base, query_params, post_data={},
+ file_data=False):
+ """
+ This method signs the request with just the timestamp and
+ private key, which is what api v1.1 and 2 rely on.
+
+ fn - object mapping from mockdb describing POST, etc.
+ base - Base URL to ping.
+ query_params - Dictionary of data eventually getting sent over
+ to Gengo.
+ post_data - Any extra special post data to get sent over.
+ """
+ # Encoding jobs becomes a bit different than any other method call,
+ # so we catch them and do a little
+ # JSON-dumping action. Catching them also allows us to provide some
+ # sense of portability between the various
+ # job-posting methods in that they can all safely rely on passing
+ # dictionaries around. Huzzah!
+ req_method = requests.__getattribute__(lower(fn['method']))
+ if fn['method'] == 'POST' or fn['method'] == 'PUT':
+ if 'job' in post_data:
+ query_params['data'] = json.dumps(post_data['job'],
+ separators=(',', ':'))
+ elif 'jobs' in post_data:
+ query_params['data'] = json.dumps(post_data['jobs'],
+ separators=(',', ':'))
+ elif 'comment' in post_data:
+ query_params['data'] = json.dumps(post_data['comment'],
+ separators=(',', ':'))
+ elif 'action' in post_data:
+ query_params['data'] = json.dumps(post_data['action'],
+ separators=(',', ':'))
+
+ query_hmac = hmac.new(self.private_key,
+ query_params['ts'],
+ sha1)
+ query_params['api_sig'] = query_hmac.hexdigest()
+
+ if self.debug is True:
+ print query_params
+
+ if not file_data:
+ return req_method(base,
+ headers=self.headers,
+ data=query_params)
+ else:
+ return req_method(base,
+ headers=self.headers,
+ files=file_data,
+ data=query_params)
+ else:
+ query_string = urlencode(sorted(query_params.items(),
+ key=itemgetter(0)))
+ if self.private_key is not None:
+ query_hmac = hmac.new(self.private_key,
+ query_params['ts'],
+ sha1)
+ query_params['api_sig'] = query_hmac.hexdigest()
+ query_string = urlencode(query_params)
+
+ if self.debug is True:
+ print base + '?%s' % query_string
+ return req_method(base + '?%s' % query_string,
+ headers=self.headers)
+
+ @staticmethod
+ def unicode2utf8(text):
+ try:
+ if isinstance(text, unicode):
+ text = text.encode('utf-8')
+ except:
+ pass
+ return text
177 gengo/mockdb.py
@@ -0,0 +1,177 @@
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""
+A huge map of every Gengo API endpoint to a function definition in gengo-
+python.
+
+Parameters that need to be embedded in the URL are treated with mustaches,
+e.g:
+
+{{bert}}, etc
+
+When creating new endpoint definitions, keep in mind that the name of the
+mustache will be replaced with the keyword that gets passed in to the
+function at call time.
+
+i.e, in this case, if I pass bert = 47 to any function, {{bert}} will be
+replaced with 47, instead of defaulting to 1 (said defaulting takes place
+at conversion time).
+"""
+
+# Gengo API urls. %(version)s gets replaced with v1/etc at run time.
+api_urls = {
+ 'sandbox': 'http://api.sandbox.mygengo.com/%(version)s',
+ 'base': 'http://api.gengo.com/%(version)s',
+}
+
+# The API endpoint 'table', 'database', 'hash', 'dictionary', whatever
+# you'd like to call it. To keep things uber nice and organized, we secure
+# away all the endpoints here with easily replaceable scenarios. Win!
+apihash = {
+ # All Account-information based methods...
+ 'getAccountStats': {
+ 'url': '/account/stats',
+ 'method': 'GET',
+ },
+ 'getAccountBalance': {
+ 'url': '/account/balance',
+ 'method': 'GET',
+ },
+
+ # Creating new translation requests.
+ 'postTranslationJob': {
+ 'url': '/translate/job',
+ 'method': 'POST',
+ },
+ 'postTranslationJobs': {
+ 'url': '/translate/jobs',
+ 'method': 'POST',
+ },
+
+ # Updating an existing translation request.
+ 'updateTranslationJob': {
+ 'url': '/translate/job/{{id}}',
+ 'method': 'PUT',
+ },
+
+ # Viewing existing translation requests.
+ 'getTranslationJob': {
+ 'url': '/translate/job/{{id}}',
+ 'method': 'GET',
+ },
+ 'getTranslationJobs': {
+ 'url': '/translate/jobs',
+ 'method': 'GET',
+ },
+ 'getTranslationJobBatch': {
+ 'url': '/translate/jobs/{{id}}',
+ 'method': 'GET',
+ },
+
+ 'getTranslationJobGroup': {
+ 'url': '/translate/jobs/group/{{id}}',
+ 'method': 'GET',
+ },
+
+ # Get a quote for how much a given job will cost.
+ 'determineTranslationCost': {
+ 'url': '/translate/service/quote',
+ 'method': 'POST',
+ 'upload': True, # with this being set the payload will be checked
+ # for file_path args and - if found - modified in a way so that
+ # opened file descriptors are passed to requests to do a multi part
+ # file upload. for now this is tied to jobs data only.
+ },
+
+ # Deal with comments and other metadata about a TranslationJob in
+ # progress.
+ 'postTranslationJobComment': {
+ 'url': '/translate/job/{{id}}/comment',
+ 'method': 'POST',
+ },
+ 'getTranslationJobComments': {
+ 'url': '/translate/job/{{id}}/comments',
+ 'method': 'GET',
+ },
+ 'getTranslationJobFeedback': {
+ 'url': '/translate/job/{{id}}/feedback',
+ 'method': 'GET',
+ },
+ 'getTranslationJobRevisions': {
+ 'url': '/translate/job/{{id}}/revisions',
+ 'method': 'GET',
+ },
+ 'getTranslationJobRevision': {
+ 'url': '/translate/job/{{id}}/revisions/{{revision_id}}',
+ 'method': 'GET',
+ },
+ 'getTranslationJobPreviewImage': {
+ 'url': '/translate/job/{{id}}/preview',
+ 'method': 'GET',
+ },
+
+ # Delete a job...
+ 'deleteTranslationJob': {
+ 'url': '/translate/job/{{id}}',
+ 'method': 'DELETE',
+ },
+
+ # Translation Service language information. Holds information
+ # about which languages can be converted to which, etc.
+ 'getServiceLanguagePairs': {
+ 'url': '/translate/service/language_pairs',
+ 'method': 'GET',
+ },
+ 'getServiceLanguages': {
+ 'url': '/translate/service/languages',
+ 'method': 'GET',
+ },
+
+ # glossary stuff
+ 'getGlossaryList': {
+ 'url': '/translate/glossary',
+ 'method': 'GET',
+ },
+
+ 'getGlossary': {
+ 'url': '/translate/glossary/{{id}}',
+ 'method': 'GET',
+ },
+
+ # order information
+ 'getTranslationOrderJobs': {
+ 'url': '/translate/order/{{id}}',
+ 'method': 'GET',
+ },
+}
510 gengo/tests.py
@@ -0,0 +1,510 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""
+A set of tests for the Gengo API. They all require an internet connection.
+"""
+
+import unittest
+import os
+import random
+import time
+
+from gengo import Gengo, GengoError, GengoAuthError
+
+API_PUBKEY = os.getenv('GENGO_PUBKEY')
+API_PRIVKEY = os.getenv('GENGO_PRIVKEY')
+
+
+class TestGengoCore(unittest.TestCase):
+ """
+ Handles testing the core parts of Gengo (i.e, authentication
+ signing, etc).
+ """
+ def test_MethodDoesNotExist(self):
+ gengo = Gengo(public_key=API_PUBKEY,
+ private_key=API_PRIVKEY)
+ # With how we do functions, AttributeError is a bit tricky to
+ # catch...
+ self.assertRaises(AttributeError, getattr, Gengo, 'bert')
+
+ def test_GengoAuthNoCredentials(self):
+ gengo = Gengo(public_key='',
+ private_key='')
+ self.assertRaises(GengoError, gengo.getAccountStats)
+
+ def test_GengoAuthBadCredentials(self):
+ gengo = Gengo(public_key='bert',
+ private_key='beeeerrrttttt')
+ self.assertRaises(GengoAuthError, gengo.getAccountStats)
+
+
+class TestAccountMethods(unittest.TestCase):
+ """
+ Tests the methods that deal with retrieving basic information about
+ the account you're authenticating as. Checks for one property on
+ each method.
+ """
+ def setUp(self):
+ self.gengo = Gengo(public_key=API_PUBKEY,
+ private_key=API_PRIVKEY)
+ self.gengo.api_url = 'http://api.staging.gengo.com/%(version)s'
+
+ def test_getAccountStats(self):
+ stats = self.gengo.getAccountStats()
+ self.assertEqual(stats['opstat'], 'ok')
+
+ def test_getAccountBalance(self):
+ balance = self.gengo.getAccountBalance()
+ self.assertEqual(balance['opstat'], 'ok')
+
+
+class TestLanguageServiceMethods(unittest.TestCase):
+ """
+ Tests the methods that deal with getting information about language-
+ translation service support from Gengo.
+ """
+ def setUp(self):
+ self.gengo = Gengo(public_key=API_PUBKEY,
+ private_key=API_PRIVKEY)
+ self.gengo.api_url = 'http://api.staging.gengo.com/%(version)s'
+
+ def test_getServiceLanguagePairs(self):
+ resp = self.gengo.getServiceLanguagePairs()
+ self.assertEqual(resp['opstat'], 'ok')
+
+ def test_getServiceLanguages(self):
+ resp = self.gengo.getServiceLanguages()
+ self.assertEqual(resp['opstat'], 'ok')
+
+
+class TestTranslationSingleJobFlow(unittest.TestCase):
+ """
+ Tests the flow of creating a job, adding a comment, getting the details,
+ and then deleting the job.
+ """
+ def setUp(self):
+ self.gengo = Gengo(public_key=API_PUBKEY,
+ private_key=API_PRIVKEY)
+ self.gengo.api_url = 'http://api.staging.gengo.com/%(version)s'
+ self.created_job_ids = []
+
+ single_job = {
+ 'type': 'text',
+ 'slug': 'Single :: English to Japanese',
+ 'body_src': 'Test%ding myGe%dngo A%dPI li%dbrary calls.' %
+ (int(random.randrange(1, 226, 1)),
+ int(random.randrange(1, 226, 1)),
+ int(random.randrange(1, 226, 1)),
+ int(random.randrange(1, 226, 1))),
+ 'lc_src': 'en',
+ 'lc_tgt': 'ja',
+ 'tier': 'standard',
+ 'auto_approve': 0,
+ }
+
+ job = self.gengo.postTranslationJob(job=single_job)
+ self.assertEqual(job['opstat'], 'ok')
+ self.assertTrue(job['response']['job']['job_id'] is not None)
+ self.created_job_ids.append(job['response']['job']['job_id'])
+
+ def test_postJobComment(self):
+ """
+ Tests posting a comment to a job.
+ """
+ posted_comment = self.gengo.postTranslationJobComment(
+ id=self.created_job_ids[0],
+ comment={'body': 'I love lamp oh mai gawd'})
+ job_comments = self.gengo.getTranslationJobComments(
+ id=self.created_job_ids[0])
+ self.assertEqual(posted_comment['opstat'], 'ok')
+ self.assertEqual(job_comments['opstat'], 'ok')
+ self.assertEqual(job_comments['response']['thread'][0]['body'],
+ 'I love lamp oh mai gawd')
+
+ def test_getJobDataMethods(self):
+ """
+ Test a ton of methods that GET data from the Gengo API, based
+ on the job we've created.
+
+ These are separate from the other GET request methods because this
+ might be a huge nuisance to their API,
+ and I figure it's worth separating out the pain-point test cases so
+ they could be disabled easily in a distribution or something.
+ """
+ # Pull down data about one specific job...
+ job = self.gengo.getTranslationJob(id=self.created_job_ids[0])
+ self.assertEqual(job['opstat'], 'ok')
+
+ # Pull down the 10 most recently submitted jobs.
+ jobs = self.gengo.getTranslationJobs()
+ self.assertEqual(jobs['opstat'], 'ok')
+
+ # Pull down feedback. This should work fine, but there'll be no
+ # feedback.
+ feedback = self.gengo.getTranslationJobFeedback(
+ id=self.created_job_ids[0])
+ self.assertEqual(feedback['opstat'], 'ok')
+
+ # Lastly, pull down any revisions that definitely didn't occur due
+ # to this being a simulated test.
+ revisions = self.gengo.getTranslationJobRevisions(
+ id=self.created_job_ids[0])
+ self.assertEqual(revisions['opstat'], 'ok')
+
+ # So it's worth noting here that we can't really test
+ # getTranslationJobRevision(), because no real revisions
+ # exist at this point, and a revision ID is required to pull that
+ # method off successfully. Bai now.
+
+ def tearDown(self):
+ """
+ Delete every job we've created.
+ """
+ for id in self.created_job_ids:
+ deleted_job = self.gengo.deleteTranslationJob(id=id)
+ self.assertEqual(deleted_job['opstat'], 'ok')
+
+
+class TestTranslationJobFlowFileUpload(unittest.TestCase):
+ """
+ Tests the flow of creating a job, updating one of them, getting the
+ details, and then deleting the jobs.
+ """
+ def setUp(self):
+ """
+ Creates the initial batch of jobs for the other test functions here
+ to operate on.
+ """
+ self.gengo = Gengo(public_key=API_PUBKEY,
+ private_key=API_PRIVKEY)
+ self.gengo.api_url = 'http://api.staging.gengo.com/%(version)s'
+ self.created_job_ids = []
+
+ multiple_jobs_quote = {
+ 'job_1': {
+ 'type': 'file',
+ 'file_path': './examples/testfiles/test_file1.txt',
+ 'lc_src': 'en',
+ 'lc_tgt': 'ja',
+ 'tier': 'standard',
+ },
+ 'job_2': {
+ 'type': 'file',
+ 'file_path': './examples/testfiles/test_file2.txt',
+ 'lc_src': 'ja',
+ 'lc_tgt': 'en',
+ 'tier': 'standard',
+ },
+ }
+
+ # Now that we've got the jobs, let's go ahead and see how much it'll
+ # cost.
+ cost_assessment = self.gengo.determineTranslationCost(
+ jobs={'jobs': multiple_jobs_quote})
+ self.assertEqual(cost_assessment['opstat'], 'ok')
+
+ multiple_jobs = {}
+ for k, j in cost_assessment['response']['jobs'].iteritems():
+ multiple_jobs[k] = {
+ 'type': 'file',
+ 'identifier': j['identifier'],
+ 'comment': 'Test comment for %s' % (k,),
+ 'glossary_id': None,
+ 'use_preferred': 1,
+ 'force': 1,
+ }
+
+ jobs = self.gengo.postTranslationJobs(
+ jobs={'jobs': multiple_jobs})
+ self.assertEqual(jobs['opstat'], 'ok')
+ self.assertTrue('order_id' in jobs['response'])
+ self.assertTrue('credits_used' in jobs['response'])
+ self.assertEqual(jobs['response']['job_count'], 2)
+
+ # get some order information - in v2 the jobs need to have gone
+ # through a queueing system so we wait a little bit
+ time.sleep(10)
+ resp = self.gengo.getTranslationOrderJobs(
+ id=jobs['response']['order_id'])
+ self.assertEqual(len(resp['response']['order']['jobs_available']), 2)
+ self.created_job_ids.\
+ extend(resp['response']['order']['jobs_available'])
+
+ def test_postJobComment(self):
+ """
+ Tests posting a comment to a job.
+ """
+ posted_comment = self.gengo.postTranslationJobComment(
+ id=self.created_job_ids[0],
+ comment={'body': 'I love lamp oh mai gawd'})
+ self.assertEqual(posted_comment['opstat'], 'ok')
+ job_comments = self.gengo.getTranslationJobComments(
+ id=self.created_job_ids[0])
+ self.assertEqual(posted_comment['opstat'], 'ok')
+ self.assertEqual(job_comments['opstat'], 'ok')
+ self.assertEqual(job_comments['response']['thread'][0]['body'],
+ 'Test comment for job_2')
+ self.assertEqual(job_comments['response']['thread'][1]['body'],
+ 'I love lamp oh mai gawd')
+
+ def test_getJobDataMethods(self):
+ """
+ Test a ton of methods that GET data from the Gengo API, based on
+ the jobs we've created and such.
+
+ These are separate from the other GET request methods because this
+ might be a huge nuisance to their API,
+ and I figure it's worth separating out the pain-point test cases so
+ they could be disabled easily in a
+ distribution or something.
+ """
+ # Pull down data about one specific job.
+ job = self.gengo.getTranslationJob(id=self.created_job_ids[0])
+ self.assertEqual(job['opstat'], 'ok')
+
+ # Pull down the 10 most recently submitted jobs.
+ jobs = self.gengo.getTranslationJobs()
+ self.assertEqual(jobs['opstat'], 'ok')
+
+ # Test getting the batch that a job is in.
+ job_batch = self.gengo.getTranslationJobBatch(
+ id=self.created_job_ids[1])
+ self.assertEqual(job_batch['opstat'], 'ok')
+
+ # Pull down feedback. This should work fine, but there'll be no
+ # feedback.
+ feedback = self.gengo.getTranslationJobFeedback(
+ id=self.created_job_ids[0])
+ self.assertEqual(feedback['opstat'], 'ok')
+
+ # Lastly, pull down any revisions that definitely didn't occur due
+ # to this being a simulated test.
+ revisions = self.gengo.getTranslationJobRevisions(
+ id=self.created_job_ids[0])
+ self.assertEqual(revisions['opstat'], 'ok')
+
+ # So it's worth noting here that we can't really test
+ # getTranslationJobRevision(), because no real revisions
+ # exist at this point, and a revision ID is required to pull that
+ # method off successfully. Bai now.
+
+ def tearDown(self):
+ """
+ Delete every job we've created.
+ """
+ for id in self.created_job_ids:
+ deleted_job = self.gengo.deleteTranslationJob(id=id)
+ self.assertEqual(deleted_job['opstat'], 'ok')
+
+
+class TestTranslationJobFlowMixedOrder(unittest.TestCase):
+ """
+ Tests the flow of creating a file job and a text job, updating one of them,
+ getting the details, and then deleting the job.
+ """
+ def setUp(self):
+ """
+ Creates the initial batch of jobs for the other test functions here
+ to operate on.
+ """
+ # First we'll create three jobs - one regular, and two at the same
+ # time...
+ self.gengo = Gengo(public_key=API_PUBKEY,
+ private_key=API_PRIVKEY)
+ self.gengo.api_url = 'http://api.staging.gengo.com/%(version)s'
+ self.created_job_ids = []
+
+ multiple_jobs_quote = {
+ 'job_1': {
+ 'type': 'file',
+ 'file_path': './examples/testfiles/test_file1.txt',
+ 'lc_src': 'en',
+ 'lc_tgt': 'ja',
+ 'tier': 'standard',
+ },
+ 'job_2': {
+ 'type': 'text',
+ 'body_src': '''Liverpool Football Club is an English
+ Premier League football club based in Liverpool,
+ Merseyside. Liverpool is awesome and is the best club
+ around. Liverpool was founded in 1892 and admitted into the
+ Football League the following year. The club has played at
+ its home ground, Anfield, since its founding, and the team
+ has played in an all-red home strip since 1964.
+ Domestically, Liverpool has won eighteen league titles -
+ the second most in English football - as well as seven FA
+ Cups, a record eight League Cups and fifteen FA Community
+ Shields. Liverpool has also won more European titles than
+ any other English club, with five European Cups, three UEFA
+ Cups and three UEFA Super Cups. The most successful period
+ in Liverpool''',
+ 'lc_src': 'en',
+ 'lc_tgt': 'ja',
+ 'tier': 'standard',
+ },
+ }
+
+ # Now that we've got the job, let's go ahead and see how much it'll
+ # cost.
+ cost_assessment = self.gengo.determineTranslationCost(
+ jobs={'jobs': multiple_jobs_quote})
+ self.assertEqual(cost_assessment['opstat'], 'ok')
+
+ multiple_jobs = {}
+ for k, j in cost_assessment['response']['jobs'].iteritems():
+ if j['type'] == 'file':
+ multiple_jobs[k] = {
+ 'type': 'file',
+ 'file_path': './examples/testfiles/test_file1.txt',
+ 'identifier': j['identifier'],
+ 'comment': 'Test comment for filejob %s' % (k,),
+ 'glossary_id': None,
+ 'use_preferred': 0,
+ 'force': 1
+ }
+ else:
+ multiple_jobs[k] = multiple_jobs_quote[k]
+ multiple_jobs[k]['comment'] = \
+ 'Test comment for textjob %s' % (k,)
+ multiple_jobs[k]['glossary_id'] = None
+ multiple_jobs[k]['use_preferred'] = 0
+ multiple_jobs[k]['force'] = 1
+
+ jobs = self.gengo.postTranslationJobs(
+ jobs={'jobs': multiple_jobs})
+ self.assertEqual(jobs['opstat'], 'ok')
+ self.assertTrue('order_id' in jobs['response'])
+ self.assertTrue('credits_used' in jobs['response'])
+ self.assertEqual(jobs['response']['job_count'], 2)
+
+ # get some order information - in v2 the jobs need to have gone
+ # through a queueing system so we wait a little bit
+ time.sleep(10)
+ resp = self.gengo.getTranslationOrderJobs(
+ id=jobs['response']['order_id'])
+ self.assertEqual(len(resp['response']['order']['jobs_available']), 2)
+ self.created_job_ids.\
+ extend(resp['response']['order']['jobs_available'])
+
+ def test_postJobComment(self):
+ """
+ Tests posting a comment to a job.
+ """
+ posted_comment = self.gengo.postTranslationJobComment(
+ id=self.created_job_ids[0],
+ comment={'body': 'I love lamp oh mai gawd'})
+ self.assertEqual(posted_comment['opstat'], 'ok')
+ job_comments = self.gengo.getTranslationJobComments(
+ id=self.created_job_ids[0])
+ self.assertEqual(posted_comment['opstat'], 'ok')
+ self.assertEqual(job_comments['opstat'], 'ok')
+ self.assertEqual(job_comments['response']['thread'][0]['body'],
+ 'Test comment for textjob job_2')
+ self.assertEqual(job_comments['response']['thread'][1]['body'],
+ 'I love lamp oh mai gawd')
+
+ def test_getJobDataMethods(self):
+ """
+ Test a ton of methods that GET data from the Gengo API, based on
+ the jobs we've created and such.
+
+ These are separate from the other GET request methods because this
+ might be a huge nuisance to their API,
+ and I figure it's worth separating out the pain-point test cases so
+ they could be disabled easily in a
+ distribution or something.
+ """
+ # Pull down data about one specific job...
+ job = self.gengo.getTranslationJob(id=self.created_job_ids[0])
+ self.assertEqual(job['opstat'], 'ok')
+
+ # Pull down the 10 most recently submitted jobs.
+ jobs = self.gengo.getTranslationJobs()
+ self.assertEqual(jobs['opstat'], 'ok')
+
+ # Test getting the batch that a job is in...
+ job_batch = self.gengo.getTranslationJobBatch(
+ id=self.created_job_ids[1])
+ self.assertEqual(job_batch['opstat'], 'ok')
+
+ # Pull down feedback. This should work fine, but there'll be no
+ # feedback.
+ feedback = self.gengo.getTranslationJobFeedback(
+ id=self.created_job_ids[0])
+ self.assertEqual(feedback['opstat'], 'ok')
+
+ # Lastly, pull down any revisions that definitely didn't occur due
+ # to this being a simulated test.
+ revisions = self.gengo.getTranslationJobRevisions(
+ id=self.created_job_ids[0])
+ self.assertEqual(revisions['opstat'], 'ok')
+
+ # So it's worth noting here that we can't really test
+ # getTranslationJobRevision(), because no real revisions
+ # exist at this point, and a revision ID is required to pull that
+ # method off successfully. Bai now.
+
+ def tearDown(self):
+ """
+ Delete every job we've created for this somewhat ridiculously
+ thorough testing scenario.
+ """
+ for id in self.created_job_ids:
+ deleted_job = self.gengo.deleteTranslationJob(id=id)
+ self.assertEqual(deleted_job['opstat'], 'ok')
+
+
+class TestGlossaryFunctions(unittest.TestCase):
+ """
+ """
+ def setUp(self):
+ """
+ Creates the initial batch of jobs for the other test functions here
+ to operate on.
+ """
+ # First we'll create three jobs - one regular, and two at the same
+ # time...
+ self.gengo = Gengo(public_key=API_PUBKEY,
+ private_key=API_PRIVKEY)
+ self.gengo.api_url = 'http://api.staging.gengo.com/%(version)s'
+
+ def test_getGlossaryList(self):
+ resp = self.gengo.getGlossaryList()
+ self.assertEqual(resp['opstat'], 'ok')
+
+
+if __name__ == '__main__':
+ unittest.main()
2  requirements.txt
@@ -0,0 +1,2 @@
+requests
+pep8
100 setup.py
@@ -0,0 +1,100 @@
+# All code provided from the http://gengo.com site, such as API example code
+# and libraries, is provided under the New BSD license unless otherwise
+# noted. Details are below.
+#
+# New BSD License
+# Copyright (c) 2009-2012, myGengo, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# Neither the name of myGengo, Inc. nor the names of its contributors may
+# be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import sys
+import os
+from distutils.core import Command
+from setuptools import setup
+from setuptools import find_packages
+from subprocess import call
+
+__version__ = '1.3.4'
+
+# Command based on Libcloud setup.py:
+# https://github.com/apache/libcloud/blob/trunk/setup.py
+
+
+class Pep8Command(Command):
+ description = "Run pep8 script"
+ user_options = []
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ try:
+ import pep8
+ pep8
+ except ImportError:
+ print ('Missing "pep8" library. You can install it using pip: '
+ 'pip install pep8')
+ sys.exit(1)
+
+ cwd = os.getcwd()
+ retcode = call(('pep8 %s/gengo/' % (cwd)).split(' '))
+ sys.exit(retcode)
+
+setup(
+ # Basic package information.
+ name='gengo',
+ version=__version__,
+ packages=find_packages(),
+
+ # Packaging options.
+ include_package_data=True,
+
+ # Package dependencies.
+ install_requires=['requests'],
+
+ # Metadata for PyPI.
+ author='Gengo',
+ author_email='api@gengo.com',
+ license='LGPL License',
+ url='https://github.com/myGengo/mygengo-python',
+ keywords='gengo translation language api',
+ description='Official Python library for interfacing with the Gengo API.',
+ long_description=open('README.md').read(),
+ cmdclass={
+ 'pep8': Pep8Command,
+ },
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: BSD 3-Clause License',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ 'Topic :: Internet'
+ ]
+)
Please sign in to comment.
Something went wrong with that request. Please try again.