Append the request to the batch-part

@param mixed $method  - The method of the request (GET, POST...)
@param mixed $request - The request that will get appended to the batch

@return HttpResponse

@throws \ArangoDBClient\ClientException
513588
public function append($method, $request)
    {
        preg_match('%/_api/simple/(?P<simple>\w*)|/_api/(?P<direct>\w*)%ix', $request, $regs);

        if (!isset($regs['direct'])) {
            $regs['direct'] = '';
        }
        $type = $regs['direct'] !== '' ? $regs['direct'] : $regs['simple'];

        if ($method === 'GET' && $type === $regs['direct']) {
            $type = 'get' . $type;
        }

        if (null === $this->_nextBatchPartId) {
            if (is_a($this->_batchParts, \SplFixedArray::class)) {
                $nextNumeric = $this->_nextId;
                $this->_nextId++;
            } else {
                $nextNumeric = count($this->_batchParts);
            }
            $batchPartId = $nextNumeric;
        } else {
            $batchPartId            = $this->_nextBatchPartId;
            $this->_nextBatchPartId = null;
        }

        $eol = HttpHelper::EOL;

        $result = 'HTTP/1.1 202 Accepted' . $eol;
        $result .= 'location: /_db/_system/_api/document/0/0' . $eol;
        $result .= 'content-type: application/json; charset=utf-8' . $eol;
        $result .= 'etag: "0"' . $eol;
        $result .= 'connection: Close' . $eol . $eol;
        $result .= '{"error":false,"_id":"0/0","id":"0","_rev":0,"hasMore":1, "result":[{}], "documents":[{}]}' . $eol . $eol;

        $response  = new HttpResponse($result);
        $batchPart = new BatchPart($this, $batchPartId, $type, $request, $response, [
            'cursorOptions'  => $this->_batchPartCursorOptions,
            '_documentClass' => $this->_documentClass,
        ]);

        $this->_batchParts[$batchPartId] = $batchPart;

        $response->setBatchPart($batchPart);

        return $response;
    }
88997
public function get($method, $data = array())
    {
        //set cURL transfer option for get request
        // and get ouput
        return $this->createEndPoint($method, $data)
                    ->setOpt(CURLOPT_CUSTOMREQUEST, 'GET')
                    ->setopt(CURLOPT_HTTPGET, true)
                    ->exec();
    }
260865
public function request(string $method, ...$params) : ResponseInterface
    {
        try {
            $response = $this->client
                ->post($this->path, $this->makeJson($method, $params));

            if ($response->hasError()) {
                // throw exception on error
                throw new BadRemoteCallException($response);
            }

            return $response;
        } catch (Throwable $exception) {
            throw exception()->handle($exception);
        }
    }
456676
protected function makeRequest($endpoint = null, $method, $params)
    {
        $endpoint = $endpoint ?: $this->getEndpoint();

        // Prepend relationship, if one exists.
        if (static::getParentID()) {
            $params = array_merge([
                static::getParentID()
            ], $params);
        }

        $results = call_user_func_array([static::$client->$endpoint(), $method], $params);

        // Set errors from server...if any
        $this->messageBag = static::$client->errors();

        return $results;
    }
223650
protected function doRequest($request)
    {
        if (!$this->firstRequest) {
            $this->initialize($request);
        }
        $this->firstRequest = false;

        $this->applyBindings();
        $this->applyContextualBindings();
        $this->applyInstances();
        $this->applyApplicationHandlers();

        $request = Request::createFromBase($request);
        $response = $this->kernel->handle($request);

        $method = new \ReflectionMethod(get_class($this->app), 'callTerminableMiddleware');
        $method->setAccessible(true);
        $method->invoke($this->app, $response);

        return $response;
    }
741514
public function request(string $method, string $url): Response
    {
        return $this->client->request($method, $url, $this->options);
    }
510489
protected function sendRequest(string $method = 'PURGE', string $uri, array $headers = [])
    {
        $client = new Client([
            'base_uri' => self::API_ENDPOINT,
            'headers'  => array_merge($headers, [
                'Content-Type' => 'application/json',
                'Fastly-Key'   => $this->apiToken
            ])
        ]);

        // Prepend the service endpoint
        if (in_array($method, ['POST','GET'])) {
            $uri = "service/{$this->serviceId}/{$uri}";
        }

        try {

            $client->request($method, $uri);

        } catch (BadResponseException $e) {

            throw FastlyApiException::create(
                $e->getRequest(),
                $e->getResponse()
            );
        }

        return true;
    }
1035901
public function request($method, array $params = [])
    {
        $client = new \GuzzleHttp\Client();

        $multipartParams = [];
        foreach ($params as $key => $value) {
            $multipartParams[] = [
                'name' => $key,
                'contents' => is_scalar($value) ? (string)$value : $value
            ];
        }

        try {
            $response = $client->post($this->getUrl($method), [
                'verify' => false,
                'multipart' => $multipartParams ?: null
            ]);
            $response = json_decode($response->getBody());

            if ($response === null) {
                throw new HttpRuntimeException('Empty response.');
            }
            return new Response($response->ok, $response->result);
        } catch (ClientException $e) {
            $response = json_decode($e->getResponse()->getBody()->getContents());
            return new Response($response->ok, null, $response->error_code, $response->description);
        } catch (ServerException $e) {
            return new Response(false, null, $e->getResponse()->getStatusCode(), $e->getResponse()->getReasonPhrase());
        }
    }
694433
protected function request($url, $method = 'GET', array $params = array())
    {
        $this->client->setEventDispatcher($this->getEventDispatcher());
        $this->client->activatePlugins($this->registerPlugins);

        $response = $this->client->request($method, $url, $params);
        return $response;
    }
1275005
public function method($method)
    {
        $method  = strtolower($method);
        $builder = new RequestBuilder([
            'domain' => $this->domain,
            'basePath' => $this->basePath,
            'method' => $method,
            'guzzleOptions' => $this->guzzleOptions,
            'returnType' => $this->returnType,
        ]);
        $builder->withHeaders($this->headers);

        if (in_array($method, [ 'patch', 'post', 'put' ])) {
            $builder->withHeader(new ContentType('application/json'));
        }

        return $builder;
    }
132425
public function request($method, $uri, array $parameters = [], array $options = [])
    {
        $parameters['key'] = $this->apiKey;
        $options['query'] = $parameters;

        $uri = $this->apiUrl.$uri.'/json';

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

        $result = $this->decoder->decode($response);

        if (!isset($result['status'])) {
            throw new ClientErrorException('Missing return status');
        }

        if (!in_array($result['status'], [
                'OK',
                'ZERO_RESULTS',
            ], true)) {
            throw new ClientErrorException(sprintf('Invalid return status "%s"', $result['status']));
        }

        return $result;
    }
800920
public function call($method, $params = [])
    {
        if (null === $this->client) {
            $this->client = new Client([
                'base_uri' => static::API_URL,
                'content-type' => 'application/json',
            ]);
        }

        $requestParams = array_merge($this->defaultParams, [
            $method => [$params],
        ]);

        if ($this->sandbox) {
            $requestParams['apikey'] = self::SANDBOX_KEY;
        }

        $response = $this->client->post(null, ['body' => json_encode($requestParams)]);
        if ($response->getStatusCode() != 200) {
            throw new \Exception('Api http error: ' . $response->getStatusCode(), $response->getStatusCode());
        }

        $result = json_decode($response->getBody(), true);
        if (isset($result['error'])) {
            throw new \BadMethodCallException('Api error: ' . $result['error']['description'],
                $result['error']['code']);
        }

        return $result;
    }
723925
public function handle(string $method, $body = false, $uriAppend = false, array $queryParams = [])
    {
        $clientBuilder = new ClientBuilder();
        $url           = HttpHelper::setHttPortToUrl($this->client->getGatewayUrl(), false) . '/' . $this->resource->getVersion() . '/' . $this->resource->getURI();
        $client = $clientBuilder->setConnectionParams(['client' => ['headers' => $this->setAuthorization()]])
                                ->setHosts(['host' => $url])
                                ->build();

        try {

            $size = $queryParams['body']['size'] ?? 0;
            $from = $queryParams['body']['from'] ?? 0;

            $response = new ElasticSearchResponse($this->multi ? $client->msearch($queryParams) : $client->search($queryParams), $this->multi, $size, $from);
        } catch (\Exception $ex) {
            $error = json_decode($ex->getMessage());
            throw new \Exception($error->error->reason ?? $ex->getMessage());
        }

        return $response;
    }
583487
public function appendMethod($method) {
    if (is_string($method)) {
      $method = InterfaceMethodNode::create($method);
    }
    $this->statements->lastChild()->before($method);
    FormatterFactory::format($this);
    return $this;
  }
1079205
private function handleRequest(MethodInterface $method)
    {
        $result = $this->client->sendRequest(
            $method,
            $method->getMethod(),
            $method->getAction(),
            $this->getOptions($method)
        );

        if ($method instanceof MethodResultCollectionInterface) {
            return $this->mapper->mapCollection($result, $method);
        }

        return $this->mapper->map($result, $method->createResultObject());
    }
1143802
protected function request($method, $param = array(), $catchException = true)
    {
        if (!$this->session) {
            $this->login();
        }
        $this->lastException = null;
        try {

            // add as first parameter the session
            array_unshift($param, $this->session);
            $response = call_user_func_array(array($this->soapClient, $method), $param);
        } catch (\SoapFault $e) {
            if ($catchException) {
                $this->lastException = $e;

                return false;
            } else {
                throw $e;
            }
        }

        return $response;
    }
1018549
private function createRequest($method, array $payload)
    {
        $request = new Request(
            'POST',
            self::API_BASE_URL . $method,
            ['Content-Type' => 'application/x-www-form-urlencoded'],
            http_build_query($payload)
        );

        return $request;
    }