Execute on SSO server.

@param string       $method  HTTP method: 'GET', 'POST', 'DELETE'
@param string       $command Command
@param array|string $data    Query or post parameters
@return array|object
510521
protected function request($method, $command, $data = null)
    {
        if (!$this->isAttached()) {
            throw new NotAttachedException('No token');
        }
        $url = $this->getRequestUrl($command, !$data || $method === 'POST' ? [] : $data);

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: application/json', 'Authorization: Bearer '. $this->getSessionID()]);

        if ($method === 'POST' && !empty($data)) {
            $post = is_string($data) ? $data : http_build_query($data);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        }
        $response = curl_exec($ch);

        if (curl_errno($ch) != 0) {
            $message = 'Server request failed: ' . curl_error($ch);
            throw new Exception($message);
        }

        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        list($contentType) = explode(';', curl_getinfo($ch, CURLINFO_CONTENT_TYPE));

        if ($contentType != 'application/json') {
            $message = 'Expected application/json response, got ' . $contentType;
            throw new Exception($message);
        }
        $data = json_decode($response, true);

        if ($httpCode == 403) {
            $this->clearToken();
            throw new NotAttachedException($data['error'] ?: $response, $httpCode);
        }

        if ($httpCode >= 400) {
            throw new Exception($data['error'] ?: $response, $httpCode);
        }

        return $data;
    }
1054163
protected function callService($command, $data = array())
    {
        if (!$this->init) {
            throw new ClientNotInitializedException();
        }

        $data['auth.key'] = $this->clientApiConfig->getKey();
        $data['auth.secret'] = $this->clientApiConfig->getSecret();
        $data['command'] = $command;
        $data['project_id'] = $this->clientApiConfig->getProjectId();

        $msg = json_encode($data).PHP_EOL;

        $this->sendMessage($msg);

        $buffer = $this->readSocket();

        if ($this->debug) {
            print $buffer;
        }

        $result = json_decode($buffer, true);
        if (!count($result)) {
            throw new NullSocketResponseException();
        }

        return $result;
    }
218825
private function request($method, $uri, $data = [])
    {
        $uri = $this->getUri($uri);

        $headers = [];

        // Basic Auth
        $credentials = $this->key.':'.$this->password;

        // User Agent
        $agent = sprintf("%s %s", Client::NAME, Client::VERSION);

        $ch = curl_init();

        if (strtoupper($method) === 'GET' && !empty($data)) {
            $queryString = http_build_query($data);
            $uri .= '?'.$queryString;
        }

        $options = [
            CURLOPT_URL => $uri,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER => true,
            CURLOPT_USERAGENT => $agent,
            CURLOPT_USERPWD => $credentials,
            CURLOPT_TIMEOUT => 60,
        ];

        if (strtoupper($method) === 'POST') {
            $jsonData = json_encode($data);

            $headers[] = 'Content-Type: application/json';
            $headers[] = 'Content-Length: '.strlen($jsonData);

            $options[CURLOPT_CUSTOMREQUEST] = 'POST';
            $options[CURLOPT_POSTFIELDS] = $jsonData;
        }

        if (isset($this->version) && is_numeric($this->version)) {
            $headers[] = 'X-EWAY-APIVERSION: '.$this->version;
        }

        $options[CURLOPT_HTTPHEADER] = $headers;

        curl_setopt_array($ch, $options);

        $rawResponse = curl_exec($ch);

        $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);

        if (curl_errno($ch)) {
            $responseError = curl_error($ch);
            $responseBody = '';
        } else {
            $responseError = '';
            $responseBody = $this->parseResponse($rawResponse, $headerSize);
        }

        $response = new Response($statusCode, $responseBody, $responseError);

        curl_close($ch);

        return $response;
    }
977055
protected function _execute($command) {
		try {
			if (!$class = $this->_instance($command)) {
				return false;
			}
		} catch (ClassNotFoundException $e) {
			return false;
		}
		$data = [];
		$params = $class->invokeMethod('_params');

		foreach ($params as $param) {
			$data[$param] = $class->invokeMethod("_{$param}", [$this->request]);
		}

		if ($message = $class->invokeMethod('_save', [$data])) {
			$this->out($message);
			return true;
		}
		return false;
	}
15735
private function write($data, $method = 'PUT')
    {
        $jsonData = json_encode($data);
        $header = array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($jsonData)
        );
        try
        {
            $ch = $this->curl($method);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
            $return = curl_exec($ch);
            curl_close($ch);
            return json_decode($return, true);
        } catch (Exception $e)
        {
            //...
        }
        return null;
    }
618732
public function execute(interfaces\commands\Command $command)
    {
        $handler = $this->resolver->resolve($command);
        
        return call_user_func([$handler, 'handle'], $command);
    }
1010379
protected function request($url, $method, $data = null)
    {
        $this->testLogin();
        try {
            $response = $this->transport->send(
                $url, $method, $data, array(
                'Content-Type: ' . $this->mapper->getContentType(),
                )
            );
        } catch (HttpStatusException $e) {
            $message = $e->getMessage();
            if ($e->getCode() == 403 || $e->getCode() == 422) {
                $this->errors = $this->mapper->mapFromStorage($this->transport->getLastResponse());
                if ($this->errors instanceof ErrorArray && count($this->errors) > 0) {
                    $message .= PHP_EOL . 'Errors:' . PHP_EOL . $this->errors;
                }
            }

            if (self::$debug) {
                printf(
                    'Url: %s' . PHP_EOL . 'Method: %s' . PHP_EOL . 'Data: %s', $url, $method, $data
                );
            }

            switch ($e->getCode()) {
                case 401:
                    throw new NotLoggedInException($message, 0, $e);
                    break;
                case 403:
                    throw new ForbiddenException($message, 0, $e);
                    break;
                case 404:
                    throw new NotFoundException($message, 0, $e);
                    break;
                case 406:
                case 422:
                    throw new NotValidException($message, 0, $e);
                    break;
                default:
                    $message = 'Unknown error; check https://github.com/bluetools/moneybird_php_api/wiki/Common-errors';
                // no break
                case 500:
                case 501:
                    throw new ServerErrorException($message, 0, $e);
                    break;
            }
        }

        return $response;
    }
981783
protected function exec($method, $uri, $data, $content_type)
    {
        $connect = $this->getConnect($uri, $method, $content_type);
        if ($data) {
            $this->setData($connect, $data, $content_type);
        }

        $api_result = curl_exec($connect);
        $api_http_code = curl_getinfo($connect, CURLINFO_HTTP_CODE);
        $api_http_time = curl_getinfo($connect, CURLINFO_TOTAL_TIME);

        $response = array(
            "status" => $api_http_code,
            "total_time" => $api_http_time,
        );

        if ($content_type == "application/json") {
            $response["response"] = json_decode($api_result, true);
        } elseif ($content_type == "text/html") {
            $response["response"] = $api_result;
        }

        if ($response['status'] >= 400) {
            throw new Exception($response['response'], $response['status']);
        }

        curl_close($connect);

        return $response;
    }
95212
private function send(string $method, string $command, array $options = []): array 
    {
        $result = $this->client->da_request($method, self::CMD_PREFIX . $command, $options);
        
        return $result;
    }
1303857
public function invoke($instance, string $method, array $data)
    {
        // get the parameters
        $parameters = $this->resolveMethodParameters($instance, $method, $data, true);

        // get the reflection of method
        $reflection = new ReflectionMethod(get_class($instance), $method);

        // allow access
        $reflection->setAccessible(true);

        // execute the method
        return $reflection->invokeArgs($instance, $parameters);
    }
410569
public function request(array $data = [], string $method = Request::GET): Response
    {
        $path = '_cluster/settings';

        return $this->getClient()->request($path, $method, $data);
    }
659617
private function createRequest($method, $resource, array $data = [])
    {
        if (!empty($data)) {
            $data['signature'] = $this->apiSignature;
        }

        return $this->requestFactory->createRequest($method, $resource, [], $this->encode($data));
    }
518281
protected function get($method, array $data = [], $key = 'key')
    {
        $data = $this->data($data);

        if (!isset($this->cache[$method][$key])) {
            $this->cache[$method][$key] = $this->client->$method($data);
        }

        return $this->cache[$method][$key];
    }
1215426
public function command($method, array $parameters = [])
    {
        $start = microtime(true);

        $result = $this->client->{$method}(...$parameters);

        $time = round((microtime(true) - $start) * 1000, 2);

        if (isset($this->events)) {
            $this->event(new CommandExecuted($method, $parameters, $time, $this));
        }

        return $result;
    }
1202689
private function performRequest($command, $parameters)
        {
        // add the apikey to the parameters
        $parameters["key"] = $this->api_key;

        // make an array out of the dictionary so that each element is a key value pair glued together with an '=', and urlencode the parameters
        $param_array = array();
        foreach ($parameters as $key=>$value)
            $param_array[] = "$key=" . urlencode($value);

        // glue the array together unto a string with elements connected with '&'
        $params = implode("&", $param_array);

        // put the whole URL together now
        $url = $this->base_url . $command . "?" . $params;

        // cal the server
        $json = $this->call($url);

        $data = json_decode($json, true);

        if (isset($data["error"]))
          {
          $this->error["code"]    = $data["error"]["code"];
          $this->error["message"] = $data["error"]["message"];
          $data = false;
          }

        return $data;
        }
1232318
private function apiCall($command, $data=array()) {
			if (!isset($this->rest_commands[$command])) {
				return false;
			}

			$cmd = $this->rest_commands[$command];

			$url = $cmd['url'];
			$url = str_replace(array('{k}', '{s}') ,array($this->nx_key, $this->nx_secret), $url);

			$parsed_data = array();
			foreach ($data as $k => $v) $parsed_data['{'.$k.'}'] = $v;
			$url = str_replace(array_keys($parsed_data) ,array_values($parsed_data), $url);

			$url = trim($this->rest_base_url, '/') . $url;
			$post_data = '';

			// If available, use CURL
			if (function_exists('curl_version')) {

				$to_nexmo = curl_init( $url );
				curl_setopt( $to_nexmo, CURLOPT_RETURNTRANSFER, true );
				curl_setopt( $to_nexmo, CURLOPT_SSL_VERIFYPEER, false);
				curl_setopt($to_nexmo, CURLOPT_HTTPHEADER, array('Accept: application/json'));

				if ($cmd['method'] == 'POST') {
					curl_setopt( $to_nexmo, CURLOPT_POST, true );
					curl_setopt( $to_nexmo, CURLOPT_POSTFIELDS, $post_data );
				}

				$from_nexmo = curl_exec( $to_nexmo );
				$curl_info = curl_getinfo($to_nexmo);
				$http_response_code = $curl_info['http_code'];
				curl_close ( $to_nexmo );

			} elseif (ini_get('allow_url_fopen')) {
				// No CURL available so try the awesome file_get_contents

				$opts = array('http' =>
					array(
						'method'  => 'GET',
						'header'  => 'Accept: application/json'
					)
				);

				if ($cmd['method'] == 'POST') {
					$opts['http']['method'] = 'POST';
					$opts['http']['header'] .= "\r\nContent-type: application/x-www-form-urlencoded";
					$opts['http']['content'] = $post_data;
				}

				$context = stream_context_create($opts);
				$from_nexmo = file_get_contents($url, false, $context);

				// et the response code
				preg_match('/HTTP\/[^ ]+ ([0-9]+)/i', $http_response_header[0], $m);
				$http_response_code = $m[1];

			} else {
				// No way of sending a HTTP post :(
				return false;
			}

			$data = json_decode($from_nexmo, true);
			return array(
				'data' => $data,
				'http_code' => (int)$http_response_code
			);

		}
860553
public static function execute($sql, $data = [])
    {
        $statement = self::$pdo->prepare($sql);
        $statement->execute($data);
        return $statement;
    }