bardiyamap / sdk
Official Bardiya Map SDK for PHP: Places, Geocoding, Directions, Distance Matrix, Address Validation, map style and tiles, Tracking, location history, Realtime and webhooks.
Requires
- php: ^8.1
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^7.3
- guzzlehttp/psr7: ^2.0
- psr/http-client: ^1.0
Requires (Dev)
- phpunit/phpunit: ^10.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Official PHP client for the Bardiya Map API: Places, Geocoding, Directions, Distance Matrix, Address Validation, map style and tiles, Tracking, location history, Realtime (SSE) and webhooks.
- 39 of 39 published contract operations.
- Composer package, PHP 8.1+, Guzzle 7.
- Two credential families kept apart (
X-API-Keyfor maps,Authorization: Bearerfor tracking). - Tracking reads routed to the read plane automatically.
- Typed
BardiyaExceptionwith envelope parsing, request id andRetry-After. - Retries only safe-to-repeat operations; a write is never replayed.
- Webhook signature verification.
Status: published. Packagist serves bardiyamap/sdk version 0.1.0 from
https://github.com/EngMohamed05/bardiya-php, tagged v0.1.0.
Install
composer require bardiyamap/sdk:^0.1.0
No VCS or path repository is needed: Composer resolves the package and its Guzzle/PSR-7 dependencies from Packagist.
Quickstart
use BardiyaMap\Sdk\BardiyaClient; $client = BardiyaClient::create([ 'mapsApiKey' => getenv('BARDIYA_MAPS_KEY'), 'trackingApiKey' => getenv('BARDIYA_TRACKING_KEY'), ]); $places = $client->places()->searchPlaces('coffee', 30.0444, 31.2357, 2000, null, null, 5, 'en'); echo $places->getCount();
examples/quickstart.php is a runnable version; examples/laravel-integration.php
shows a service-provider singleton and a webhook route.
Credentials
| Family | Header | Endpoints |
|---|---|---|
| Maps | X-API-Key |
places, geocode, directions, distance matrix, validate-address, style, tiles |
| Tracking | Authorization: Bearer |
/v1/tracking, /v1/webhooks |
Both are organization credentials: keep them in the server environment, never in a template, a mobile app or a browser bundle. Device ingest uses a short-lived credential minted by your backend:
$credential = $client->tracking()->issueIngestToken($sessionId); $ingest = $client->ingest($credential->getToken(), $organizationId); $ingest->sendLocation($sessionId, $event);
Errors
try { $client->tracking()->getSession($sessionId); } catch (BardiyaException $failure) { $failure->getStatusCode(); // 404 $failure->getErrorCode(); // "session_not_found" $failure->getRequestId(); // X-Bardiya-Request-Id $failure->getDetails(); // envelope details $failure->getRetryAfterSeconds(); // when the server advised one $failure->isRetryable(); // false for a terminal sandbox exhaustion }
A 429 with X-Free-Sandbox-Credits-Remaining: 0 and no Retry-After is a
lifetime balance exhaustion: it never refills, so it is not retryable and the SDK
does not retry it.
Retries
Only operations that are safe to repeat are retried. GET/HEAD retry on
transient statuses. The three chargeable POST computations (/v1/directions,
/v1/distance-matrix, /v1/validate-address) retry only when
retryPostComputations is enabled and the call passes an
Idempotency-Key; even then an HTTP error response is final and only an
ambiguous transport failure is replayed. Retry-After is honoured up to
maxRetryAfterMs (30s default); otherwise the wait is full-jitter exponential
backoff. The header is accepted on every metered Maps route, including GET reads;
the ledger deduplicates debit and recomputes rather than caching the body. The
server-side idempotency ledger is flag-gated off in production, so no
exactly-once guarantee is claimed.
Realtime
foreach ($client->streamSession($sessionId) as $frame) { if ($frame->type === 'location') { $payload = $frame->json(); // decoded data: } }
Guzzle streams the response (stream => true), so a long-lived stream does not
buffer in memory. The platform does not support Last-Event-ID resume:
reconnect and re-read the snapshot.
Webhooks
$genuine = BardiyaClient::verifyWebhookSignature( $secret, $timestamp, $request->getContent(), $signatureHeader );
The scheme is v1=hex(HMAC-SHA256(secret, "<timestamp>." + body)) with a
300-second replay window. Always verify the raw body: re-encoding the JSON
changes the digest. hash_equals is used for the comparison.
Building
python sdk/php/generate.py --apply # regenerate from the shared contract
composer install
vendor/bin/phpunit
python sdk/php/generate.py without --apply is the drift gate.
License
Apache-2.0. See LICENSE and NOTICE.