Sends the request to the api.

@param string $method
@param array  $query
@param array  $body

@return array response
968972
private function sendRequest(string $method, string $uri, array $query = [], array $body = []) : array {
        $uri = sprintf('%s%s', $this->baseUrl, ltrim($uri, '/'));

        $options = [
            'headers' => [
                'Authorization' => (string) $this->authentication
            ],
            'http_errors' => false
        ];

        if (! empty($query)) {
            $options['query'] = $query;
        }

        if (! empty($body)) {
            $options['json'] = $body;
        }

        $response = $this->client->request(
            $method,
            $uri,
            $options
        );

        $json = json_decode((string) $response->getBody(), true);
        if ($json === null) {
            if ($this->throwsExceptions) {
                throw new SDKError();
            }

            return [(string) $response->getBody()];
        }

        if (($json['status'] === false) && ($this->throwsExceptions)) {
            throw new SDKException(
                $json['error']['message'],
                $json['error']['type'],
                $json['error']['link']
            );
        }

        return $json;
    }
295578
protected function sendRequest($method, $url, $body)
    {
        $options = [
            'headers' => [
                'Accept-Encoding' => 'gzip',
                'Content-Type' => 'application/json',
            ],
            'body' => $body,
        ];

        try {
            $response = $this->client->request($method, $url, $options);
            return json_decode($response->getBody(), true);
        } catch (ClientException $e) {
            throw new PredictionIOAPIError($e->getMessage());
        }
    }
392172
public function create(string $method, string $uri, array $headers = [], $body = null): RequestInterface
    {
        if (!is_array($body)) {
            return $this->getRequestFactory()->createRequest($method, $uri, $headers, $body);
        }

        return $this->getRequestFactory()->createRequest($method, $uri, $headers);
    }
1065890
public function run($uri, $method, array $queryParams = array(), array $body = array())
    {
        $url = sprintf('/%s%s', self::API_VERSION, $uri);

        return $this->runUrl($url, $method, $queryParams, $body);
    }
1026909
public static function request($method, $url, $query_data = null, $body = null, array $headers = array(), array $options = array())
    {
        $method = strtoupper($method);

        $_options = array(
            'method' => $method,
            'user_agent' => 'pake '.pakeApp::VERSION,
            'ignore_errors' => true,
        );

        $parsed_url = parse_url($url);

        $proxy_var_name = null;

        if ($parsed_url['scheme'] == 'http') {
            $proxy_var_name = 'http_proxy';
        } elseif ($parsed_url['scheme'] == 'https') {
            if (isset($_SERVER['https_proxy'])) {
                $proxy_var_name = 'https_proxy';
            } elseif (isset($_SERVER['HTTPS_PROXY'])) {
                $proxy_var_name = 'HTTPS_PROXY';
            }
        }

        if (null !== $proxy_var_name) {
            if (isset($_SERVER[$proxy_var_name])) {
                $parsed_proxy_str = parse_url($_SERVER[$proxy_var_name]);

                if (is_array($parsed_proxy_str) and
                    $parsed_proxy_str['scheme'] == 'http' and
                    isset($parsed_proxy_str['host']) and
                    isset($parsed_proxy_str['port'])
                ) {
                    $_options['proxy'] = 'tcp://'.$parsed_proxy_str['host'].':'.$parsed_proxy_str['port'];
                    $_options['request_fulluri'] = true;
                    pake_echo_comment('(using proxy: '.$parsed_proxy_str['host'].':'.$parsed_proxy_str['port'].')');
                } else {
                    pake_echo_error('"'.$proxy_var_name.'" environment variable is set to the wrong value. expecting http://host:port');
                }
            }
        }

        if (null !== $body) {
            if (is_array($body)) {
                $body = http_build_query($body);
            }

            $_options['content'] = $body;
        }

        if (count($headers) > 0) {
            $_options['header'] = implode("\r\n", $headers)."\r\n";
        }

        $options = array_merge($_options, $options);

        if (null !== $query_data) {
            if (is_array($query_data)) {
                $query_data = http_build_query($query_data);
            }

            $url .= '?'.$query_data;
        }

        $context = stream_context_create(array('http' => $options));

        pake_echo_action('HTTP '.$method, $url);
        $stream = @fopen($url, 'r', false, $context);

        if (false === $stream) {
            $err = error_get_last();
            throw new pakeException('HTTP request failed: '.$err['message']);
        }

        $meta = stream_get_meta_data($stream);
        $response = stream_get_contents($stream);

        fclose($stream);

        $status = $meta['wrapper_data'][0];
        $code = substr($status, 9, 3);

        if ($code > 400)
            throw new pakeException('http request returned: '.$status);

        pake_echo_action('…', 'got '.strlen($response).' bytes');

        return $response;
    }
1005057
protected function send(string $method, $path, array $headers = [], $body = []): Contracts\Response
    {
        if ($this instanceof Contracts\Filterable) {
            $body = $this->filterRequest($body);
        }

        $endpoint = ($path instanceof Contracts\Endpoint)
                        ? $this->getApiEndpoint($path->getPath())->addQuery($path->getQuery())
                        : $this->getApiEndpoint($path);

        $message = $this->responseWith(
            $this->client->send($method, $endpoint, $headers, $body)
        );

        return $this->interactsWithResponse($message);
    }
980673
public static function sendRequest($method = 'sendMessage', $params)
    {
        $curl = curl_init(self::$api_url . self::$api_token . '/'. $method);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

        if(self::$proxy) {
            curl_setopt_array($curl, self::setProxy());
        }

        $curl_result = curl_exec($curl);
        $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);

        if ($http_code != 200) {
            if ($curl_result) {
                $curl_result = json_decode($curl_result, true);
                throw new \Exception($curl_result['description']);
            }
            throw new \Exception('an error was encountered');
        }

        return $curl_result;
    }
708656
private function getResponse($method, $path, $body = null, $headers = [])
    {
        $allHeaders = array_merge($this->getAuthorizationHeader(), $headers);
        $uri = $path;

        $request = new Request($method, $uri, $allHeaders, $body);

        return $this->guzzle->send($request);
    }
472139
protected function sendPost(string $uri, array $query = [], array $body = []) : array {
        return $this->sendRequest(
            'POST',
            $uri,
            $query,
            $body
        );
    }
909282
public function request($method = self::REQUEST_POST, $resource, array $params = [], array $headers = [])
    {
        $signature = $this->createSignature($resource);
        $method = strtoupper($method);

        $options = [
            'headers' => array_merge($headers, [
                'X-Auth-Key' => $this->key,
                'X-Auth-Workspace' => $this->workspace,
                'X-Auth-Signature' => $signature,
                'Content-Type' => 'application/json; charset=utf-8',
                'Accept' => 'application/json'
            ])
        ];

        /**
         * If POST and data is not an url then send data in body as json string
         */
        if ($method === self::REQUEST_POST && isset($params['data']) && !self::isUrl($params['data']))
        {
            if (is_string($params['data']))
            {
                $params['data'] = self::stringToArray($params['data']);
            }

            if ($params['data'])
            {
                $options[\GuzzleHttp\RequestOptions::JSON] = $params['data'];
                unset($params['data']);
            }
        }

        $options[\GuzzleHttp\RequestOptions::QUERY] = $params;
        return $this->handleRequest($method, $resource, $options);
    }
1110228
public function doRequest($uri, $method = 'GET', $headers = array(), $body = NULL) {

    $in = NULL;
    if (!empty($body)) {
      // For whatever reason, CURL seems to want POST request data to be
      // a string, not a file handle. So we adjust. PUT, on the other hand,
      // needs to be in a file handle.
      if ($method == 'POST') {
        $in = $body;
      }
      else {
        // First we turn our body into a temp-backed buffer.
        $in = fopen('php://temp', 'wr', FALSE);
        fwrite($in, $body, strlen($body));
        rewind($in);
      }
    }
    return $this->handleDoRequest($uri, $method, $headers, $in);
    //return $this->handleDoRequest($uri, $method, $headers, $body);

  }
232801
private function call( $method, $api, $body ) {
    $key = $this->generateHookKey( $method, $api );
    if (array_key_exists($key, $this->hookMap)) {
      call_user_func([$this, $this->hookMap[$key]], $body);
    }
  }
836038
public function send( string$body=null ):Response
	{
		$this->justSend($body);

		return new Response( $this, $this->handle );
	}
583320
public function handle(string $method, $body = false, $uriAppend = false, array $queryParams = [])
    {
        $client   = $this->createElasticClient();
        $param    = $queryParams[0];
        $endPoint = "search";

        if (is_a($param, Search::class)) {
            $endPoint    = "search";
            $queryParams = $param->getParams();

        } elseif (is_a($param, MSearch::class)) {
            $endPoint    = "msearch";
            $queryParams = $param->getParams();
        }

        try {
            $elasticData = $client->{$endPoint}($queryParams);

            if ($client->transport->getLastConnection()) {
                $elasticData['debug'] = $client->transport->getLastConnection()->getLastRequestInfo();
            }

            if ($endPoint == 'msearch') {
                foreach ($elasticData['responses'] as $key => $responseItem) {
                    $responseItem['debug'] = $elasticData['debug'];
                    $response[]            = new Response($responseItem);
                }
            } else {
                $response = new Response($elasticData, $queryParams['body']['size'] ?? 0, $queryParams['body']['from'] ?? 0);
            }
        } catch (\Exception $ex) {
            $error = json_decode($ex->getMessage());
            throw new \Exception($error->error->reason ?? $ex->getMessage());
        }

        return $response;
    }
215610
protected function send($method, $endpoint = '', array $headers = null, $body = null)
    {
        $this->lastResponse = null;
        $url = $this->baseUrl . $endpoint;
        $options = ['headers' => \array_merge($this->defaultHeaders, $headers)];

        if (!empty($body)) {
            $options['body'] = $body;
        }

        $this->lastRequest = $this->httpClient->request(
            $method,
            $url,
            $options
        );

        try {
            $this->lastResponse = $this->httpClient->send($this->lastRequest);
        } catch (\Exception $error) {
            throw new HttpServiceException(
                HttpServiceException::BAD_SERVICE_REQUEST,
                [$error->getMessage()]
            );
        }

        return $this->lastResponse;
    }
522091
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
		$method = $method ?? 'GET';
		$params = $this->requestParams($path, $params ?? [], $body ?? []);

		if($method === 'POST'){
			$body   = $params;
			$params = [];
		}

#		return parent::request('', $params, $method, $body, $headers);

		$request = $this->requestFactory
			->createRequest($method, Psr7\merge_query($this->apiURL, $params));

		foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
			$request = $request->withAddedHeader($header, $value);
		}

		if($method === 'POST'){
			$request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
			$body    = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738));
			$request = $request->withBody($body);
		}

		return $this->http->sendRequest($request);
	}
587067
public function sendHttpRequest(array $requestData, $method = 'POST')
    {
        // Perform re-login if required.
        if ('getchallenge' !== $requestData[ 'operation' ] && time() > $this->serviceExpireTime) {
            $this->login($this->userName, $this->accessKey);
        }

        $requestData[ 'sessionName' ] = $this->sessionName;
        
        try {
            switch ($method) {
                case 'GET':
                    $response = $this->httpClient->get($this->wsBaseURL, [ 'query' => $requestData, 'timeout' => $this->requestTimeout ]);
                    break;
                case 'POST':
                    $response = $this->httpClient->post($this->wsBaseURL, [ 'form_params' => $requestData, 'timeout' => $this->requestTimeout ]);
                    break;
                default:
                    throw new WSException("Unsupported request type {$method}");
            }
        } catch (RequestException $ex) {
            $urlFailed = $this->httpClient->getConfig('base_uri').$this->wsBaseURL;
            throw new WSException(
                sprintf('Failed to execute %s call on "%s" URL', $method, $urlFailed),
                'FAILED_SENDING_REQUEST',
                $ex
            );
        }

        $jsonRaw = $response->getBody();
        $jsonObj = json_decode($jsonRaw, true);

        $result = (is_array($jsonObj) && !self::checkForError($jsonObj))
            ? $jsonObj[ 'result' ]
            : null;
        return $result;
    }