private function runRequest($method, $url, $content, $extraHeaders, $cache, $blocking, $options)
    {
        $deferred = new Deferred();

        $key = 'guzzle.'.sha1($url);
        if ($method === 'get' && $this->cache->has($key)) {
            $deferred->resolve($this->cache->get($key));

            return $deferred->promise();
        }

        $headers = [
            'User-Agent' => $this->getUserAgent(),
        ];

        $headers['authorization'] = $this->token;

        $headers = array_merge($headers, $extraHeaders);

        if (! is_null($content)) {
            $headers['Content-Type']   = 'application/json';
            $content                   = json_encode($content);
            $headers['Content-Length'] = strlen($content);
        }

        if ($blocking) {
            $response = $this->driver->blocking($method, $url, $headers, $content);

            return json_decode($response->getBody());
        }

        $this->driver->runRequest($method, $url, $headers, $content, $options)->then(
            function ($response) use ($method, $cache, $key, $deferred) {
                $json = json_decode($response->getBody());

                if ($method === 'get' && $cache !== false) {
                    $this->cache->set($key, $json, $cache === null ? static::CACHE_TTL : (int) $cache);
                }

                $deferred->resolve($json);
            },
            function ($e) use ($deferred, $url) {
                if (! ($e instanceof \Exception)) {
                    if (is_callable([$e, 'getStatusCode'])) {
                        $e = $this->handleError(
                            $e->getStatusCode(),
                            $e->getReasonPhrase(),
                            $e->getBody(),
                            $url
                        );
                    } else {
                        $e = $this->handleError(
                            0,
                            'unknown',
                            'unknown',
                            $url
                        );
                    }
                }

                $deferred->reject($e);
            },
            function ($content) use ($deferred) {
                $deferred->notify($content);
            }
        );

        return $deferred->promise();
    }
private function runRequest($method, $url, $content, $extraHeaders, $cache, $blocking, $options)
    {
        $deferred = new Deferred();

        $key = 'guzzle.'.sha1($url);
        if ($method === 'get' && $this->cache->has($key)) {
            $deferred->resolve($this->cache->get($key));

            return $deferred->promise();
        }

        $headers = [
            'User-Agent' => $this->getUserAgent(),
        ];

        $headers['authorization'] = $this->token;

        $headers = array_merge($headers, $extraHeaders);

        if (! is_null($content)) {
            $headers['Content-Type']   = 'application/json';
            $content                   = json_encode($content);
            $headers['Content-Length'] = strlen($content);
        }

        if ($blocking) {
            $response = $this->driver->blocking($method, $url, $headers, $content);

            return json_decode($response->getBody());
        }

        $this->driver->runRequest($method, $url, $headers, $content, $options)->then(
            function ($response) use ($method, $cache, $key, $deferred) {
                $json = json_decode($response->getBody());

                if ($method === 'get' && $cache !== false) {
                    $this->cache->set($key, $json, $cache === null ? static::CACHE_TTL : (int) $cache);
                }

                $deferred->resolve($json);
            },
            function ($e) use ($deferred, $url) {
                if (! ($e instanceof \Exception)) {
                    if (is_callable([$e, 'getStatusCode'])) {
                        $e = $this->handleError(
                            $e->getStatusCode(),
                            $e->getReasonPhrase(),
                            $e->getBody(),
                            $url
                        );
                    } else {
                        $e = $this->handleError(
                            0,
                            'unknown',
                            'unknown',
                            $url
                        );
                    }
                }

                $deferred->reject($e);
            },
            function ($content) use ($deferred) {
                $deferred->notify($content);
            }
        );

        return $deferred->promise();
    }
private function runRequest ( $ method , $ url , $ content , $ extraHeaders , $ cache , $ blocking , $ options ) { $ deferred = new Deferred ( ) ; $ key = 'guzzle.' . sha1 ( $ url ) ; if ( $ method === 'get' && $ this -> cache -> has ( $ key ) ) { $ deferred -> resolve ( $ this -> cache -> get ( $ key ) ) ; return $ deferred -> promise ( ) ; } $ headers = [ 'User-Agent' => $ this -> getUserAgent ( ) , ] ; $ headers [ 'authorization' ] = $ this -> token ; $ headers = array_merge ( $ headers , $ extraHeaders ) ; if ( ! is_null ( $ content ) ) { $ headers [ 'Content-Type' ] = 'application/json' ; $ content = json_encode ( $ content ) ; $ headers [ 'Content-Length' ] = strlen ( $ content ) ; } if ( $ blocking ) { $ response = $ this -> driver -> blocking ( $ method , $ url , $ headers , $ content ) ; return json_decode ( $ response -> getBody ( ) ) ; } $ this -> driver -> runRequest ( $ method , $ url , $ headers , $ content , $ options ) -> then ( function ( $ response ) use ( $ method , $ cache , $ key , $ deferred ) { $ json = json_decode ( $ response -> getBody ( ) ) ; if ( $ method === 'get' && $ cache !== false ) { $ this -> cache -> set ( $ key , $ json , $ cache === null ? static :: CACHE_TTL : ( int ) $ cache ) ; } $ deferred -> resolve ( $ json ) ; } , function ( $ e ) use ( $ deferred , $ url ) { if ( ! ( $ e instanceof \ Exception ) ) { if ( is_callable ( [ $ e , 'getStatusCode' ] ) ) { $ e = $ this -> handleError ( $ e -> getStatusCode ( ) , $ e -> getReasonPhrase ( ) , $ e -> getBody ( ) , $ url ) ; } else { $ e = $ this -> handleError ( 0 , 'unknown' , 'unknown' , $ url ) ; } } $ deferred -> reject ( $ e ) ; } , function ( $ content ) use ( $ deferred ) { $ deferred -> notify ( $ content ) ; } ) ; return $ deferred -> promise ( ) ; }
Runs http calls.

@param string        $method       The request method.
@param string        $url          The endpoint that will be queried.
@param array         $content      Parameters that will be encoded into JSON and sent with the request.
@param array         $extraHeaders Extra headers to send with the request.
@param bool|int|null $cache        If an integer is passed, used as cache TTL, if null is passed, default TTL is
used, if false, cache is disabled
@param bool          $blocking     Whether the request should be sent as blocking.
@param array         $options      Array of options to pass to Guzzle.

@throws ContentTooLongException
@throws DiscordRequestFailedException
@throws NoPermissionsException
@throws NotFoundException

@return \React\Promise\Promise
Runs http calls .