Send the actual request to the connect endpoint
@param string $verb
@param string $path
@param null|Model|string $body
@return string
@throws GuzzleException
481328
public function sendRequest($verb, $path, $body = null)
    {
        $this->logger->info('Module: ' . __CLASS__);

        if ($body instanceof Model) {
            $body = $body->toJSON(true);
        }

        $headers = [
            'Authorization' => 'ApiKey ' . $this->config->apiKey,
            'Request-ID' => uniqid('api-request-'),
            'Content-Type' => 'application/json',
        ];

        $this->logger->info('HTTP Request: ' . strtoupper($verb) . ' ' . $this->config->apiEndpoint . $path);
        $this->logger->debug("Request Headers:\n" . print_r($headers, true));

        if (isset($body)) {
            $this->logger->debug("Request Body:\n" . $body);
        }

        $response = $this->http->request(strtoupper($verb), trim($this->config->apiEndpoint . $path), [
            'body' => $body,
            'headers' => $headers
        ]);

        $this->logger->info('HTTP Code: ' . $response->getStatusCode());

        return $response->getBody()->getContents();
    }
337204
private function createRequest($path, $method, $parameters = [], $headers = [], $body)
    {
        $request =  new Request();

        $request
            ->setPath($path)
            ->setMethod($method)
            ->setParameters(new ParameterBag((array) $parameters))
            ->setHeaders(new ParameterBag((array) $headers))
            ->setBody($body)
            ->setOptions(new ParameterBag((array) $this->options))
        ;

        return $this->lastRequest = $request;
    }
1008515
protected function httpPatch(string $path, $body, array $requestHeaders = []): ResponseInterface
    {
        $requestHeaders['Content-Type'] = 'application/json';

        return $response = $this->httpClient->sendRequest(
            $this->requestBuilder->create('PATCH', $path, $requestHeaders, json_encode($body))
        );
    }
741117
public function send(string $method, string $path)
    {
        //extract the meta data
        $data = $this->data;
        $query = $this->query;
        $agent = $this->meta['agent'];
        $headers = $this->headers;

        //permutation groups
        $postable = $method === CurlHandler::METHOD_POST || $method === CurlHandler::METHOD_PUT;
        $custom = $method != CurlHandler::METHOD_GET && $method != CurlHandler::METHOD_POST;

        //resolve the data
        //if the method is a put or post
        if ($postable) {
            //figure out how to encode it
            switch ($this->meta['request']) {
                case CurlHandler::ENCODE_JSON:
                    $data = json_encode($data);
                    break;
                case CurlHandler::ENCODE_QUERY:
                default:
                    $data = http_build_query($data);
                    break;
            }
        //it's a get or delete
        } else {
            //let the data be the query
            $query = array_merge($data, $query);
        }

        //form the url
        $url = $this->host . $path;

        //if we have a query
        if (!empty($query)) {
            //add it on to the url
            $url .= '?' . http_build_query($query);
        }

        // send it into curl
        $request = CurlHandler::i($this->map)
            ->setUrl($url)
            // sets connection timeout to 10 sec.
            ->setConnectTimeout(10)
            // sets the follow location to true
            ->setFollowLocation(true)
            // set page timeout to 60 sec
            ->setTimeout(60)
            // verifying Peer must be boolean
            ->verifyPeer(false)
            //if the agent is set
            ->when($agent, function () use ($agent) {
                // set USER_AGENT
                $this->setUserAgent($agent);
            })
            //if there are headers
            ->when(!empty($headers), function () use ($headers) {
                // set headers
                $this->setHeaders($headers);
            })
            //set the custom request
            ->when($custom, function () use ($method) {
                $this->setCustomRequest($method);
            })
            //when post or put
            ->when($postable, function () use ($data) {
                if (empty($data)) {
                    return;
                }

                //set the post data
                $this->setPostFields($data);
            });

        //how should we return the data ?
        switch ($this->meta['response']) {
            case CurlHandler::ENCODE_QUERY:
                $response = $request->getQueryResponse(); // get the query response
                break;
            case CurlHandler::ENCODE_JSON:
                $response = $request->getJsonResponse(); // get the json response
                break;
            case CurlHandler::ENCODE_XML:
                $response = $request->getSimpleXmlResponse(); // get the xml response
                break;
            case CurlHandler::ENCODE_RAW:
            default:
                $response = $request->getResponse(); // get the raw response
                break;
        }

        //reset paths
        $this->paths = [];

        return $response;
    }
47064
public function send(
        string $route,
        array $path = [],
        array $query = [],
        array $headers = []
    ) {
        $request = $this->requestStack->getCurrentRequest();
        $headers = array_merge(null === $request ? [] : $request->headers->all(), $headers);

        $response = $this->producer->send(
            $this->requestService->create($route, $path, $query, $headers, $this->method)
        );

        $this->method = 'GET';

        return $response;
    }
593798
public function request($verb, $params = [])
    {
        $xml = $this->getOaiResponse($verb, $params);
        return $this->responseProcessor
            ? $this->responseProcessor->process($xml) : $xml;
    }
93605
public function withVerbs(string ...$verbs): RouteInterface
    {
        foreach ($verbs as &$verb) {
            $verb = strtoupper($verb);
            if (!in_array($verb, RouteInterface::VERBS)) {
                throw new RouteException("Invalid HTTP verb `{$verb}`.");
            }

            unset($verb);
        }

        $route = clone $this;
        $route->verbs = $verbs;

        return $route;
    }
177615
public function request($method, $path, $paramData)
    {
        if($method == 'get' && count($paramData) > 0) {
            $path = $path . '?' . http_build_query($paramData);
            $paramData=array();
        }
        $this->setSignature($path, $paramData);
        $req = $this->client->createRequest($method, $path, array());
        if($method == 'post' || $method == 'delete') {
            foreach ($paramData as $k => $v) {
                $req->setPostField($k, $v);
            }
        }
        try {
            $res = $req->send();
            return $res->json();
        } catch (\Guzzle\Common\Exception\RuntimeException $e) {
            echo $e->getResponse()->getBody();
        }
    }
409456
public function call($verb, $endpoint, $options = [])
    {
        if ($this->validMethod($verb)) {
            // Get the headers and body from the options.
            $headers = isset($options['headers']) ? $options['headers'] : [];
            $body = isset($options['body']) ? $options['body'] : null;
            $pv = isset($options['protocol_version']) ? $options['protocol_version'] : '1.1';
            // Make the request.
            $request = new Request($verb, $endpoint, $headers, $body, $pv);
            // Save the request as the last request.
            $this->last_request = $request;
            // Send it.
            $response = $this->client->send($request, $options);
            if ($response instanceof ResponseInterface) {
                // Set the last response.
                $this->last_response = $response;
                // If the caller wants the raw response, give it to them.
                if (isset($options['parse_response']) && $options['parse_response'] === false) {
                    return $response;
                }
                $parsed_response = $this->parseResponse($response);
                return $parsed_response;
            } else {
                // This only really happens when the network is interrupted.
                throw new BadResponseException('A bad response was received.',
                    $request);
            }
        } else {
            throw new \Exception('Unrecognised HTTP verb.');
        }
    }
469961
public function request($path, $body, $httpMethod = 'GET', array $headers = [], array $options = [])
	{
		$request = $this->createRequest($httpMethod, $path, $body, $headers);

		try {
			$response = $this->client->send($request, $options);
		} catch (\LogicException $e) {
			throw new \ErrorException($e->getMessage(), $e->getCode(), $e);
		} catch (\RuntimeException $e) {
			throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
		}

		$this->lastRequest  = $request;
		$this->lastResponse = $response;

		return $response;
	}
406113
protected function request($verb, $path, $resource = '', array $payload = [])
    {
        return $this->client->request($verb, $path, $this->resourceType, $resource, $payload, $this->headers);
    }
425286
protected function synchronousExecute($method, $verb, array $data = [])
    {
        $request = new Request($method, $verb, [], $this->serialize($data));

        $response = $this->client->send($request);
        return $response;
    }
1372320
protected function httpPostRaw(string $path, $body, array $requestHeaders = []): ResponseInterface
    {
        return $response = $this->httpClient->sendRequest(
            $this->requestBuilder->create('POST', $path, $requestHeaders, $body)
        );
    }
596691
protected function createRequest(string $verb, string $route, $body = [], $headers = [])
    {
        $url = Router::getRouteUrl($route);

        if (strtoupper($verb) === 'GET') {
            $url .= '?' . http_build_query($body);
        }

        $request = new Request($verb, $url, $this->mergeDefaultHeaders($headers), json_encode($body));

        $this->setRequest($request);

        return $request;
    }
905715
private function request($path = 'post/index.json', $method = 'GET', array $data = null, array $options = null, $class = null)
    {
        if (empty($path)) {
            throw new \InvalidArgumentException('Argument "path" cannot be empty');
        }

        if (strtoupper($method) === 'GET') {
            $request_options = ['query' => $data];
        } elseif (strtoupper($method) === 'POST') {
            $request_options = $this->prepareRequestParams($data);
        } else {
            throw new \InvalidArgumentException('Unsupported request method');
        }

        ($this->progress_handler !== null && is_callable($this->progress_handler)) && $request_options['progress'] = $this->progress_handler;
        ($this->debug_log_handler !== null && is_callable($this->debug_log_handler)) && $request_options['debug'] = $this->createDebugStream();

        if (is_array($options)) {
            $request_options = array_replace_recursive($request_options, $options);
        }

        try {
            $response = $this->client->request($method, $path, $request_options);
            $raw_result = (string)$response->getBody();
            $result = json_decode($raw_result, true);

            if (!is_array($result)) {
                if ($this->throw_exceptions === true) {
                    throw new E621Exception(E621Exception::MESSAGE_DATA_INVALID, 0, null, $response);
                } else {
                    $result = [
                        'reason' => E621Exception::MESSAGE_DATA_INVALID,
                        'error'  => 'Response couldn\'t be decoded into array',
                    ];
                }
            }
        } catch (GuzzleConnectException $e) {
            if ($this->throw_exceptions === true) {
                throw new ConnectException($e);
            } else {
                $result = [
                    'reason' => ConnectException::MESSAGE,
                    'error'  => $e->getMessage(),
                ];
            }
        } catch (RequestException $e) {
            $response = $e->getResponse();
            $this->debugLog($e);

            if ($response !== null && $response->getBody() !== null) {
                $raw_result = (string)$response->getBody();
                $result = json_decode($raw_result, true);

                if (!is_array($result)) {
                    $result = 'Request resulted in a `' . $e->getResponse()->getStatusCode() . ' ' . $e->getResponse()->getReasonPhrase() . '` response';

                    if ($this->throw_exceptions === true) {
                        throw new E621Exception($result, 0, $e, $response);
                    }

                    $result = [
                        'reason' => ConnectException::MESSAGE,
                        'error'  => $result,
                    ];
                }
            } else {
                if ($this->throw_exceptions === true) {
                    throw new E621Exception(E621Exception::MESSAGE_REQUEST_ERROR, 0, $e, $response);
                } else {
                    $result = [
                        'reason' => ConnectException::MESSAGE,
                        'error'  => $e->getMessage(),
                    ];
                }
            }
        } catch (GuzzleException $e) {
            if ($this->throw_exceptions === true) {
                throw new E621Exception(E621Exception::MESSAGE_CLIENT_ERROR, 0, $e);
            } else {
                $result = [
                    'reason' => E621Exception::MESSAGE_CLIENT_ERROR,
                    'error'  => $e->getMessage(),
                ];
            }
        } finally {
            $this->endDebugStream();
        }

        // Search for result class if we don't have one, this shouldn't happen but fail safe should be left anyway
        if (empty($class)) {
            $class = Generic::class;
            $method_config = Methods::lookupByPath($path);

            if ($method_config !== null) {
                $class = $method_config['class'];
            }
        }

        /** @noinspection PhpUndefinedVariableInspection */
        return new Response($class, $result, isset($raw_result) ? $raw_result : null);
    }
354092
public function request($endpoint, $verb = 'GET', $params = [], $data = null)
    {
        $context = $this->getStreamContext($verb);
        if ($data) {
            stream_context_set_option($context, array('http' => array('content' => json_encode($data))));
        }

        $query = http_build_query($params);
        $base = $this->getConfig()->getServer().$endpoint;
        $url = $base;

        if (!empty($query)) {
            $parsed = parse_url($base);
            if (key_exists('query', $parsed) || substr($base, -1) == "?") {
                $url .= '&'.$query;
            } else {
                $url .= '?'.$query;
            }
        }

        $handle = fopen($url, 'r', false, $context);
        if ($handle === false) {
            $e = error_get_last();
            throw new \Exception($e['message'], $e['type']);
        }
        $response = stream_get_contents($handle);
        fclose($handle);

        $response = json_decode($response, true);

        return $response;
    }
330011
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
		$params = $params ?? [];
		$method = strtoupper($method);
		$token  = $this->storage->getAccessToken($this->serviceName);

		if($token->isExpired()){
			$token = $this->refreshAccessToken($token);
		}

		if(!isset($params['fmt'])){
			$params['fmt'] = 'json';
		}

		if(in_array($method, ['POST', 'PUT', 'DELETE']) && !isset($params['client'])){
			$params['client'] = $this->options->user_agent;
		}

		$headers = array_merge($this->apiHeaders, $headers ?? [], ['Authorization' => 'Bearer '.$token->accessToken]);

		return parent::request(explode('?', $path)[0], $params, $method, $body, $headers);
	}