Validate request and return the values.

@param mixed $response
@param string $method
@param array $params
@return bool|object
@throws InvalidResponseException
428098
private function _finishResponse($response, string $method, array $params)
    {
        $valid = $this->_isValidResponse($response);

        if ($valid === true) {
            if (isset($response->value)) {
                return $response->value;
            } else {
                return $response;
            }
        } else {
            throw new InvalidResponseException($valid . ' (' . $this->_parseUrl($method, $params) . ')');
        }
    }
151415
public function handle(Response $response, $method = null, $mime = null) {
    if (empty($method) || !method_exists($this, $method)) {
      return $this->_parse($response, $mime);
    }
    return $this->$method($response, $mime);
  }
437636
protected function request($endpoint = null, $method, $params)
    {
        $results = $this->makeRequest($endpoint, $method, $params);

        return $results ? $this->newInstance($results, true) : null;
    }
909282
public function request($method = self::REQUEST_POST, $resource, array $params = [], array $headers = [])
    {
        $signature = $this->createSignature($resource);
        $method = strtoupper($method);

        $options = [
            'headers' => array_merge($headers, [
                'X-Auth-Key' => $this->key,
                'X-Auth-Workspace' => $this->workspace,
                'X-Auth-Signature' => $signature,
                'Content-Type' => 'application/json; charset=utf-8',
                'Accept' => 'application/json'
            ])
        ];

        /**
         * If POST and data is not an url then send data in body as json string
         */
        if ($method === self::REQUEST_POST && isset($params['data']) && !self::isUrl($params['data']))
        {
            if (is_string($params['data']))
            {
                $params['data'] = self::stringToArray($params['data']);
            }

            if ($params['data'])
            {
                $options[\GuzzleHttp\RequestOptions::JSON] = $params['data'];
                unset($params['data']);
            }
        }

        $options[\GuzzleHttp\RequestOptions::QUERY] = $params;
        return $this->handleRequest($method, $resource, $options);
    }
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);
	}
145511
private function validateAndCall(&$mapping, $method, ...$params)
    {
        $mapping = $this->makeMapping($mapping);

        if (! method_exists($mapping, $method))
        {
            throw new \BadMethodCallException("EntityMapping [" . get_class($mapping) .
                "] does not implement '$method'."
            );
        }

        return call_user_func_array([$mapping, $method], $params);
    }
1068763
private function request($method, $resource, array $params)
    {
        $queryParams = ['api_key' => $this->apiKey];
        $queryParams += $params;

        $uri = $resource .'/?'. http_build_query($queryParams);

        try {
            $response = $this->client->request($method, $uri);
        } catch (ClientException $e) {
            $response = $e->getResponse();
            $msg = $response->getBody();
            $code = $response->getStatusCode();
            $previous = $e;
            throw new StreamFeedException($msg, $code, $previous);
        }

        $body = $response->getBody()->getContents();

        return json_decode($body, true);
    }
1244851
public function request($method, $params = [])
    {
        $response = $this->client->post($this->getUrl($method), ['query' => $params]);

        if ($response->getStatusCode() === 200) {
            return (string)$response->getBody();
        } else {
            throw new Exception(sprintf('Sms.ru problem. Status code is %s', $response->getStatusCode()), $response->getStatusCode());
        }
    }
301050
protected function request($api, array $params, $method = 'post', array $options = [], $returnResponse = false)
    {
        $params = array_merge($params, $this->merchant->only(['sub_appid', 'sub_mch_id']));

        $params['appid'] = $this->merchant->app_id;
        $params['mch_id'] = $this->merchant->merchant_id;
        $params['device_info'] = $this->merchant->device_info;
        $params['nonce_str'] = uniqid();
        $params = array_filter($params);
        $params['sign'] = generate_sign($params, $this->merchant->key, 'md5');

        $options = array_merge([
            'body' => XML::build($params),
        ], $options);

        $response = $this->getHttp()->request($api, $method, $options);

        return $returnResponse ? $response : $this->parseResponse($response);
    }
1319947
private function request(string $method, string $path, array $query = [], array $body = []): ResponseInterface
    {
        $request = [
            'base_uri'    => $this->baseUri,
            'auth'        => [$this->username, $this->password, 'digest'],
            'http_errors' => false,
        ];

        if (count($query) > 0) {
            $request['query'] = $query;
        }

        if (count($body) > 0) {
            $request['json'] = $body;
        }

        $response = null;

        // Threefold request attempt to bypass possible non-reproducible errors.
        for ($i = 0; $i < 3; $i++) {

            $response = $this->guzzleClient->request(
                $method,
                $path,
                $request
            );

            if ($response->getStatusCode() < 400) {
                return $response;
            }
        }

        throw new \InvalidArgumentException((string)$response->getBody());
    }
154526
protected function doRequest($method, $endpoint, array $params = array(), $isVault = false)
    {
        if (empty($method) || !is_string($method)) {
            throw new InvalidArgumentException("HTTP METHOD must a string and a valid HTTP METHOD Value");
        }

        if (empty($endpoint) || !is_string($endpoint)) {
            throw new InvalidArgumentException("Endpoint must be a string and a valid api endpoint");
        }

        $credentials = $this->getConfiguration()->getApiUsername() . ':' . $this->getConfiguration()->getApiPassword();

        $url = $this->getConfiguration()->getApiEndpoint();

        if ($isVault) {
            $url = $this->getConfiguration()->getSecureVaultEndpoint();
        }

        $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'HiPayFullservice/1.0 (SDK PHP)';
        $finalUrl = $url . $endpoint;

        // set appropriate options
        $options = array(
            CURLOPT_URL => $finalUrl,
            CURLOPT_USERPWD => $credentials,
            CURLOPT_HTTPHEADER => array(
                'Accept: ' . $this->getConfiguration()->getApiHTTPHeaderAccept(),
                'User-Agent: ' . $userAgent
            ),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FAILONERROR => false,
            CURLOPT_HEADER => false,
        );

        // add post parameters
        if (strtolower($method) == 'post') {
            $options[CURLOPT_POST] = true;
            $options[CURLOPT_POSTFIELDS] = http_build_query($params);
        } else {
            $options[CURLOPT_POST] = false;
        }

        $proxyConfiguration = $this->getConfiguration()->getProxy();

        if (!empty($proxyConfiguration)) {
            $options[CURLOPT_PROXY] = $proxyConfiguration["host"];
            $options[CURLOPT_PROXYPORT] = $proxyConfiguration["port"];
            $options[CURLOPT_PROXYUSERPWD] = $proxyConfiguration["user"] . ":" . $proxyConfiguration["password"];
        }

        /**
         * Send a new request
         * $method can be any valid HTTP METHOD (GET, POST etc ...)
         * $uri The url/endpoint to request
         * $options Needed configuration
         */
        foreach ($options as $option => $value) {
            curl_setopt($this->_httpClient, $option, $value);
        }

        // execute the given cURL session
        if (false === ($result = curl_exec($this->_httpClient))) {
            throw new CurlException(curl_error($this->_httpClient), curl_errno($this->_httpClient));
        }

        $body = $result;

        $status = (int)curl_getinfo($this->_httpClient, CURLINFO_HTTP_CODE);
        $httpResponse = json_decode($body);

        if (floor($status / 100) != 2) {
            if (is_object($httpResponse) && isset($httpResponse->message, $httpResponse->code)) {
                $description = (isset($httpResponse->description)) ? $httpResponse->description : "";
                throw new ApiErrorException($httpResponse->message, $httpResponse->code, $description);
            } else {
                throw new HttpErrorException($body, $status);
            }
        }

        //Return a simple response object
        return new Response((string)$body, $status, array('Content-Type' => array('application/json; encoding=UTF-8')));
    }
527940
protected function _request($method, $url, $params = [], $options = null)
    {
        $opts = $this->_opts->merge($options);
        list($resp, $options) = static::_staticRequest($method, $url, $params, $opts);
        $this->setLastResponse($resp);
        return [$resp->json, $options];
    }
989541
private function request($url, $params = [], $method = 'GET')
    {
        // Set URL & Header
        curl_setopt($this->curl, CURLOPT_URL, $this->url . $url);
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, array());

        //Add post vars
        if($method == 'POST')
        {
            curl_setopt($this->curl, CURLOPT_POST, count($params));
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
        }

        //Get result
        $result = curl_exec($this->curl);
        if($result === false)
            throw new \Exception('CURL error: ' . curl_error($this->curl));

        // decode results
        $result = json_decode($result, true);

        if(!is_array($result) || json_last_error())
            throw new \Exception('JSON decode error');

        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;
    }
720754
protected static function _staticRequest($method, $url, $params, $options)
    {
        $opts = \Stripe\Util\RequestOptions::parse($options);
        $baseUrl = isset($opts->apiBase) ? $opts->apiBase : static::baseUrl();
        $requestor = new \Stripe\ApiRequestor($opts->apiKey, $baseUrl);
        list($response, $opts->apiKey) = $requestor->request($method, $url, $params, $opts->headers);
        $opts->discardNonPersistentHeaders();
        return [$response, $opts];
    }
350653
protected function processRequest($method, $params)
    {
        if (empty($this->wsdl)) {
            throw new \Exception('Must specifiy WSDL in child class before calling processRequest.  Did you remember to implement the __construct method?'
            );
        }
        if (empty($this->uri)) {
            throw new \Exception('Must specifiy uri in child class before calling processRequest.  Did you remember to implement the __construct method?'
            );
        }

        if (substr($this->wsdl, 0, 4) != 'http') {
            $this->_soapClient = new \SoapClient(
                dirname(__DIR__) . '/wsdl/' . $this->wsdl,
                $this->_options
            );
        } else {
            $this->_soapClient = new \SoapClient($this->wsdl, $this->_options);
        }

        try {
            $outputHeader = '';
            $resp = $this->_soapClient->__soapCall(
                $method,
                $params,
                null,
                $this->_headers,
                $outputHeader
            );

            return $resp;
        } catch (\Exception $e) {
            $this->output->error(print_r($e, true));
        }
    }
63551
protected function doRequest($method, $apiMethod, array $data = [])
    {
        $url = $this->config['endpoint'] . $apiMethod;
        $data = $this->mergeData($this->createAuthData(), $data);

        $response = $this->getGuzzleClient()->request($method, $url, ['json' => $data]);
        $responseContent = \GuzzleHttp\json_decode($response->getBody());

        if (!property_exists($responseContent, 'success') || !$responseContent->success) {
            throw new InvalidRequestException($method, $url, $data, $response);
        }

        return $responseContent;
    }