PHP code example of sportrizer / sportysky-client-php
1. Go to this page and download the library: Download sportrizer/sportysky-client-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/ */
sportrizer / sportysky-client-php example snippets
bash
composer
php
$response = $apiClient->getCountryForecastResponse('FR', new \DateTime('2020-01-14T17:36:00+00:00'));
$data = json_decode($response->getBody()->getContents(), true);
php
$response = $apiClient->getRegionForecastResponse('FR-BRE', new \DateTime('2020-01-14T17:36:00+00:00'));
$data = json_decode($response->getBody()->getContents(), true);
php
$response = $apiClient->getDepartmentForecastResponse('FR-29', new \DateTime('2020-01-14T17:36:00+00:00'));
$data = json_decode($response->getBody()->getContents(), true);
php
$response = $apiClient->getSpotForecastResponse(
'1234-1234-1234-1234',
new \DateTime('2020-01-14T17:36:00+00:00'),
new \DateTime('2020-01-14T17:36:00+00:00')
);
$data = json_decode($response->getBody()->getContents(), true);
php
$response = $apiClient->getSpotForecastByCodeAndCountryResponse(
'29000',
'FR',
new \DateTime('2020-01-14T17:36:00+00:00'),
new \DateTime('2020-01-14T17:36:00+00:00')
);
$data = json_decode($response->getBody()->getContents(), true);
php
use Sportrizer\Sportysky\Utils\Geo\Box;
use Sportrizer\Sportysky\Utils\Geo\Point;
// search nearest spot
$response = $apiClient->getSpotsResponse(
new Point(33.3, 44.4)
);
$data = json_decode($response->getBody()->getContents(), true);
// find all spots inside a bounding box
$response = $apiClient->getSpotsResponse(
null,
new Box(new Point(22.2, 33.3), new Point(33.3, 44.4))
);
// pagination
$response = $apiClient->getSpotsResponse(
null,
null,
3 // get page 3
);
$data = json_decode($response->getBody()->getContents(), true);
php
use Sportrizer\Sportysky\ApiClient;
use Sportrizer\Sportysky\Authenticator;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use Psr\Http\Message\ResponseInterface;
$authenticator = new Authenticator(getenv('SPORTYSKY_CLIENT_ID'), getenv('SPORTYSKY_CLIENT_SECRET'));
$handler = HandlerStack::create();
$handler->push(
Middleware::mapResponse(
function (ResponseInterface $response) {
$bodyContent = json_decode($response->getBody()->getContents(), true);
$bodyContent['test_Middleware'] = true;
return $response->withBody(
\GuzzleHttp\Psr7\stream_for(
json_encode($bodyContent)
)
);
}
)
);
$apiClient = new ApiClient($authenticator->getToken(), $handler);
php
use Sportrizer\Sportysky\ApiClient;
use Sportrizer\Sportysky\Authenticator;
use GuzzleHttp\HandlerStack;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Middleware;
use Kevinrob\GuzzleCache\CacheMiddleware;
use Kevinrob\GuzzleCache\Strategy\PublicCacheStrategy;
use Doctrine\Common\Cache\FilesystemCache;
use Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage;
$authenticator = new Authenticator(getenv('SPORTYSKY_CLIENT_ID'), getenv('SPORTYSKY_CLIENT_SECRET'));
$handler = HandlerStack::create();
$handler->push(
Middleware::mapResponse(
function (ResponseInterface $response) {
$bodyContent = json_decode($response->getBody()->getContents(), true);
$bodyContent['test_Middleware'] = true;
return $response->withBody(
\GuzzleHttp\Psr7\stream_for(
json_encode($bodyContent)
)
);
}
)
);
$handler->push(
new CacheMiddleware(
new PublicCacheStrategy(
new DoctrineCacheStorage(
new FilesystemCache('/tmp/')
)
)
)
);
$apiClient = new ApiClient($authenticator->getToken(), $handler);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.