Skip to content

Commit

Permalink
[TASK] Allow filter by sport
Browse files Browse the repository at this point in the history
  • Loading branch information
Woeler committed Nov 2, 2024
1 parent 21065fc commit 2515efb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Api/Komoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,29 @@ public function getUserId(): ?int
return $this->userid;
}

public function getTours(int $page = 0, int $limit = 50, ?TourType $type = null): array
public function getTours(int $page = 0, int $limit = 50, ?TourType $type = null, ?Sport $sport = null): array
{
$params = ['page' => $page, 'limit' => $limit];

if ($type !== null) {
$params += ['type' => $type->value];
}
if ($sport !== null) {
$params += ['sport_types' => $sport->value];
}

return json_decode($this->client->get('https://www.komoot.com/api/v007/users/'.$this->userid.'/tours/', [
'auth' => [$this->email, $this->password],
'query' => $params,
])->getBody()->getContents(), true);
}

public function getAllTours(?TourType $type = null): array
public function getAllTours(?TourType $type = null, ?Sport $sport = null): array
{
$page = 0;
$all = [];
while (true) {
$tours = $this->getTours($page, 50, $type);
$tours = $this->getTours($page, 50, $type, $sport);
$all = array_merge($all, $tours['_embedded']['tours']);

if ($page + 1 === $tours['page']['totalPages']) {
Expand Down

0 comments on commit 2515efb

Please sign in to comment.