@param string $method
@param $data
@param array $headers

@return resource
171574
private function getContext(string $method, $data, array $headers)
    {
        $options = [
            'http' => [
                'header' => $this->join(': ', $headers),
                'method' => $method,
                'content' => $this->getRawData($data),
            ],
        ];

        if (is_array($this->options)) {
            $options = array_merge_recursive($options, $this->options);
        }

        if (!empty($this->cookies)) {
            $options['http']['header'] .= 'Cookie: '.$this->join('=', $this->cookies, '; ');
        }

        $context = stream_context_create($options);

        return $context;
    }
261651
protected function checkConnection($method, $path, $data, $headers)
    {
        $basicAuth = '';
        if ($this->options['username']) {
            $basicAuth .= "{$this->options['username']}:{$this->options['password']}@";
        }
        if ($this->options['headers']) {
            $headers = array_merge($this->options['headers'], $headers);
        }
        if (!isset($headers['Content-Type'])) {
            $headers['Content-Type'] = 'application/json';
        }
        $stringHeader = '';
        if ($headers != null) {
            foreach ($headers as $key => $val) {
                $stringHeader .= $key.': '.$val."\r\n";
            }
        }
        if ($this->httpFilePointer == null) {
            // TODO SSL support?
            $host = $this->options['host'];
            if ($this->options['port'] != 80) {
                $host .= ":{$this->options['port']}";
            }
            $this->httpFilePointer = @fopen(
                'http://'.$basicAuth.$host.$path,
                'r',
                false,
                stream_context_create(
                    [
                        'http' => [
                            'method'        => $method,
                            'content'       => $data,
                            'ignore_errors' => true,
                            'max_redirects' => 0,
                            'user_agent'    => 'Doctrine CouchDB ODM $Revision$',
                            'timeout'       => $this->options['timeout'],
                            'header'        => $stringHeader,
                        ],
                    ]
                )
            );
        }

        // Check if connection has been established successfully.
        if ($this->httpFilePointer === false) {
            $error = error_get_last();
            throw HTTPException::connectionFailure(
                $this->options['ip'],
                $this->options['port'],
                $error['message'],
                0
            );
        }
    }
230531
public function call($method, array $data = null, $type = 'get')
    {
        $url = self::URL_PREFIX . '/' . $method . '?auth_token=' . $this->token;
        if ($data && $type == 'get') {
            $url .= '&' . implode('&', $data);
        }

        $options = [
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true
        ];
        if ($data && $type == 'post') {
            $options[CURLOPT_POST] = true;
            $options[CURLOPT_POSTFIELDS] = $data;
        }
        $response = self::jsonValidate($this->executeCurl($options), $this->returnArray);

        return $response['data'];
    }
142506
private function processRequest($url, $headers, $method = 'post')
    {
        if (array_key_exists('body', $headers)) {
            $headers['body'] = json_encode($headers['body']);
        }

        if ($method == 'post') {
            $response = $this->guzzle->request('POST', $url, $headers);
        } elseif ($method == 'delete') {
            $response = $this->guzzle->request('DELETE', $url, $headers);
        } else {
            $params = $this->processGetParams($headers);
            $response = $this->guzzle->request('GET', $url . $params);
        }
        $response = $this->processResponse($response);

        return $response;
    }
285558
protected function request($method, array $data = array())
    {
        $auth = base64_encode($this->username . ':' . $this->password);
        $header = "Authorization: Basic $auth";
        $opts = array(
            'http' => array(
                'method' => 'GET',
                'header' => $header
            )
        );
        $ctx = stream_context_create($opts);

        $client = new \SoapClient(
            $this->endpoint . '/wsdl',
            array(
                'location' => $this->endpoint,
                'exceptions' => 1,
                'stream_context' => $ctx,
                'trace' => true
            )
        );

        $response = call_user_func_array(array($client, $method), $data);
        if (isset($response->return)) {
            return $response->return;
        }

        return null;
    }
909580
public function request($method, $url, array $data = [])
    {
        return $this->request->send($this->baseUrl.'/'.$url, $method, $data);
    }
218825
private function request($method, $uri, $data = [])
    {
        $uri = $this->getUri($uri);

        $headers = [];

        // Basic Auth
        $credentials = $this->key.':'.$this->password;

        // User Agent
        $agent = sprintf("%s %s", Client::NAME, Client::VERSION);

        $ch = curl_init();

        if (strtoupper($method) === 'GET' && !empty($data)) {
            $queryString = http_build_query($data);
            $uri .= '?'.$queryString;
        }

        $options = [
            CURLOPT_URL => $uri,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER => true,
            CURLOPT_USERAGENT => $agent,
            CURLOPT_USERPWD => $credentials,
            CURLOPT_TIMEOUT => 60,
        ];

        if (strtoupper($method) === 'POST') {
            $jsonData = json_encode($data);

            $headers[] = 'Content-Type: application/json';
            $headers[] = 'Content-Length: '.strlen($jsonData);

            $options[CURLOPT_CUSTOMREQUEST] = 'POST';
            $options[CURLOPT_POSTFIELDS] = $jsonData;
        }

        if (isset($this->version) && is_numeric($this->version)) {
            $headers[] = 'X-EWAY-APIVERSION: '.$this->version;
        }

        $options[CURLOPT_HTTPHEADER] = $headers;

        curl_setopt_array($ch, $options);

        $rawResponse = curl_exec($ch);

        $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);

        if (curl_errno($ch)) {
            $responseError = curl_error($ch);
            $responseBody = '';
        } else {
            $responseError = '';
            $responseBody = $this->parseResponse($rawResponse, $headerSize);
        }

        $response = new Response($statusCode, $responseBody, $responseError);

        curl_close($ch);

        return $response;
    }
1227306
protected function sendRequest($method, $endpoint, $data = null)
    {
        return $this->httpClient->request(
            $method,
            $this->getEndpoint() . $endpoint,
            $this->getHeaders(),
            $data
        );
    }
1254449
public function copy($headers = false, $body = false, $url = false, $method = false)
    {
        $copy = clone $this;

        if ($headers !== false) $copy->_headers = new HeaderCollection($headers);
        if ($body !== false) $copy->_body = $body;
        if ($url !== false) $copy->_url = $url;
        if ($method !== false) $copy->_method = $method;

        unset($copy->_querystring);

        return $copy;
    }
861231
public function request(string $resource, string $method, array $data = [], array $files = [])
	{
		if (!strpos($resource, '://')) {
			if (!strpos($resource, '.')) {
				$resource .= '.json';
			}
			$resource = self::API_URL . $resource;
		}

		foreach ($data as $key => $val) {
			if ($val === null) {
				unset($data[$key]);
			}
		}

		foreach ($files as $key => $file) {
			if (!is_file($file)) {
				throw new Exception("Cannot read the file $file. Check if file exists on disk and check its permissions.");
			}
			$data[$key] = new \CURLFile($file);
		}

		$headers = ['Expect:'];

		if ($method === 'JSONPOST') {
			$method = 'POST';
			$data = json_encode($data);
			$headers[] = 'Content-Type: application/json';

		} elseif ($method === 'GET' && $data) {
			$resource .= '?' . http_build_query($data, '', '&');
		}

		$request = OAuth\Request::from_consumer_and_token($this->consumer, $this->token, $method, $resource);
		$request->sign_request(new OAuth\SignatureMethod_HMAC_SHA1, $this->consumer, $this->token);
		$headers[] = $request->to_header();

		$options = [
			CURLOPT_URL => $resource,
			CURLOPT_HEADER => false,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_HTTPHEADER => $headers,
		] + $this->httpOptions;
		if ($method === 'POST') {
			$options += [
				CURLOPT_POST => true,
				CURLOPT_POSTFIELDS => $data,
				CURLOPT_SAFE_UPLOAD => true,
			];
		}

		$curl = curl_init();
		curl_setopt_array($curl, $options);
		$result = curl_exec($curl);
		if (curl_errno($curl)) {
			throw new Exception('Server error: ' . curl_error($curl));
		}

		$payload = @json_decode($result, false, 128, JSON_BIGINT_AS_STRING); // intentionally @

		if ($payload === false) {
			throw new Exception('Invalid server response');
		}

		$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
		if ($code >= 400) {
			throw new Exception(isset($payload->errors[0]->message)
				? $payload->errors[0]->message
				: "Server error #$code with answer $result",
				$code
			);
		}

		return $payload;
	}
763214
public function get($service, $headers = null, $data = null)
	{
		return $this->customRequest($service, 'GET', $headers, $data);
	}
976815
public function makeRequest($method, $endpoint, array $data = [])
    {
        $response = $this->client->request($method, $endpoint, $data);

        return json_decode((string) $response->getBody());
    }
959495
public function query($interface, $method, $data) {
        $headers = ['rpc_client_name' => $this->config[ 'name' ],
                    'rpc_token' => $this->config[ 'token' ],
                    'rpc_serialize' => $this->config[ 'serialize' ],
                    'rpc_interface' => $interface,
                    'rpc_method' => $method];
        if (IS_SWOOLE && \Co::getuid()) {
            return $this->queryCoroutine($headers, $data);
        } else {
            return $this->queryByRequest($headers, $data);
        }

    }
1145810
private function getCachedResponse($method, $url, array $data, array $headers)
    {
        if ($this->cache)
        {
            return $this->cache->findResponse($method, $url, $data, $headers, $this->basicAuthCredentials);
        }

        return false;
    }
633892
public function updatePaymentMethod(array $data, array $headers = [])
    {
        $url = $this->url('hosted_pages/update_payment_method');

        return $this->post($url, $data, $headers);
    }
632572
public function invoke($uri, $method, array $headers = [])
    {
        $client   = new Client();
        $res      = $client->createRequest(strtoupper($method), url('/') . '/' . $uri, array_merge($headers, $this->getHeaders()));
        $response = $res->send();
        $types    = $response->getHeader('Content-Type')->toArray();
        $body     = $response->getBody(true);
        foreach ($types as $type) {
            if ($type == 'application/json' && function_exists('json_decode') and is_string($body)) {
                return json_decode($body);
            }
        }

        return $body;
    }
701376
protected function table(array $headers, array $data)
    {
        $dataset = [];

        foreach (array_values($data) as $value) {
            $dataset[] = array_combine($headers, $value);
        }

        return Utils\format_items('table', $dataset, $headers);
    }