Make an API call to https://api.vk.com/method/

@param string $method API method name
@param array $query API method params

@return mixed The response

@throws \Exception
350203
public function api($method, array $query = array())
    {
        /* Generate query string from array */
        foreach ($query as $param => $value) {
            if (is_array($value)) {
                // implode values of each nested array with comma
                $query[$param] = implode(',', $value);
            }
        }
        $query['access_token'] = isset($this->accessToken['access_token'])
            ? $this->accessToken['access_token']
            : '';
        if (empty($query['v'])) {
            $query['v'] = $this->getApiVersion();
        }
        $url = 'https://api.vk.com/method/' . $method . '?' . http_build_query($query);
        $result = json_decode($this->curl($url), true);

        if (isset($result['response'])) {
            return $result['response'];
        }

        return $result;
    }
1272808
public function post(string $method, string $access_token, array $params = array()) {
        $params = $this->formatParams($params);
        $params[static::PARAM_ACCESS_TOKEN] = $access_token;

        if (!isset($params[static::PARAM_VERSION])) {
            $params[static::PARAM_VERSION] = $this->version;
        }

        if ($this->language && !isset($params[static::PARAM_LANG])) {
            $params[static::PARAM_LANG] = $this->language;
        }

        $url = $this->host . '/' . $method;

        try {
            $response = $this->http_client->post($url, $params);
        } catch (TransportRequestException $e) {
            throw new VKClientException($e);
        }

        return $this->parseResponse($response);
    }
826616
protected function prepareBody(array $query)
    {
        $method = isset($query['from']['method']) ? $query['from']['method'] : null;

        if ($method === 'POST') {
            // The query grammar already parsed the body for us.
            // We return the value of the query and guzzle does the rest.
            return isset($query['body']) ? $query['body'] : null;
        }
    }
959981
private function httpGet( $path, array $query = array() ){

        $url = new Uri( $this->baseUrl . $path );

        foreach( $query as $name => $value ){
            $url = URI::withQueryValue($url, $name, $value );
        }

        //---

        $request = new Request(
            'GET',
            $url,
            $this->buildHeaders()
        );

        try {

            $response = $this->getHttpClient()->sendRequest( $request );

        } catch (\RuntimeException $e){
            throw new Exception\NotifyException( $e->getMessage(), $e->getCode(), $e );
        }

        //---

        switch( $response->getStatusCode() ){
            case 200:
                return $this->handleResponse( $response );
            case 404:
                return null;
            default:
                return $this->handleErrorResponse( $response );
        }

    }
572368
public function getMethod($method)
    {
        $method = \strtoupper($method);

        if (!isset($this->methods[$method])) {
            throw new \Exception('Method not found');
        }

        return $this->methods[$method];
    }
1343319
private function _mysql_query($query) {

        // call "mysqli_query"
        $result = mysqli_query($this->link, $query);

        // stop if there was an error
        if (!$result) throw new Exception($this->_mysql_error());

        // return the result if query was successful
        return $result;

    }
741514
public function request(string $method, string $url): Response
    {
        return $this->client->request($method, $url, $this->options);
    }
409053
public function performHttpRequest($method, $resourceName, $query = null, $body = null)
    {
        $curl = curl_init();

        if ($this->Authentication === null) {
            throw new Exceptions\AuthenticateException('Can not perform API Request without Authentication');
        }

        $headers = array (
            'User-agent: ' . implode(' ', $this->userAgent),
            'Accept: application/json',
            'Content-Type: application/json',
            'Accept-Charset: utf-8',
            sprintf('Authorization: AccessKey %s', $this->Authentication->accessKey)
        );

        $headers = array_merge($headers, $this->headers);

        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_HEADER, true);
        curl_setopt($curl, CURLOPT_URL, $this->getRequestUrl($resourceName, $query));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->connectionTimeout);

        foreach ($this->httpOptions as $option => $value) {
            curl_setopt($curl, $option, $value);
        }

        if ($method === self::REQUEST_GET) {
            curl_setopt($curl, CURLOPT_HTTPGET, true);
        } elseif ($method === self::REQUEST_POST) {
            curl_setopt($curl, CURLOPT_POST, true);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
        } elseif ($method === self::REQUEST_DELETE) {
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::REQUEST_DELETE);
        } elseif ($method === self::REQUEST_PUT){
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::REQUEST_PUT);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
        } elseif ($method === self::REQUEST_PATCH){
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::REQUEST_PATCH);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
        }

        // Some servers have outdated or incorrect certificates, Use the included CA-bundle
        $caFile = realpath(__DIR__ . '/../ca-bundle.crt');
        if (!file_exists($caFile)) {
            throw new Exceptions\HttpException(sprintf('Unable to find CA-bundle file "%s".', __DIR__ . '/../ca-bundle.crt'));
        }

        curl_setopt($curl, CURLOPT_CAINFO, $caFile);

        $response = curl_exec($curl);

        if ($response === false) {
            throw new Exceptions\HttpException(curl_error($curl), curl_errno($curl));
        }

        $responseStatus = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE);

        // Split the header and body
        $parts = explode("\r\n\r\n", $response, 3);
        list($responseHeader, $responseBody) = ($parts[0] === 'HTTP/1.1 100 Continue') ? array ($parts[1], $parts[2]) : array ($parts[0], $parts[1]);

        curl_close($curl);

        return array ($responseStatus, $responseHeader, $responseBody);
    }
72273
public function send(array $query = []): Response
    {
        $endpoint = new Put();
        $endpoint->setBody($this->toArray());
        $endpoint->setParams($query);

        return $this->getType()->requestEndpoint($endpoint);
    }
1219300
public function dispatch($method)
	{
		// Save original input.
		$original_input = Request::input();
		
		// Create request.
		$request = Request::create($this->uri, $method, $this->params);
		
		// Replace input (maintain api auth parameters).
		Request::replace(array_merge($request->input(), array(
			'client_id'     => Request::input('client_id'),
			'client_secret' => Request::input('client_secret'),
			'access_token'  => Request::input('access_token'),
		)));
		
		// Dispatch request.
		$response = Route::dispatch($request);
		
		// Restore original input.
		Request::replace($original_input);
		
		$content = $response->getContent();
		return empty($content) ? null : json_decode($response->getContent(), true);
	}
682702
public function request($method, $url, array $params = [])
    {
        if (!$this->authenticated()) {
            $this->authenticate();
        }

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

        $params['query']['format'] = 'json';

        try {
            $response = $this->getHttpClient()->request($method, $url, $params);
        } catch (RequestException $e) {
            return $e->getResponse();
        }

        return $response;
    }
464724
public function sendRequest($method = null){
        \Pingqu\OpenApi\Auth\Sign::setConfig([
            'accessKeyId'=>$this->accessKeyId,
            'accessKey'=>$this->accessKeySecret
        ]);
        $method = empty($method)?'GET':$method;
        $para = empty($this->params)?[]:$this->params;
        $httpCore = new \Pingqu\OpenApi\Http\RequestCore($this->api);
        $httpCore->set_body(\DdvPhp\DdvUrl::buildQuery($para));
        $httpCore->set_method($method);
        foreach ($this->header as $key=>$item) {
            $httpCore->add_header($key,$item);
        }
        $httpCore->add_header('Authorization', \Pingqu\OpenApi\Auth\Sign::getAuth($httpCore));
        $httpResponse = $httpCore->send_request(true);
        return $httpResponse;
    }
759222
protected function signRequest(string $method, string $uri, array $query): array
    {
        $query = array_merge($query,
            [
                'tonce' => $this->getTonce(),
                'access_key' => $this->options['publicKey'],
            ]);
        ksort($query, SORT_STRING);
        $sign = implode('|', [$method, $uri, http_build_query($query)]);
        $query['signature'] = hash_hmac('SHA256', $sign, $this->options['secretKey']);

        return $query;
    }
199251
private function addQueryParameters(Request $request, array $query)
    {
        $request->query->add($query);
        $request->server->add(['QUERY_STRING' => http_build_query($query)]);

        return $request;
    }
1181936
private function queryPublic($method, array $request = array())
    {
        // build the POST data string
        $postdata = http_build_query($request, '', '&');
        // make request
        curl_setopt($this->curl, CURLOPT_URL, $this->url . '/' . $this->version . '/public/' . $method);
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postdata);
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, array());
        $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))
            throw new \Exception('JSON decode error');
        return $result;
    }
686020
private function post($url, array $query = array())
    {
        return $this->browser->post($url, array(), $this->prepareQueryString($query));
    }
303418
public function query($entity, $query)
	{
		$retValue = array();

		if (! is_null($this->_db)){
			try{
				$mongo = $this->_db->selectCollection($entity);

				// Find by query
				$cursor = $mongo->find($query);

				if (is_null($cursor))
					$retValue = array();
				else
					$retValue = iterator_to_array($cursor);
			}
			catch(Exception $e) {
				$this->_log->addError($e->getMessage());
			}	
		}

		return $retValue;
	}