Skip to content

Latest commit

 

History

History
533 lines (529 loc) · 23.2 KB

README.md

File metadata and controls

533 lines (529 loc) · 23.2 KB

WritePath Translation API (Java)

With the WritePath Translation API and Proofreading API, developers can easily access a large number of experienced translators & editors with industry expertise in more than 35 languages. This API offers an easy and efficient way to integrate translation into your backend system, user interface, document management system, web shop, website content management system (CMS), mobile app, etc. It helps to automate repeating processes, cuts down process costs and gives you more time to focus on your core business.

For details check the Java translation API documentation. It takes care of authorization, JSON encoding and decoding and it can do a few more very convenient things.

Getting started:

Sign up at writepath.co and request your API keys.
co.writepath

Class Client

java.lang.Object
co.writepath.Client


public class Client
extends java.lang.Object
Java client for WritePath that maps all API functions. For detailed explanations of the API, please visit https://www.writepath.co/en/developers

Field Summary

Fields 
Modifier and Type Field and Description
private java.lang.String apiKey
Your API key
private com.fasterxml.jackson.databind.ObjectMapper objectMapper 
private java.lang.String privateKey
Your private API key
private java.lang.String url
Address of API

Constructor Summary

Constructors 
Constructor and Description
Client(java.lang.String apiKey, java.lang.String privateKey)
Instantiate new Client with your public and private API key set

Method Summary

All Methods Static Methods Instance Methods Concrete Methods 
Modifier and Type Method and Description
private java.lang.String encodeFileToBase64Binary(java.lang.String fileName) 
Reply getLanguages(int service)
Fetch the list of supported languages
Reply getStatus(int jobId, int format)
Retrieves a specific job.
Reply getWordBalance()
Fetch the word balance for the user
Reply getWordCountDocument(int service, int langId, java.lang.String fileName)
Fetch the word count for .docx, .xlsx or .pptx documents
Reply getWordCountPlainText(int service, int langId, java.lang.String text)
Fetch the word document for plain text
private static java.lang.String hmacSha1(java.lang.String value, java.lang.String key) 
Reply postComment(int jobId, java.lang.String comment)
Post a comment on a job
private org.apache.http.client.methods.HttpPost preparePost(java.lang.String url, Data data) 
Reply sendDocument(int service, int langId, int category, java.lang.String fileName, java.lang.String instructions, java.lang.String notifyUrl)
Send a job with file attachment to the service
Reply sendPlainText(int service, int langId, int category, java.lang.String text, java.lang.String instructions, java.lang.String notifyUrl)
Send a job with plain text to the service.
BatchReply sendBatchedPlainText(int service, int langId, int category, List <java.lang.String> text, java.lang.String instructions, java.lang.String notifyUrl)
Send batched jobs with plain text to the service.
BatchReply getBatchedStatus(int jobId, int format)
Retrieves specific batched jobs.

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

url

private java.lang.String url
Address of API

apiKey

private java.lang.String apiKey
Your API key

privateKey

private java.lang.String privateKey
Your private API key

objectMapper

private com.fasterxml.jackson.databind.ObjectMapper objectMapper

Constructor Detail

Client

public Client(java.lang.String apiKey,
              java.lang.String privateKey)
Instantiate new Client with your public and private API key set
Parameters:
apiKey - Public API key
privateKey - Private API key

Method Detail

preparePost

private org.apache.http.client.methods.HttpPost preparePost(java.lang.String url,
                                                            Data data)
                                                     throws java.io.UnsupportedEncodingException,
                                                            com.fasterxml.jackson.core.JsonProcessingException
Throws:
java.io.UnsupportedEncodingException
com.fasterxml.jackson.core.JsonProcessingException

encodeFileToBase64Binary

private java.lang.String encodeFileToBase64Binary(java.lang.String fileName)

hmacSha1

private static java.lang.String hmacSha1(java.lang.String value,
                                         java.lang.String key)

sendPlainText

public Reply sendPlainText(int service,
                           int langId,
                           int category,
                           java.lang.String text,
                           java.lang.String instructions,
                           java.lang.String notifyUrl)
                    throws java.io.IOException
Send a job with plain text to the service.
Parameters:
service - The service you require: 1 = editing, 2 = translation only, 4 = premium translation (translation + editing)
langId - The id of the translation / editing language.
category - The category / topic your text is about.
text - the text you would like to have translated or edited. Can include HTML tags, these are not counted as words.
instructions - instructions for the translator / editor.
notifyUrl - When job is finished, a REST post is sent to that URL
Returns:
server reply with wordsUsed and orderId set
Throws:
java.io.IOException - in case of network or json mapping issues

sendDocument

public Reply sendDocument(int service,
                          int langId,
                          int category,
                          java.lang.String fileName,
                          java.lang.String instructions,
                          java.lang.String notifyUrl)
                   throws java.io.IOException
Send a job with file attachment to the service
Parameters:
service - The service you require: 1 = editing, 2 = translation only, 4 = premium translation (translation + editing)
langId - The id of the translation / editing language.
category - The category / topic your text is about.
fileName - The path + filename of your document (only .docx, .pptx, .xlsx)
instructions - instructions for the translator / editor.
notifyUrl - When job is finished, a REST post is sent to that URL
Returns:
server reply with wordsUsed and orderId set
Throws:
java.io.IOException - in case of network or json mapping issues

getStatus

public Reply getStatus(int jobId,
                       int format)
                throws java.io.IOException
Retrieves a specific job.
Parameters:
jobId - id of the job you want to fetch. It's the orderId you get returned if you post a job.
format - The format of the returned content. 1 = as a file, 2 = as plain text
Returns:
server reply with wordsUsed, status, dueDate, wordsBalance, commentFinished and document set
Throws:
java.io.IOException - in case of network or json mapping issues

postComment

public Reply postComment(int jobId,
                         java.lang.String comment)
                  throws java.io.IOException
Post a comment on a job
Parameters:
jobId - The id of the job (= orderId) you want to comment on.
comment - Your comment
Returns:
server reply with empty response
Throws:
java.io.IOException - in case of network or json mapping issues

getLanguages

public Reply getLanguages(int service)
                   throws java.io.IOException
Fetch the list of supported languages
Parameters:
service - id of service needed
Returns:
server reply with langArray set
Throws:
java.io.IOException - in case of network or json mapping issues

getWordBalance

public Reply getWordBalance()
                     throws java.io.IOException
Fetch the word balance for the user
Returns:
server reply with words balance set
Throws:
java.io.IOException - in case of network or json mapping issues

getWordCountPlainText

public Reply getWordCountPlainText(int service,
                                   int langId,
                                   java.lang.String text)
                            throws java.io.IOException
Fetch the word document for plain text
Parameters:
service - The service you require: 1 = editing, 2 = translation only, 4 = premium translation (translation + editing)
langId - The id of the translation / editing language.
text - the text you would like to have translated or edited. Can include HTML tags, these are not counted as words.
Returns:
server reply with word count set
Throws:
java.io.IOException - in case of network or json mapping issues

getWordCountDocument

public Reply getWordCountDocument(int service,
                                  int langId,
                                  java.lang.String fileName)
                           throws java.io.IOException
Fetch the word count for .docx, .xlsx or .pptx documents
Parameters:
service - The service you require: 1 = editing, 2 = translation only, 4 = premium translation (translation + editing)
langId - The id of the translation / editing language.
fileName - path of file that needs to be checked
Returns:
server reply with word count set
Throws:
java.io.IOException - in case of network or json mapping issues