Search in sources :

Example 1 with LanguagesResource

use of com.google.api.services.translate.model.LanguagesResource in project google-cloud-java by GoogleCloudPlatform.

the class HttpTranslateRpc method listSupportedLanguages.

@Override
public List<LanguagesResource> listSupportedLanguages(Map<Option, ?> optionMap) {
    try {
        Map<String, ?> content = ImmutableMap.of("target", firstNonNull(Option.TARGET_LANGUAGE.getString(optionMap), options.getTargetLanguage()));
        HttpRequest httpRequest = translate.getRequestFactory().buildPostRequest(buildTargetUrl("languages"), new JsonHttpContent(translate.getJsonFactory(), content)).setParser(translate.getObjectParser());
        List<LanguagesResource> languages = httpRequest.execute().parseAs(LanguagesListResponse.class).getLanguages();
        //     .execute().getLanguages();
        return languages != null ? languages : ImmutableList.<LanguagesResource>of();
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) LanguagesListResponse(com.google.api.services.translate.model.LanguagesListResponse) LanguagesResource(com.google.api.services.translate.model.LanguagesResource) JsonHttpContent(com.google.api.client.http.json.JsonHttpContent) IOException(java.io.IOException)

Aggregations

HttpRequest (com.google.api.client.http.HttpRequest)1 JsonHttpContent (com.google.api.client.http.json.JsonHttpContent)1 LanguagesListResponse (com.google.api.services.translate.model.LanguagesListResponse)1 LanguagesResource (com.google.api.services.translate.model.LanguagesResource)1 IOException (java.io.IOException)1