Skip to content

Commit

Permalink
feat: added round resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 22, 2024
1 parent d86ba3e commit eeabb10
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 213 deletions.
26 changes: 6 additions & 20 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,22 +661,17 @@ $response = $api->rivals()->getAllByTeamId(1);
### Rounds

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

#### `getAll`

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

Get all rounds:

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

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

#### `getById`
Expand All @@ -688,8 +683,7 @@ getById(int $id): RoundItem
Get round by id:

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

#### `getAllBySeasonId`
Expand All @@ -701,27 +695,19 @@ getAllBySeasonId(int $seasonId): RoundCollection
Get all rounds by season id:

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

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

#### `getAllBySearchQuery`

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

Get all rounds by search query:

```php
$rounds = $sportMonksFootball->rounds()->getAllBySearchQuery('30');

foreach ($rounds->getData() as $round) {
echo $round->getName();
}
$response = $api->rounds()->getAllBySearchQuery('30');
```

### Schedules
Expand Down
114 changes: 0 additions & 114 deletions src/Endpoint/RoundEndpoint.php

This file was deleted.

75 changes: 75 additions & 0 deletions src/Resource/RoundResource.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\RoundCollection;
use ProgrammatorDev\SportMonksFootball\Entity\Response\RoundItem;
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait;
use ProgrammatorDev\Validator\Exception\ValidationException;
use Psr\Http\Client\ClientExceptionInterface;

class RoundResource extends Resource
{
use PaginationTrait;

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

return new RoundCollection($data);
}

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

return new RoundItem($data);
}

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

return new RoundCollection($data);
}

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

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

return new RoundCollection($data);
}
}
11 changes: 6 additions & 5 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\RefereeResource;
use ProgrammatorDev\SportMonksFootball\Resource\RegionResource;
use ProgrammatorDev\SportMonksFootball\Resource\RivalResource;
use ProgrammatorDev\SportMonksFootball\Resource\RoundResource;

class SportMonksFootball extends Api
{
Expand Down Expand Up @@ -138,11 +139,11 @@ public function rivals(): RivalResource
return new RivalResource($this);
}

// public function rounds(): RoundEndpoint
// {
// return new RoundEndpoint($this);
// }
//
public function rounds(): RoundResource
{
return new RoundResource($this);
}

// public function schedules(): ScheduleEndpoint
// {
// return new ScheduleEndpoint($this);
Expand Down
62 changes: 62 additions & 0 deletions tests/Integration/RoundResourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Test\Integration;

use ProgrammatorDev\SportMonksFootball\Entity\Response\RoundCollection;
use ProgrammatorDev\SportMonksFootball\Entity\Response\RoundItem;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;
use ProgrammatorDev\SportMonksFootball\Test\MockResponse;
use ProgrammatorDev\SportMonksFootball\Test\Util\TestCollectionResponseTrait;
use ProgrammatorDev\SportMonksFootball\Test\Util\TestItemResponseTrait;
use ProgrammatorDev\SportMonksFootball\Test\Util\TestValidationExceptionTrait;

class RoundResourceTest extends AbstractTest
{
use TestItemResponseTrait;
use TestCollectionResponseTrait;
use TestValidationExceptionTrait;

public static function provideItemResponseData(): \Generator
{
yield 'get by id' => [
RoundItem::class,
MockResponse::ROUND_ITEM_DATA,
'rounds',
'getById',
[1]
];
}

public static function provideCollectionResponseData(): \Generator
{
yield 'get all' => [
RoundCollection::class,
MockResponse::ROUND_COLLECTION_DATA,
'rounds',
'getAll'
];
yield 'get all by season id' => [
RoundCollection::class,
MockResponse::ROUND_COLLECTION_DATA,
'rounds',
'getAllBySeasonId',
[1]
];
yield 'get all by search query' => [
RoundCollection::class,
MockResponse::ROUND_COLLECTION_DATA,
'rounds',
'getAllBySearchQuery',
['test']
];
}

public static function provideValidationExceptionData(): \Generator
{
yield 'get all by search query, blank query' => [
'rounds',
'getAllBySearchQuery',
['']
];
}
}
2 changes: 2 additions & 0 deletions tests/Integration/SportMonksFootballTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\RefereeResource;
use ProgrammatorDev\SportMonksFootball\Resource\RegionResource;
use ProgrammatorDev\SportMonksFootball\Resource\RivalResource;
use ProgrammatorDev\SportMonksFootball\Resource\RoundResource;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;

class SportMonksFootballTest extends AbstractTest
Expand All @@ -40,5 +41,6 @@ public function testMethods()
$this->assertInstanceOf(RefereeResource::class, $this->api->referees());
$this->assertInstanceOf(RegionResource::class, $this->api->regions());
$this->assertInstanceOf(RivalResource::class, $this->api->rivals());
$this->assertInstanceOf(RoundResource::class, $this->api->rounds());
}
}
Loading

0 comments on commit eeabb10

Please sign in to comment.