Uses cURL to communicate with the gateway service

@param string $verb
@param string $endpoint
@param string|null $data
@param array<string,string>|null $queryStringParams

@throws \Exception
@return GatewayResponse
351013
protected function sendRequest(
        $verb,
        $endpoint,
        $data = null,
        array $queryStringParams = null
    ) {
        try {
            $queryString = $this->buildQueryString($queryStringParams);
            $request = curl_init($this->serviceUrl . $endpoint . $queryString);

            $this->headers = array_merge($this->headers, [
                'Content-Type' => sprintf('%s', $this->contentType),
                'Content-Length' => $data === null ? 0 : strlen($data),
            ]);

            $headers = [];
            foreach ($this->headers as $key => $value) {
                $headers[] = $key . ': '. $value;
            }

            curl_setopt($request, CURLOPT_CONNECTTIMEOUT, $this->timeout);
            curl_setopt($request, CURLOPT_TIMEOUT, $this->timeout);
            curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false); //true,);
            curl_setopt($request, CURLOPT_SSL_VERIFYHOST, false); //2,);
            curl_setopt($request, CURLOPT_CUSTOMREQUEST, strtoupper($verb));
            curl_setopt($request, CURLOPT_POSTFIELDS, $data);
            curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($request, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
            // curl_setopt($request, CURLOPT_VERBOSE, true);
            curl_setopt($request, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);

            if (
                $this->curlOptions != null
                && !empty($this->curlOptions)
            ) {
                curl_setopt_array($request, $this->curlOptions);
            }

            $curlResponse = curl_exec($request);
            $curlInfo = curl_getinfo($request);
            $curlError = curl_errno($request);

            $response = new GatewayResponse();
            $response->statusCode = $curlInfo['http_code'];
            $response->rawResponse = $curlResponse;
            return $response;
        } catch (\Exception $e) {
            throw new \Exception(
                "Error occurred while communicating with gateway.",
                $e->getCode(),
                $e
            );
        }
    }
183126
protected function httpRequest($action, $data, $method = 'POST', $options = [ ]) {
        $response = $this->{$this->http_request_type}($action, $data, $method, $options);
        $json = json_decode($response, true);
        if ($json === NULL) {
            throw new Sailthru_Client_Exception(
                "Response: {$response} is not a valid JSON",
                Sailthru_Client_Exception::CODE_RESPONSE_INVALID
            );
        }
        if (!empty($json['error'])) {
            throw new Sailthru_Client_Exception($json['errormsg'], $json['error']);
        }

        return $json;
    }
1363282
public function request(string $verb, string $path, array $query = [], array $options = [])
    {
        $options['query'] = $query;

        if (!empty($options['query']['filter']) && is_array($options['query']['filter'])) {
            // Default to an AND filter.
            $options['query']['filter'] = implode(',', $options['query']['filter']);
        }
        $response = $this->makeRequest($verb, $path, $query, $options);

        return $this->processResponse($response);
    }
470191
protected function sendRequest($verb, $params)
    {
        // Set up the request:
        $this->client->resetParameters(false, false); // keep cookies/auth
        $this->client->setUri($this->baseUrl);

        // Load request parameters:
        $query = $this->client->getRequest()->getQuery();
        $query->set('verb', $verb);
        foreach ($params as $key => $value) {
            $query->set($key, $value);
        }

        // Perform request:
        return $this->client->setMethod('GET')->send();
    }
516590
protected function httpRequest($method, $data)
    {
        $url  = $this->getEndpoint($method);
        $body = http_build_query($data);

        $headers = [
            'Content-Type' => 'application/x-www-form-urlencoded'
        ];

        $response = $this->httpClient->request('POST', $url, $headers, $body)->getBody();

        $payload  = StringUtil::parseFuckStr($response);

        return $payload;
    }
425286
protected function synchronousExecute($method, $verb, array $data = [])
    {
        $request = new Request($method, $verb, [], $this->serialize($data));

        $response = $this->client->send($request);
        return $response;
    }
425214
public function post($endpoint, $data, $options = [])
    {
        if (!is_array($data)) {
            $options['body'] = $data;
        } else {
            $options['form_params'] = $data;
        }

        return $this->request('post', $endpoint, $options);
    }
1147107
protected function getOaiResponse($verb, $params)
    {
        // Debug:
        $this->write(
            "Sending request: verb = {$verb}, params = " . print_r($params, true)
        );

        // Set up retry loop:
        do {
            $result = $this->sendRequest($verb, $params);
            if ($result->getStatusCode() == 503) {
                $delayHeader = $result->getHeaders()->get('Retry-After');
                $delay = is_object($delayHeader)
                    ? $delayHeader->getDeltaSeconds() : 0;
                if ($delay > 0) {
                    $this->writeLine(
                        "Received 503 response; waiting {$delay} seconds..."
                    );
                    sleep($delay);
                }
            } elseif (!$result->isSuccess()) {
                throw new \Exception('HTTP Error ' . $result->getStatusCode());
            }
        } while ($result->getStatusCode() == 503);

        // If we got this far, there was no error -- send back response.
        return $result->getBody();
    }
14155
public function buildUrl($endpoint)
    {
        if (filter_var($endpoint, FILTER_VALIDATE_URL))
        {
            return $endpoint . '.' . $this->dataFormat;
        }

        if (substr($this->url, -1) != '/')
        {
            $this->url = $this->url . '/';
        }

        return $this->url . $endpoint . '.' . $this->dataFormat;
    }
191219
protected function createEndPoint($method, $data = array())
    {
        //create array for api key
        $data['api_token'] = $this->apiKey;
        //make API end point
        $endPoint = $this->url  . '/' . $method . '?' . http_build_query($data);
        //set API endpoint
        $this->setOpt(CURLOPT_URL, $endPoint);
        //return this object
        return $this;
    }
38501
protected function getFromCache($url, array $data, $endpoint)
	{
		$key = $endpoint . $url;
		$key .= http_build_query($data);
		$key = sha1($key);

		return $this->mc->get('jira:cache:' . $key);
	}
766877
public static function request($endpoint)
  {
    return (new Request(NULL, NULL, NULL))->host($endpoint)->get()->path('')->accept('application/json');
  }
406113
protected function request($verb, $path, $resource = '', array $payload = [])
    {
        return $this->client->request($verb, $path, $this->resourceType, $resource, $payload, $this->headers);
    }
970912
protected function sendData($verb, $parameters)
    {
        // Set the endpoint
        $endpoint = $this->buildEndpoint();

        // Set the header
        $this->buildHttpHeader();

        // Send the request
        $client = new Client(); //GuzzleHttp\Client

        $error = true;
        try {

            $response = $client->request($verb, $endpoint, $parameters);

            $error = false;

        } catch (\GuzzleException $e) {
            $this->errorMessage = $e->getResponse()->getBody()->getContents();

        } catch (\GuzzleHttp\Exception\ClientException $e) {
            $this->errorMessage = $e->getResponse()->getBody()->getContents();

        } catch (\GuzzleHttp\Exception\ServerException $e) {
            $this->errorMessage = $e->getResponse()->getBody()->getContents();

        } catch (Exception $e) {
            $this->errorMessage = 'Unknown Exception in Guzzle request';

        }

        return $error ? (! $error) : json_decode($response->getBody(), true);
    }
215610
protected function send($method, $endpoint = '', array $headers = null, $body = null)
    {
        $this->lastResponse = null;
        $url = $this->baseUrl . $endpoint;
        $options = ['headers' => \array_merge($this->defaultHeaders, $headers)];

        if (!empty($body)) {
            $options['body'] = $body;
        }

        $this->lastRequest = $this->httpClient->request(
            $method,
            $url,
            $options
        );

        try {
            $this->lastResponse = $this->httpClient->send($this->lastRequest);
        } catch (\Exception $error) {
            throw new HttpServiceException(
                HttpServiceException::BAD_SERVICE_REQUEST,
                [$error->getMessage()]
            );
        }

        return $this->lastResponse;
    }
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;
    }
902141
protected function createRequest($endpoint, $method, $data = [], $parameters = [])
    {
        $body    = '';
        $url     = $this->url . $endpoint;
        $hasData = !empty($data);

        // Setup authentication.
        $parameters = $this->authenticate($url, $method, $parameters);

        // Setup method.
        $this->setupMethod($method);

        // Include post fields.
        if ($hasData) {
            $body = \json_encode($data);
            \curl_setopt($this->ch, CURLOPT_POSTFIELDS, $body);
        }

        $this->request = new Request(
            $this->buildUrlQuery($url, $parameters),
            $method,
            $parameters,
            $this->getRequestHeaders($hasData),
            $body
        );

        return $this->getRequest();
    }