/**
  * @param string    $url
  * @param array     $params
  * @param string    $method
  * @param bool|true $has_return_value
  * @param bool|true $json_response
  * @param bool|true $has_api_response
  *
  * @return array|mixed|stdClass|string
  * @throws TranslationProxy_Api_Error
  * @throws RuntimeException
  * @throws InvalidArgumentException
  */
 public function send_request($url, $params = array(), $method = 'GET', $has_return_value = true, $json_response = true, $has_api_response = true)
 {
     if (!$url) {
         throw new InvalidArgumentException('Empty target URL given!');
     }
     $response = null;
     $method = strtoupper($method);
     if ($params) {
         $url = TranslationProxy_Api::add_parameters_to_url($url, $params);
         if ($method === 'GET') {
             $url .= '?' . http_build_query($params);
         }
     }
     if (!isset($params['api_version']) || !$params['api_version']) {
         $params['api_version'] = self::API_VERSION;
     }
     WPML_TranslationProxy_Com_Log::log_call($url, $params);
     $api_response = $this->call_remote_api($url, $params, $method, $has_return_value);
     if ($has_return_value) {
         if (!isset($api_response['headers']['content-type'])) {
             throw new RuntimeException('Invalid HTTP response, no content type in header given!');
         }
         $content_type = $api_response['headers']['content-type'];
         $api_response = $api_response['body'];
         $api_response = strpos($content_type, 'zip') !== false ? gzdecode($api_response) : $api_response;
         WPML_TranslationProxy_Com_Log::log_response($json_response ? $api_response : 'XLIFF received');
         if ($json_response) {
             $response = json_decode($api_response);
             if ($has_api_response) {
                 if (!$response || !isset($response->status->code) || $response->status->code !== 0) {
                     $sanitized_url = WPML_TranslationProxy_Com_Log::sanitize_url($url);
                     $sanitized_params = WPML_TranslationProxy_Com_Log::sanitize_data($params);
                     $sanitized_response = WPML_TranslationProxy_Com_Log::sanitize_data($response);
                     $exception_message = 'Cannot communicate with the remote service response on url: `' . $sanitized_url . '` params: `' . serialize($sanitized_params) . '` response: `' . serialize($sanitized_response) . '`';
                     if (isset($response->status->message)) {
                         $exception_message = '';
                         if (isset($response->status->code)) {
                             $exception_message = '(' . $response->status->code . ') ';
                         }
                         $exception_message .= $response->status->message;
                     }
                     throw new RuntimeException($exception_message);
                 }
                 $response = $response->response;
             }
         } else {
             $response = $api_response;
         }
     }
     return $response;
 }