Create a request.

@param string $uri URI as a string.
@param string $method Request method.
@param array $queryOrData Query (GET) or data (POST/PUT/DELETE/PATCH).
@return \self The request.
489062
public static function create($uri, $method = 'GET', array $queryOrData = [])
    {
        $method = strtoupper($method);
        $query = [];
        $data = [];
        switch ($method) {
            case 'POST':
            case 'PUT':
            case 'DELETE':
            case 'PATCH':
                $data = $queryOrData;
                break;
            default:
                $query = $queryOrData;
                break;
        }
        return new self(new Uri($uri), $method, $query, $data);
    }
1320552
protected function filterRequest($uri, $method)
    {
        if (!empty($filtersPattern = $this->filter[$uri][$method])) {

            $filters = explode('|', $filtersPattern);

            foreach ($filters as $filter) {

                list($className, $params) = $this->getClassNameWithParams($filter);

                $name = app()->getNamespace() . 'Filters\\' . $className;

                $instance = $this->container->make($name);

                $filterResponse = call_user_func_array([$instance, 'handle'], $params);

                if(!$filterResponse instanceof Request) {
                    return $filterResponse;
                }
            }
        }
    }
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;
    }
65056
protected function createRequest($client, $method, $uri = '', array $parameters = [])
    {
        /**
         * @see \JonnyW\PhantomJs\Http\Request
         **/
        $request = $client->getMessageFactory()->createRequest($uri, $method);
        $request->addHeader(
            'User-Agent',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0'
        );

        $request->addHeader(
            'Content-Type',
            'application/x-www-form-urlencoded'
        );

        if (isset($parameters['form_params'])) {
            $request->setRequestData($parameters['form_params']);
        }

        return $request;
    }
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;
    }
489484
public function requestAsync($method, $uri = null, array $options = [])
    {
        return $this->doRequest($method, $uri, $options, true);
    }
1213209
protected function makeRequest($method, $uri, $parameters = [], $cookies = [], $files = [])
    {
        $uri = $this->prepareUrlForRequest($uri);

        $this->call($method, $uri, $parameters, $cookies, $files);

        $this->clearInputs()->followRedirects()->assertPageLoaded($uri);

        $this->currentUri = $this->app->make('request')->fullUrl();

        $this->crawler = new Crawler($this->response->getContent(), $this->currentUri);

        return $this;
    }
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;
    }
913867
public function request($method, $uri, array $parameters = [])
    {
        return $this->container->get(AdapterInterface::class)
            ->request($method, $uri, $parameters);
    }
1080465
protected HttpRequest createHttpRequest(URI uri, HttpMethod method) {
        HttpRequest request = new HttpRequest();
        request.setUri(uri);
        request.setMethod(method);

        // Set authorization header
        request.setHeaders(createHeaders());

        return request;
    }
695782
protected function _doRequest($method, $uri, $options)
    {
        // For Guzzle5 we cannot have any options that are not pre-defined,
        // so instead we put it in the config array
        if (isset($options[self::OPT_VIDEO_MANAGER_ID])) {
            $options['config'][self::OPT_VIDEO_MANAGER_ID] = $options[self::OPT_VIDEO_MANAGER_ID];
            unset($options[self::OPT_VIDEO_MANAGER_ID]);
        }

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

        return $this->httpClient->send($request);
    }
937903
private function getNewRequest(string $method, UriInterface $uri): RequestInterface
    {
        return $this->transport->createRequest($method, $uri);
    }
314386
protected function createRoute($methods, $uri, $action)
    {
        $route = parent::createRoute($methods, $uri, $action);
        if (! empty($this->groupStack)) {
            $route = $this->mergePriority($route);
        }

        return $route;
    }
1126803
public function request($method, $uri, array $options = []) {
      $apiToken = $this->addTokens();
      try {
         $options['headers']['Content-Type'] = "application/json";
         $sessionHeaders = [];
         if ($apiToken) {
            if (key_exists('Session-Token', $apiToken) && $apiToken['Session-Token']) {
               $sessionHeaders['Session-Token'] = $apiToken['Session-Token'];
            }
            if (key_exists('App-Token', $apiToken) && $apiToken['App-Token']) {
               $sessionHeaders['App-Token'] = $apiToken['App-Token'];
            }
         }
         $options = array_merge_recursive($options, ['headers' => $sessionHeaders]);
         $response = $this->httpClient->request($method, $this->url . $uri, $options);
         return $response;
      } catch (ClientException $e) {
         $response = $e->getResponse();
         /*$body = $response->getBody()->getContents();
         $reasonPhrase = $response->getReasonPhrase() . (($body) ? ' ' . $body : '');*/
         return $response;
      } catch (RequestException $e) {
         $hasResponse = $e->hasResponse();
         $statusCode = ($hasResponse) ? $e->getResponse()->getStatusCode() : '500';
         $contents = ($hasResponse) ? $e->getResponse()->getReasonPhrase() : 'Request Error';
         throw new Exception($contents, $statusCode);
      }
   }
1364722
private function request($method, $uri, $body = array())
    {
        try {
            $res = $this->client->request($method, $uri, $body);
            return json_decode($res->getBody());
        } catch(RequestException $e){
            $res = VariableUtil::json2Array(
                json_decode($e->getResponse()->getBody()->getContents())[0]
            );
            /*
             * If the session expired, then we must request a new token with the
             * refresh token.
             */
            if(isset($res['errorCode']) && $res['errorCode'] == 'INVALID_SESSION_ID'){
                $this->refreshToken($method, $uri, $body);
            } else {
                throw new ExternalApiException($e->getMessage(), $e->getCode(), $e);
            }
        }
    }
1154221
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
    {
        $request = parent::write($method, $uri, $http_ver, $headers, $body);
        $this->log("\n\n" . $request);
        return $request;
    }
1219259
public static function createRequest($method, $uri)
    {
        if (! static::$requestFactory) {
            static::$requestFactory = new RequestFactory();
        }

        return static::$requestFactory->createRequest($method, $uri);
    }