1. Go to this page and download the library: Download sarus-io/sarus-sdk-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sarus-io / sarus-sdk-php example snippets
use Sarus\SdkFactory;
use Sarus\Config;
$config = new Config(
'SECRET', // Requred - API secret for sarus
'https://api.sarus.io', // Optional - base url
30, // Optional - timeout
true // Optional - ssl verify
);
//OR
$config = Config::fromArray([
'secret' => 'SECRET', // Requred - API secret for sarus
'baseUri' => 'https://api.sarus.io', // Optional - base url
'timeout' => 30, // Optional - timeout
'sslVerify' => true // Optional - ssl verify
]);
$factory = new SdkFactory();
$sdk = $factory->create($config);
// If you want to log request and response:
$logger = new Logger(); //class implemented \Psr\Log\LoggerInterface
$logFormat = \GuzzleHttp\MessageFormatter::CLF; \\Formating of log message
$logLevel = \Psr\Log\LogLevel::INFO; //By default log level is info
$sdk = $factory->createWithLogger($config, $logger, $logFormat, $logLevel);
try {
// request
} catch (\Sarus\Client\Exception\HttpException $e) {
// The exceptions is thrown if http request is not successful
$e->getMessage(); // returns either grabbed message from response body or reason phrase
$e->hasResponse(); // returns bool, if exception holds response object
$e->getResponse(); // returns \Psr\Http\Message\ResponseInterface
$e->getRequest(); // returns \Psr\Http\Message\RequestInterface
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.