feat: FuelPriceService with OAuth token caching
Also extend Pest TestCase to Unit tests and guard MySQL-only migration DDL (composite PK + PARTITION BY) behind a driver check so in-memory SQLite tests can run migrations cleanly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
28
app/Services/FuelPriceService.php
Normal file
28
app/Services/FuelPriceService.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class FuelPriceService
|
||||
{
|
||||
private const TOKEN_CACHE_KEY = 'fuel_finder_access_token';
|
||||
|
||||
public function __construct(
|
||||
private readonly StationTaggingService $taggingService,
|
||||
) {}
|
||||
|
||||
public function getAccessToken(): string
|
||||
{
|
||||
return Cache::remember(self::TOKEN_CACHE_KEY, 3540, function (): string {
|
||||
$response = Http::timeout(10)
|
||||
->post(config('services.fuel_finder.base_url').'/oauth/generate_access_token', [
|
||||
'client_id' => config('services.fuel_finder.client_id'),
|
||||
'client_secret' => config('services.fuel_finder.client_secret'),
|
||||
]);
|
||||
|
||||
return $response->json('data.access_token');
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user