Skip to content

Commit

Permalink
feat: added stage resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 22, 2024
1 parent 3b9ba11 commit b01cc74
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 229 deletions.
26 changes: 6 additions & 20 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -805,22 +805,17 @@ $response = $api->seasons()->getAllBySearchQuery('2024');
### Stages

- [Official documentation](https://docs.sportmonks.com/football/endpoints-and-entities/endpoints/stages)
- Cache default max age: `1 day`

#### `getAll`

```php
getAll(int $page = 1, int $perPage = 25, string $order = 'asc'): StageCollection
getAll(): StageCollection
```

Get all stages:

```php
$stages = $sportMonksFootball->stages()->getAll();

foreach ($stages->getData() as $stage) {
echo $stage->getName();
}
$response = $api->stages()->getAll();
```

#### `getById`
Expand All @@ -832,8 +827,7 @@ getById(int $id): StageItem
Get stage by id:

```php
$stage = $sportMonksFootball->stages()->getById(1);
echo $stage->getData()->getName();
$response = $api->stages()->getById(1);
```

#### `getAllBySeasonId`
Expand All @@ -845,27 +839,19 @@ getAllBySeasonId(int $seasonId): StageCollection
Get all stages by season id:

```php
$stages = $sportMonksFootball->stages()->getAllBySeasonId(1);

foreach ($stages->getData() as $stage) {
echo $stage->getName();
}
$response = $api->stages()->getAllBySeasonId(1);
```

#### `getAllBySearchQuery`

```php
getAllBySearchQuery(string $query, int $page = 1, int $perPage = 25, string $order = 'asc'): StageCollection
getAllBySearchQuery(string $query): StageCollection
```

Get all stages by search query:

```php
$stages = $sportMonksFootball->stages()->getAllBySearchQuery('champions');

foreach ($stages->getData() as $stage) {
echo $stage->getName();
}
$response = $api->stages()->getAllBySearchQuery('champions');
```

### Standings
Expand Down
114 changes: 0 additions & 114 deletions src/Endpoint/StageEndpoint.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Resource/BookmakerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getAllByFixtureId(int $fixtureId): BookmakerCollection
*/
public function getAllBySearchQuery(string $query): BookmakerCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/CityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getById(int $id): CityItem
*/
public function getAllBySearchQuery(string $query): CityCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/CoachResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getAllByCountryId(int $countryId): CoachCollection
*/
public function getAllBySearchQuery(string $query): CoachCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/CountryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getById(int $id): CountryItem
*/
public function getAllBySearchQuery(string $query): CountryCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/FixtureResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function getAllByHeadToHead(int $teamId1, int $teamId2): FixtureCollectio
*/
public function getAllBySearchQuery(string $query): FixtureCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/LeagueResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getAllByCountryId(int $countryId): LeagueCollection
*/
public function getAllBySearchQuery(string $query): LeagueCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/MarketResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getById(int $id): MarketItem
*/
public function getAllBySearchQuery(string $query): MarketCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/PlayerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getAllByCountryId(int $countryId): PlayerCollection
*/
public function getAllBySearchQuery(string $query): PlayerCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/RefereeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getAllBySeasonId(int $seasonId): RefereeCollection
*/
public function getAllBySearchQuery(string $query): RefereeCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/RegionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getById(int $id): RegionItem
*/
public function getAllBySearchQuery(string $query): RegionCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/RoundResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getAllBySeasonId(int $seasonId): RoundCollection
*/
public function getAllBySearchQuery(string $query): RoundCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/SeasonResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getAllByTeamId(int $teamId): SeasonCollection
*/
public function getAllBySearchQuery(string $query): SeasonCollection
{
$this->validateQuery($query, 'query');
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
Expand Down
75 changes: 75 additions & 0 deletions src/Resource/StageResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Entity\Response\StageCollection;
use ProgrammatorDev\SportMonksFootball\Entity\Response\StageItem;
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait;
use ProgrammatorDev\Validator\Exception\ValidationException;
use Psr\Http\Client\ClientExceptionInterface;

class StageResource extends Resource
{
use PaginationTrait;

/**
* @throws ClientExceptionInterface
*/
public function getAll(): StageCollection
{
$data = $this->api->request(
method: 'GET',
path: '/v3/football/stages'
);

return new StageCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getById(int $id): StageItem
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/stages/{id}', [
'id' => $id
])
);

return new StageItem($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllBySeasonId(int $seasonId): StageCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/stages/seasons/{seasonId}', [
'seasonId' => $seasonId
])
);

return new StageCollection($data);
}

/**
* @throws ValidationException
* @throws ClientExceptionInterface
*/
public function getAllBySearchQuery(string $query): StageCollection
{
$this->validateQuery($query);

$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/stages/search/{query}', [
'query' => $query
])
);

return new StageCollection($data);
}
}
2 changes: 1 addition & 1 deletion src/Resource/Util/ValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait ValidationTrait
/**
* @throws ValidationException
*/
protected function validateQuery(string $query, string $name): void
protected function validateQuery(string $query, string $name = 'query'): void
{
Validator::notBlank()->assert($query, $name);
}
Expand Down
Loading

0 comments on commit b01cc74

Please sign in to comment.