Send

@param string $api
@param string $method
@param array $data
@return array
@throws Exception
353322
public static function send(string $api, string $method, array $data) : array {
		// mail delivery first
		$class = \Application::get("apis.{$api}.submodule", ['class' => true]);
		if (empty($class)) {
			Throw new Exception('You need to specify API delivery submodule');
		}
		// check if backend has been enabled
		if (!Can::systemModuleExists('UA')) {
			Throw new Exception('You must enable UA module first!');
		}
		// initialize the object
		$object = new $class();
		return $object->send($method, $data, \Application::get("apis.{$api}"));
	}
289059
protected function request($url, $method = 'GET', array $data = [])
    {
        try {
            return call_user_func_array([$this, strtolower($method)], [$url, $data]);
        } catch (\Exception $exception) {
            throw new \RuntimeException('Http method is not valid.');
        }
    }
831071
public function call(string $method, $payload, int $flags = 0)
    {
        $this->relay->send(
            $method . pack("P", $this->seq),
            Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW
        );

        if ($flags & Relay::PAYLOAD_RAW) {
            $this->relay->send($payload, $flags);
        } else {
            $body = json_encode($payload);
            if ($body === false) {
                throw new Exceptions\ServiceException(sprintf(
                    "json encode: %s",
                    json_last_error_msg()
                ));
            }

            $this->relay->send($body);
        }

        $body = $this->relay->receiveSync($flags);

        if (!($flags & Relay::PAYLOAD_CONTROL)) {
            throw new Exceptions\TransportException("rpc response header is missing");
        }

        $rpc = unpack("Ps", substr($body, -8));
        $rpc['m'] = substr($body, 0, -8);

        if ($rpc["m"] != $method || $rpc["s"] != $this->seq) {
            throw new Exceptions\TransportException("rpc method call mismatch");
        }

        // request id++
        $this->seq++;

        // wait for the response
        $body = $this->relay->receiveSync($flags);

        return $this->handleBody($body, $flags);
    }
1061473
public function sendRequest($url = '', $data = [], $method = 'GET', $magic = 'cURL')
    {
        try {
            $request                  = new MyRequests();
            $request->debugStatus     = $this->DEBUG;
            $request->debugLevel      = $this->debugLevel;
            $request->debugLoggerPath = $this->loggerPath;
            $request->__construct();
            $result = $request->sendRequest($url, $data, $method);

            return $result;
        }
        catch (\Exception $e) {
            $message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
            if (function_exists('log_message')) {
                log_message('error', $message);
            }

            return $message;
        }
    }
271119
public function request($method, $uri, array $data = array())
    {
        $path = $this->path() . '/' . trim($uri, '/');

        $session = curl_init();

        // Curious as why i have to do this
        if ($method === 'PUT') {
            curl_setopt($session, CURLOPT_POSTFIELDS, http_build_query($data));
        } else {
            $path .= '?' . http_build_query($data);
        }

        curl_setopt($session, CURLOPT_HEADER, true);
        curl_setopt($session, CURLOPT_HTTPHEADER, $this->defaultHeaders());
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($session, CURLOPT_POST, $method !== 'GET');

        curl_setopt($session, CURLOPT_URL, $path);
        curl_setopt($session, CURLOPT_CUSTOMREQUEST, $method);
        $response = curl_exec($session);
        $statusCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
        $headerSize = curl_getinfo($session, CURLINFO_HEADER_SIZE);
        $body = substr($response, $headerSize);

        if ($statusCode !== 200) {
            throw new InvalidRequest($body);
        }

        curl_close($session);

        return json_decode($body, true);
    }
88997
public function get($method, $data = array())
    {
        //set cURL transfer option for get request
        // and get ouput
        return $this->createEndPoint($method, $data)
                    ->setOpt(CURLOPT_CUSTOMREQUEST, 'GET')
                    ->setopt(CURLOPT_HTTPGET, true)
                    ->exec();
    }
510489
protected function sendRequest(string $method = 'PURGE', string $uri, array $headers = [])
    {
        $client = new Client([
            'base_uri' => self::API_ENDPOINT,
            'headers'  => array_merge($headers, [
                'Content-Type' => 'application/json',
                'Fastly-Key'   => $this->apiToken
            ])
        ]);

        // Prepend the service endpoint
        if (in_array($method, ['POST','GET'])) {
            $uri = "service/{$this->serviceId}/{$uri}";
        }

        try {

            $client->request($method, $uri);

        } catch (BadResponseException $e) {

            throw FastlyApiException::create(
                $e->getRequest(),
                $e->getResponse()
            );
        }

        return true;
    }
792168
private function send($method, $url, array $data = [], array $headers = [], $cacheMinutes = 0)
    {
        $method = strtolower($method);

        try
        {
            return $this->courier->$method($url, $data, $headers, $cacheMinutes);
        }
        catch (HttpRequestException $exception)
        {
            $response = $exception->response();

            if ($response->getResponseType() == 'application/json')
            {
                $response = $response->toArray();
                $error = sprintf('Twitter Error: %s (Error %d)', $response['errors'][0]['message'], $response['errors'][0]['code']);
            }
            else
            {
                $error = sprintf('HTTP Error: %s (Error %d)', $exception->getMessage(), $exception->getCode());
            }

            throw new TwitterException($error);
        }
    }
968972
private function sendRequest(string $method, string $uri, array $query = [], array $body = []) : array {
        $uri = sprintf('%s%s', $this->baseUrl, ltrim($uri, '/'));

        $options = [
            'headers' => [
                'Authorization' => (string) $this->authentication
            ],
            'http_errors' => false
        ];

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

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

        $response = $this->client->request(
            $method,
            $uri,
            $options
        );

        $json = json_decode((string) $response->getBody(), true);
        if ($json === null) {
            if ($this->throwsExceptions) {
                throw new SDKError();
            }

            return [(string) $response->getBody()];
        }

        if (($json['status'] === false) && ($this->throwsExceptions)) {
            throw new SDKException(
                $json['error']['message'],
                $json['error']['type'],
                $json['error']['link']
            );
        }

        return $json;
    }
275025
protected function invokeService($service,$method,$data) {

            if (is_callable($this->onInvokeService)) {
                return call_user_func_array($this->onInvokeService,array($service,$method,$data));
            } else {
                throw new Exception('onInvokeService is not defined or not callable');
            }

        }
370775
public function sendRequest($method, $params = [])
    {
        $request = $this->request($method, $params);
        $this->lastResponse = $this->client->sendRequest($request);
        if ($this->lastResponse->isError()) {
            $this->lastResponse->throwException();
        }

        return $this->lastResponse;
    }
933351
public static function post($url, $data = [], $method = 'POST')
    {
        $ch = curl_init();

        if ( ! empty($data)) {
            $data = http_build_query($data);
        }
        
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output

        $result = curl_exec($ch);
        
        curl_close($ch);

        if (false !== $result) {
            $result = json_decode($result);
            
        } else {
            throw new \Exception('Error during making request');
        }

        return $result;
    }
844969
public function call($method, array $params = array(), $format = 'php')
    {
        $params['method']       = $method;
        $params['token_auth']   = $this->token;
        $params['format']       = $format;

        $data = $this->getConnection()->send($params);

        if ('php' === $format) {
            $object = unserialize($data);

            if (isset($object['result']) && 'error' === $object['result']) {
                throw new Exception($object['message']);
            }

            return $object;
        } else {
            return $data;
        }
    }
654594
public function update($api, $id, array $data = [])
    {
        return $this->checkException($this->callHttpMethod($this->normalizeUri($api, $id), Request::METHOD_PUT, $data));
    }
1089165
public function request($method, $scope = null, $data = null)
    {
        if (is_array($scope)) {
            $data = $scope;
            $scope = null;
        }
        $url = $scope ? $this->url.'/'.ltrim($scope, '/') : $this->url;
        $result = self::$client->request($method, $url, $data);
        if (!$scope && $result instanceof Resource) {
            // TODO: how should POST be handled here?
            foreach ($result->data() as $key => $value) {
                self::offsetSet($key, $value);
            }
        }
        return $scope ? $result : $this;
    }
1268417
public function api($url, $method, array $params = [], array $headers = [])
    {
        try {
            return $this->sendRequest($method, $url, $params, $headers);
        } catch (\Exception $e) {
            sleep(2);
            return $this->sendRequest($method, $url, $params, $headers);
        }
    }
27758
public function create($api, array $data)
    {
        return $this->checkException($this->callHttpMethod($this->normalizeUri($api), Request::METHOD_POST, $data));
    }