PHP code example of andydefer / laravel-locationiq
1. Go to this page and download the library: Download andydefer/laravel-locationiq 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/ */
declare(strict_types=1);
namespace AndyDefer\LaravelLocationIq\Contracts;
use AndyDefer\PhpLocationIq\Contracts\LocationIqClientInterface;
use AndyDefer\PhpLocationIq\Contracts\NominatimClientInterface;
use AndyDefer\PhpLocationIq\Enums\LocationIqBaseUrl;
use AndyDefer\PhpLocationIq\Enums\NominatimBaseUrl;
interface LocationIqConfigInterface
{
public function getApiKey(): string;
public function getBaseUrl(): LocationIqBaseUrl;
/**
* @return class-string<LocationIqClientInterface>
*/
public function getLocationIqClientFqcn(): string;
public function getNominatimBaseUrl(): NominatimBaseUrl;
public function getUserAgent(): string;
/**
* @return class-string<NominatimClientInterface>
*/
public function getNominatimClientFqcn(): string;
public function getDefaultDirectionsProfile(): string;
public function getDefaultAcceptLanguage(): ?string;
}
enum ErrorCode: string implements ErrorDescribable
{
case INVALID_REQUEST = 'INVALID_REQUEST';
case INVALID_KEY = 'INVALID_KEY';
case ACCESS_RESTRICTED = 'ACCESS_RESTRICTED';
case UNABLE_TO_GEOCODE = 'UNABLE_TO_GEOCODE';
case RATE_LIMITED_DAY = 'RATE_LIMITED_DAY';
case INVALID_OPTIONS = 'INVALID_OPTIONS';
case INVALID_COORDINATES = 'INVALID_COORDINATES';
case MISSING_API_KEY = 'MISSING_API_KEY';
case NO_TABLE = 'NO_TABLE';
case NOT_IMPLEMENTED = 'NOT_IMPLEMENTED';
case UNKNOWN_ERROR = 'UNKNOWN_ERROR';
public static function fromApiMessage(string $message): self;
}
public function test_it_returns_day_balance_on_success(): void
{
// Arrange: the API will answer 200 with a positive balance
$this->locationIqClient->addBalanceSuccessResponse(30000);
// Act: hit the route
$response = $this->postJson('/api/locationiq-balance');
// Assert: 200 and balance.day exposed
$response->assertOk();
$response->assertJsonPath('balance.day', 30000);
}
$this->app->instance(LocationIqConfigInterface::class, new RestrictedLocationIqConfig);