@param string $collection
@param string $body
@param array  $urlQuery
@param array  $options

@return \frankmayer\ArangoDbPhpCore\Protocols\Http\HttpResponse
517867
public function create($collection = null, $body = null, array $urlQuery = [], array $options = [])
    {

        /** @var AbstractHttpRequest $request */
        $request          = $this->getRequest();
        $request->options = $options;
        $request->body    = $body;

        if (is_array($request->body)) {
            $request->body = json_encode($request->body);
        }

        $request->path = $this->client->fullDatabasePath . static::API_PATH;

        if (null !== $collection) {
            $urlQuery = array_merge(
                $urlQuery ?: [],
                ['collection' => $collection]
            );
        }

        $urlQueryStr = $request->buildUrlQuery($urlQuery);

        $request->path .= $urlQueryStr;

        $request->method = static::METHOD_POST;

        return $this->getReturnObject($request);
    }
1106362
public function searchCollection($query, array $parameters = [], array $headers = [])
    {
        return $this->get('search/collection', array_merge($parameters, [
            'query' => $query
        ], $headers));
    }
842065
protected function perform($method, $url, $body = array(), $query = array(), $headers = array())
    {

        // response data placeholders
        $response = null;
        $responseHeaders = array();

        $logger = $this->getLogger();

        // determine allowed methods
        $methodName = strtoupper($method);

        // query string processing
        $processedUrl = $this->prepareUrl($url, $query);

        try {

            $logger->debug('NEW REQUEST: ' . $methodName . ' ' . $processedUrl);

            if (!in_array($methodName, array(
                'GET', 'POST', 'PUT', 'DELETE', 'HEAD'
            ))
            ) {
                throw new \Exception('Method not supported', HttpException::METHOD_NOT_SUPPORTED);
            }

            // prepare request headers and fields
            $contextParams = array(
                'http' => array(
                    'method' => $methodName,
                    'ignore_errors' => true   // we want to catch output although the error
                ));

            // skip SSL verification
            if($this->skipSsl){
                $contextParams['ssl'] = array(
                    'verify_peer'=>false,
                    'verify_peer_name'=>false
                );
            }

            // inject request parameters
            $this->applyHeaders($contextParams, $headers);
            $json = !empty($headers['Content-Type']) && $headers['Content-Type']=='application/json';
            $this->applyBody($contextParams, $methodName, $body, $json);

            // make request stream context
            $ctx = stream_context_create($contextParams);

            // initialize requests counter
            $counter = self::$retryLimit;

            $response = null;

            // perform request regarding counter limit and quotas
            while ($counter--) {
                try {
                    // pause upon limits exceeding
                    if (isset($responseHeaders['X-Shop-Api-Calls'])) {

                        $calls = $responseHeaders['X-Shop-Api-Calls'];
                        $limit = $responseHeaders['X-Shop-Api-Limit'];

                        if ($limit - $calls == 0) {
                            sleep(1);
                        }
                    }

                    $response = $this->doRequest($processedUrl, $ctx, $responseHeaders, $methodName);

                    break;
                } catch (\Exception $ex) {
                    // server pauses request for X seconds
                    if (!empty($responseHeaders['Retry-After'])) {
                        if ($counter <= 0) {
                            throw new \Exception('Retries count exceeded', HttpException::QUOTA_EXCEEDED);
                        }
                        sleep($responseHeaders['Retry-After']);
                    } else {
                        // other error
                        throw $ex;
                    }
                }
            }

            $parsedPayload = null;
            if ($methodName != 'HEAD') {
                // try to decode response
                if ($responseHeaders['Content-Type'] == 'application/json') {
                    $parsedPayload = @json_decode($response, true);

                    if (!$parsedPayload && !is_array($parsedPayload)) {
                        throw new \Exception('Result is not a valid JSON', HttpException::MALFORMED_RESULT);
                    }

                } else {
                    $parsedPayload = $response;
                }

                $logger->debug('Response body (decoded): ' . var_export($parsedPayload, true));
            }
        }catch(\Exception $ex){

            $message = $ex->getMessage();

            $logger->error(
                $ex->getMessage(), compact('method', 'url', 'query', 'headers', 'body', 'responseHeaders', 'response')
            );

            if($ex instanceof HttpException){
                $response = $ex->getResponse();
                $message = $ex->getMessage();
            }

            throw new HttpException(
                $message, $ex->getCode(), null, $method, $url, $headers, $query, $body, $response, $responseHeaders
            );
        }

        return array(
            'data' => $parsedPayload,
            'headers' => $responseHeaders
        );
    }
175140
public function createCollection($collectionName, array $options = [])
    {
        $this->document = $this->db->getQueryBuilder()->createCollection($collectionName, $options);

        $result = current($this->execute()->toArray());
        return $result['ok'] > 0;
    }
1249794
public function getRequest($method, $url, array $options = [])
    {
        return $this->createRequest($method, $url, null, $options);
    }
1207005
public function query($collectionName, $options = [])
    {
        $databaseName = $this->databaseName === null ? $this->db->defaultDatabaseName : $this->databaseName;

        $token = $this->log(
            'find',
            array_merge(
                [
                    'ns' => $databaseName . '.' . $collectionName,
                    'filter' => $this->document,
                ],
                $options
            ),
            __METHOD__
        );

        $readConcern = $this->getReadConcern();
        if ($readConcern !== null) {
            $options['readConcern'] = $readConcern;
        }

        try {
            $this->beginProfile($token, __METHOD__);

            $query = new \MongoDB\Driver\Query($this->document, $options);
            $this->db->open();
            $cursor = $this->db->manager->executeQuery($databaseName . '.' . $collectionName, $query, $this->getReadPreference());
            $cursor->setTypeMap($this->db->typeMap);

            $this->endProfile($token, __METHOD__);
        } catch (RuntimeException $e) {
            $this->endProfile($token, __METHOD__);
            throw new Exception($e->getMessage(), $e->getCode(), $e);
        }

        return $cursor;
    }
776075
public function post($url, $params = array(), $options = array(), $body = '')
    {
        $client = new \GuzzleHttp\Client($options);
        $query = $this->getQueryParam4AccessToken();
        $response = $client->post($url, array(
            'query' => $query,
            'body' => empty($body) ? json_encode($params, JSON_UNESCAPED_UNICODE) : $body
        ));
        if ($this->isSuccessful($response)) {
            return $this->getJson($response); // $response->json();
        } else {
            throw new Exception("微信服务器未有效的响应请求");
        }
    }
1128559
public function send(string $method, string $url, array $options)
    {
        try {
            // Guzzle overwrites all query string values in the URI if queries are specified
            // in the 'query' option, so they need to be extracted first.
            $optionsPayload = $this->mergeOptions(
                ['query' => $this->parseQueryParams($url)],
                $options
            );

            $response = $this->buildClient()->request($method, $url, $optionsPayload);

            return $this->buildResponse($response);
        } catch (GuzzleException $exception) {
            // No "custom" exceptions, just rethrow whatever guzzle spits out.
            throw $exception;
        }
    }
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);
    }
34343
protected function doFindAndRemove(array $query, array $options = array())
    {
        $document = parent::doFindAndRemove($query, $options);

        if (isset($document)) {
            // Remove the file data from the chunks collection
            $this->riakCollection->chunks->remove(array('files_id' => $document['_id']), $options);
        }

        return $document;
    }
626080
public function get($url, $params = array(), $options = array())
    {
        return $this->request($url, self::GET, $params, $options);
    }
367035
public function buildRequestParts(
        string $url,
        array $query = [],
        array $body = [],
        array $server = []
    ): RequestParts {
        $url = trim($url, '/');
        $url = trim("{$this->version}/$url", '/');
        $url = $this->buildUrlParams($url, $query);

        return new RequestParts(
            $url,
            [
                'json' => $body,
                'headers' => $server,
            ],
            [
                'decode_content' => 'gzip',
            ]
        );
    }
30018
public function listDocuments($collection, array $options = [])
    {
        $this->setOptions($options);
        $doc = new Document($this->client, $this->database, $collection);
        $doc->setHeaders($this->getHeaders());
        $rs = $doc->getAll();
        $this->checkResponse($rs);
        unset($rs['_curl_info']);

        return $rs;
    }
800246
public function send(string $method, string $url, array $options): HttpResponse
    {
        try {
            return new HttpResponse($this->buildClient()->request($method, $url, $this->mergeOptions([
                'query' => $this->parseQueryParams($url),
            ], $options)));
        } catch (\GuzzleHttp\Exception\ConnectException $e) {
            throw new Exceptions\ConnectionException($e->getMessage(), 0, $e);
        }
    }
976426
public function execute($entity, $method = 'get', $options = [])
    {

        $this->cleanQueryParams($entity);
        $configuration = $this->_getEntityConfiguration($entity);

        if ($method != 'get'){
            foreach ($configuration->attributes as $key => $attribute) {
                $this->validateAttribute($entity, $key, ['required']);
            } 
        }

        $this->processOptions($options, $configuration);

        $this->_setDefaultHeaders($configuration->query);
        $this->_setCustomHeaders($entity, $configuration->query);
        //$this->_setIdempotencyHeader($configuration->query, $configuration, $method);
        $this->setQueryParams($entity);
        
        return $this->_client->{$method}($configuration->url, $configuration->query);
    }
895586
public function update(array $query, array $newObject, array $options = array())
    {
        return $this->getCollection()->update($query, $newObject, $options);
    }
361837
public function request($method, $url, $body = null, $headers = [], $options = [])
    {
        if (is_array($url)) {
            if (count($url) > 1) {
                $uri = $url[0];
                unset($url[0]);
                $url = $uri . (strpos($uri, '?') !== false ? '&' : '?') . http_build_query($url);
            } else {
                $url = $url[0];
            }
        }

        if (preg_match('/^http(s)?:\/\//i', $url) !== 1) {
            throw new NotSupportedException(['only HTTP requests can be handled: `:url`', 'url' => $url]);
        }

        if (is_string($headers)) {
            $headers = [strpos($headers, '://') ? 'Referer' : 'User-Agent' => $headers];
        }

        if (isset($headers['-'])) {
            $headers['Referer'] = $headers['-'];
            unset($headers['-']);
        }

        if (isset($headers['Referer'])) {
            if (is_array($headers['Referer'])) {
                $referer = $headers['Referer'];
                if (isset($referer[0])) {
                    $str = $referer[0];
                    unset($referer[0]);
                } else {
                    $str = 'http://TRACK/';
                }
                $headers['Referer'] = $str . (strpos($str, '?') ? '&' : '?') . http_build_query($referer);
            } elseif (!strpos($options['Referer'], '://')) {
                $headers['Referer'] = 'http://TRACE/' . $headers['Referer'];
            }
        }

        if (!isset($headers['User-Agent'])) {
            $headers['User-Agent'] = self::USER_AGENT_IE;
        }

        if (is_int($options) || is_float($options)) {
            $options = ['timeout' => $options];
        }

        if (!isset($options['timeout'])) {
            $options['timeout'] = $this->_timeout;
        }

        if ($this->_proxy && !isset($options['proxy'])) {
            $options['proxy'] = $this->_proxy;
        }

        if ($this->_cafile && !isset($options['cafile'])) {
            $options['cafile'] = $this->_cafile;
        }

        $options['verify_peer'] = $this->_verify_peer;

        $request = new Request();
        $request->method = $method;
        $request->url = $url;
        $request->headers = $headers;
        $request->body = $body;
        $request->options = $options;

        $this->logger->debug($request, 'httpClient.request');

        $this->eventsManager->fireEvent('httpClient:beforeRequest', $this, $request);
        $response = $this->do_request($request);
        if (strpos($response->content_type, '/json') !== false && $json = json_decode($response->body, true)) {
            $response->body = $json;
        }
        $this->eventsManager->fireEvent('httpClient:afterRequest', $this, $response);
        $response->request = $request;
        $response->user_data = isset($options['user_data']) ? $options['user_data'] : null;

        $this->logger->debug($response, 'httpClient.response');

        if ($response->http_code === 429) {
            throw new TooManyRequestsException($response->url, $response);
        } elseif ($response->http_code === 403) {
            throw new ForbiddenException($response->url, $response);
        } elseif ($response->http_code === 401) {
            throw new UnauthorizedException($response->url, $response);
        }

        if ($response->http_code >= 500) {
            throw new ServiceUnavailableException(['service is unavailable: :http_code => `:url`',
                'http_code' => $response->http_code,
                'url' => $response->url], $response);
        }

        if ($response->http_code >= 400) {
            throw new BadRequestException(['bad request: :http_code => `:url`', 'http_code' => $response->http_code, 'url' => $response->url], $response);
        }

        return $response;
    }