Commit an http request.

@param string $method
@param string $url
@param array  $params
@param array  $options

@return \Shoperti\PayMe\Contracts\ResponseInterface
763
public function commit($method, $url, $params = [], $options = [])
    {
        if (empty($this->connectionToken)) {
            $this->loginApplication();
        }

        $request = [
            'exceptions'      => false,
            'timeout'         => '80',
            'connect_timeout' => '30',
            'headers'         => [
                'Content-Type'  => 'application/json',
                'Accept'        => 'application/json',
                'Authorization' => 'Bearer '.$this->connectionToken,
            ],
        ];

        if (!empty($params)) {
            $request[$method === 'get' ? 'query' : 'json'] = $params;
        }

        $raw = $this->getHttpClient()->{$method}($url, $request);
        $statusCode = $raw->getStatusCode();

        $response = $statusCode == 200
            ? $this->parseResponse($raw->getBody())
            : $this->responseError($raw->getBody(), $statusCode);

        return $this->respond($response);
    }
603257
protected function request($url, $method = self::GET, $params = array(), $options = array())
    {
        if (is_array($params)) {
            if ($method === self::GET || $method === self::DELETE) {
                $url .= (stripos($url, '?') ? '&' : '?').http_build_query($params);
                $params = '';
            } elseif (($method === self::POST || $method === self::PUT || $method === self::PATCH)
                && (empty($options['files']) && empty($options['json']) )
                && !is_string($params)
            ) {
                $params = http_build_query($params);
            }
        }

        curl_setopt($this->curl, CURLOPT_HEADER, 1);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($this->curl, CURLOPT_URL, $url);

        // 使用证书
        if (isset($options['sslcert_path']) && isset($options['sslkey_path'])) {
            if (!file_exists($options['sslcert_path']) || !file_exists($options['sslkey_path'])) {
                throw new \Exception('Certfile is not correct');
            }

            // 设置证书
            // 使用证书：cert 与 key 分别属于两个.pem文件
            curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, true);

            // 严格校验
            curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($this->curl, CURLOPT_SSLCERTTYPE, 'PEM');
            curl_setopt($this->curl, CURLOPT_SSLCERT, $options['sslcert_path']);
            curl_setopt($this->curl, CURLOPT_SSLKEYTYPE, 'PEM');
            curl_setopt($this->curl, CURLOPT_SSLKEY, $options['sslkey_path']);
        } else {
            curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 0);
        }

        // Check for files
        if (isset($options['files']) && count($options['files'])) {
            foreach ($options['files'] as $index => $file) {
                $params[$index] = $this->createCurlFile($file);
            }

            version_compare(PHP_VERSION, '5.5', '>') || curl_setopt($this->curl, CURLOPT_SAFE_UPLOAD, false);

            curl_setopt($this->curl, CURLOPT_POST, 1);
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
        } else {
            if (isset($options['json'])) {
                $params = json_encode($params, JSON_UNESCAPED_UNICODE);
                $options['headers'][] = 'content-type:application/json';
            }

            if (!empty($params)) {
                curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
            }
        }

        // Check for custom headers
        if (isset($options['headers']) && count($options['headers'])) {
            curl_setopt($this->curl, CURLOPT_HTTPHEADER, $options['headers']);
        }

        // Check for custom headers
        if (isset($options['timeout'])) {
            curl_setopt($this->curl, CURLOPT_TIMEOUT, $options['timeout']);
        }

        // Check for basic auth
        if (isset($options['auth']['type']) && 'basic' === $options['auth']['type']) {
            curl_setopt($this->curl, CURLOPT_USERPWD, $options['auth']['username'].':'.$options['auth']['password']);
        }

        $response = $this->doCurl();

        // Separate headers and body
        $headerSize = $response['curl_info']['header_size'];
        $header = substr($response['response'], 0, $headerSize);
        $body = substr($response['response'], $headerSize);

        return (object)array(
            'curl_info'    => $response['curl_info'],
            'content_type' => $response['curl_info']['content_type'],
            'status_code'  => $response['curl_info']['http_code'],
            'headers'      => $this->splitHeaders($header),
            'body'         => $body,
        );
    }
410522
private function requestAPI($method, $url, array $options = [])
    {
        try {
            return $this->sendRequest((string)$method, (string)$url, $options);
        } catch (SessionWasExpiredException $e) {
            return $this->sendRequest((string)$method, (string)$url, $options);
        } catch (ClientException $e) {
            throw new BunqException($e);
        }
    }
808153
protected static function staticRequest($method, $url, $params)
    {
        $requestor = new ApiRequestor();
        list($response, $code) = $requestor->request($method, $url, $params);
        return array($response, $code);
    }
1083601
protected function handleRequest($method, $resource, $options)
    {
        $response = null;
        try
        {
            $response = $this->handleResponse($this->getHttpClient()->request($method, $resource, $options));
        }
        catch (RequestException $e)
        {
            $this->handleException($e);
        }

        return $response;
    }
1342406
public function send($method, $uri, array $options = [])
    {
        $this->calls[] = array('send', $method, $uri, $options);

        return new Response();
    }
346183
public function requestRaw(string $url, string $method = 'GET', array $options = [])
    {
        return Response::buildFromPsrResponse($this->request($url, $method, $options, true));
    }
469131
private static function register($method, $url, $callback, $options = [])
    {
        $key = $method.'@'.$url;
        self::$routes[$key] = new Route($method, $url, $callback, $options);
    }
365352
public function put ($method, $options = array (), $options_as_xml = false, $start_tag = false) {
		$req = $this->site . $this->element_name_plural;
        if (isset ($this->_data['id']) && $this->_data['id']) { 
        	$req .= '/' . $this->_data['id'];
        }
        $req .= '/' . $method . '.xml';
		if ($options_as_xml) {
			return $this->_send_and_receive ($req, 'PUT', $options, $start_tag);
		}
		if (count ($options) > 0) {
			$req .= '?' . http_build_query ($options);
		}
		return $this->_send_and_receive ($req, 'PUT');
	}
138019
public function sendRequest(
        MethodInterface $method,
        $requestMethod,
        $url,
        array $options = []
    ) {
        try {
            $response = $this->client->request($requestMethod, $url, $options);
            return json_decode($response->getBody(), true);
        } catch (ClientException $e) {
            throw $this->mapper->get($e, $method);
        } catch (\Exception $e) {
            throw new Exception\UnexpectedError('Unexpected error', $e->getCode(), $e);
        }
    }
150866
public function post($url, $params = array(), $options = array())
    {
        return $this->request($url, self::POST, $params, $options);
    }
1197975
public function requestAsync($method, $uri = '', array $options = []): PromiseInterface
    {
        // Ensure the “X-Request-Id” header gets regenerated for every call.
        $options['headers']['X-Request-Id'] = $this->generateV4GUID();

        return parent::requestAsync($method, $uri, $options);
    }
1004978
public function delete($url, $params = array(), $options = array())
    {
        return $this->request($url, self::DELETE, $params, $options);
    }
1120136
public function get($method, array $params, array $options = array())
    {
        $this->parseOptions($options);

        $params = array_merge($params, $this->apiKeys);

        $response = $this->httpAdapter->getContent(
            sprintf(self::API_ENDPOINT, $this->scheme, $this->outputFormat, $method .'?'. http_build_query($params)),
            $this->headers
        );

        return $this->responseHandler($response);
    }
761350
public function post($url, $params, $options = [], $headers = []) {
        return $this->makeCall('post', $url, $params, $options, $headers);
    }
1354459
protected function _doRequest($method, $url, $data, $options)
    {
        $request = $this->_createRequest(
            $method,
            $url,
            $data,
            $options
        );

        return $this->send($request, $options);
    }
160100
public function request($method, $url, $options)
    {
        $this->_curl = curl_init();
        $this->setUrl($url);
        $this->_setHttpVersionOption();
        $this->setHttpMethodOption($method);
        if (is_array($options) && !empty($options)) {
            self::setOptions($this->_curl, $options);
        }
        return new Response($this->_curl);
    }