// Path: src/main/java/com/github/vbauer/yta/service/basic/ApiStatus.java
// @ThreadSafe
// public final class ApiStatus {
// 
//     /**
//      * Operation completed successfully.
//      */
//     public static final int OK = 200;
// 
//     /**
//      * Invalid API key.
//      */
//     public static final int ERR_KEY_INVALID = 401;
// 
//     /**
//      * This API key has been blocked.
//      */
//     public static final int ERR_KEY_BLOCKED = 402;
// 
//     /**
//      * You have reached the daily limit for requests
//      * (including calls of the translate method).
//      */
//     public static final int ERR_DAILY_REQ_LIMIT_EXCEEDED = 403;
// 
//     /**
//      * You have reached the daily limit for the volume of translated text
//      * (including calls of the translate method).
//      */
//     public static final int ERR_DAILY_CHAR_LIMIT_EXCEEDED = 404;
// 
//     /**
//      * The text size exceeds the maximum.
//      */
//     public static final int ERR_TEXT_TOO_LONG = 413;
// 
//     /**
//      * The text could not be translated.
//      */
//     public static final int ERR_UNPROCESSABLE_TEXT = 422;
// 
//     /**
//      * The specified translation direction is not supported.
//      */
//     public static final int ERR_LANG_NOT_SUPPORTED = 501;
// 
// 
//     private ApiStatus() {
//         throw new UnsupportedOperationException();
//     }
// 
// 
//     /**
//      * Check that status is {@link #OK} and throw {@link YTranslateApiException} otherwise.
//      *
//      * @param status status code
//      */
//     public static void check(final int status) {
//         if (status != ApiStatus.OK) {
//             throw new YTranslateApiException(status);
//         }
//     }
// 
// }
// 
// Path: src/main/java/com/github/vbauer/yta/service/basic/exception/YTranslateException.java
// @SuppressWarnings("serial")
// public class YTranslateException extends RuntimeException {
// 
//     public YTranslateException(@Nonnull final String message) {
//         super(message);
//     }
// 
//     public YTranslateException(@Nonnull final String message, @Nonnull final Throwable cause) {
//         super(message, cause);
//     }
// 
// }
// 
// Path: src/main/java/com/github/vbauer/yta/service/transport/RestClient.java
// public interface RestClient {
// 
//     /**
//      * Make REST API call.
//      *
//      * @param method url method
//      * @param parameters method parameters
//      * @return raw response in plain text
//      */
//     String callMethod(String method, Map<String, Object> parameters);
// 
// }


import com.github.vbauer.yta.service.basic.ApiStatus;
import com.github.vbauer.yta.service.basic.exception.YTranslateException;
import com.github.vbauer.yta.service.transport.RestClient;
import javax.annotation.concurrent.ThreadSafe;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.stream.Collectors;
package com.github.vbauer.yta.service.transport.impl;



/**
 * See {@link RestClient}.
 *
 * @author Vladislav Bauer
 */

@ThreadSafe
public class RestClientImpl implements RestClient {

    public static final String SERVICE_URL = "https://translate.yandex.net/api/v1.5/tr.json";
    public static final String ATTR_KEY = "key";
    public static final int DEFAULT_TIMEOUT = 30_000;

    private static final String METHOD_POST = "POST";
    private static final String PARAMETER_DELIMITER = "&";
    private static final String PARAMETER_ASSIGNMENT = "=";
    private static final String HEADER_CONTENT_TYPE = "Content-Type";
    private static final String HEADER_CONTENT_TYPE_VALUE = "application/x-www-form-urlencoded; charset=UTF-8";


    private final String key;


    public RestClientImpl(final String key) {
        this.key = key;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public String callMethod(final String method, final Map<String, Object> parameters) {
        try {
// Path: src/main/java/com/github/vbauer/yta/service/basic/ApiStatus.java
// @ThreadSafe
// public final class ApiStatus {
// 
//     /**
//      * Operation completed successfully.
//      */
//     public static final int OK = 200;
// 
//     /**
//      * Invalid API key.
//      */
//     public static final int ERR_KEY_INVALID = 401;
// 
//     /**
//      * This API key has been blocked.
//      */
//     public static final int ERR_KEY_BLOCKED = 402;
// 
//     /**
//      * You have reached the daily limit for requests
//      * (including calls of the translate method).
//      */
//     public static final int ERR_DAILY_REQ_LIMIT_EXCEEDED = 403;
// 
//     /**
//      * You have reached the daily limit for the volume of translated text
//      * (including calls of the translate method).
//      */
//     public static final int ERR_DAILY_CHAR_LIMIT_EXCEEDED = 404;
// 
//     /**
//      * The text size exceeds the maximum.
//      */
//     public static final int ERR_TEXT_TOO_LONG = 413;
// 
//     /**
//      * The text could not be translated.
//      */
//     public static final int ERR_UNPROCESSABLE_TEXT = 422;
// 
//     /**
//      * The specified translation direction is not supported.
//      */
//     public static final int ERR_LANG_NOT_SUPPORTED = 501;
// 
// 
//     private ApiStatus() {
//         throw new UnsupportedOperationException();
//     }
// 
// 
//     /**
//      * Check that status is {@link #OK} and throw {@link YTranslateApiException} otherwise.
//      *
//      * @param status status code
//      */
//     public static void check(final int status) {
//         if (status != ApiStatus.OK) {
//             throw new YTranslateApiException(status);
//         }
//     }
// 
// }
// 
// Path: src/main/java/com/github/vbauer/yta/service/basic/exception/YTranslateException.java
// @SuppressWarnings("serial")
// public class YTranslateException extends RuntimeException {
// 
//     public YTranslateException(@Nonnull final String message) {
//         super(message);
//     }
// 
//     public YTranslateException(@Nonnull final String message, @Nonnull final Throwable cause) {
//         super(message, cause);
//     }
// 
// }
// 
// Path: src/main/java/com/github/vbauer/yta/service/transport/RestClient.java
// public interface RestClient {
// 
//     /**
//      * Make REST API call.
//      *
//      * @param method url method
//      * @param parameters method parameters
//      * @return raw response in plain text
//      */
//     String callMethod(String method, Map<String, Object> parameters);
// 
// }


// Path: src/main/java/com/github/vbauer/yta/service/transport/impl/RestClientImpl.java
import com.github.vbauer.yta.service.basic.ApiStatus;
import com.github.vbauer.yta.service.basic.exception.YTranslateException;
import com.github.vbauer.yta.service.transport.RestClient;
import javax.annotation.concurrent.ThreadSafe;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.stream.Collectors;

package com.github.vbauer.yta.service.transport.impl;



/**
 * See {@link RestClient}.
 *
 * @author Vladislav Bauer
 */

@ThreadSafe
public class RestClientImpl implements RestClient {

    public static final String SERVICE_URL = "https://translate.yandex.net/api/v1.5/tr.json";
    public static final String ATTR_KEY = "key";
    public static final int DEFAULT_TIMEOUT = 30_000;

    private static final String METHOD_POST = "POST";
    private static final String PARAMETER_DELIMITER = "&";
    private static final String PARAMETER_ASSIGNMENT = "=";
    private static final String HEADER_CONTENT_TYPE = "Content-Type";
    private static final String HEADER_CONTENT_TYPE_VALUE = "application/x-www-form-urlencoded; charset=UTF-8";


    private final String key;


    public RestClientImpl(final String key) {
        this.key = key;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public String callMethod(final String method, final Map<String, Object> parameters) {
        try {
            final String uri = formatMethodUrl(method);