first commit

This commit is contained in:
2025-10-02 22:52:13 +03:00
commit 5d8d08d2f4
137 changed files with 18187 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace App\Services\ExerciseDb;
use GuzzleHttp\Client;
class ApiService
{
public const PER_PAGE = 50;
public const API_BASE_URL = 'https://www.exercisedb.dev';
public const EXERCISE_URI = '/api/v1/exercises';
/**
* Fetch a page of exercises from ExerciseDB API.
*
* @return array<int, array<string, mixed>>
*/
public function fetch(int $page = 1): array
{
$results = $this->call(
self::EXERCISE_URI,
$this->pagination($page),
);
$decoded = json_decode($results, true);
return is_array($decoded) ? $decoded : [];
}
private function pagination(int $page = 1): array
{
return [
'offset' => ($page - 1) * self::PER_PAGE,
'limit' => self::PER_PAGE,
];
}
private function call(
string $uri,
array $params = [],
): string {
$client = new Client();
$url = self::API_BASE_URL . $uri;
return $client->request('GET', $url, [
'query' => $params,
])->getBody()->getContents();
}
}