Skip to content

Commit

Permalink
feat: added venue resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 22, 2024
1 parent 5972081 commit f6fba6d
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 139 deletions.
28 changes: 7 additions & 21 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ while the [`<Entity>Collection`](05-entities.md#entitycollection) `getData()` me

For example, when requesting a fixture by id, the response will be a `FixtureItem` object and the `getData()` method will return a [`Fixture`](05-entities.md#fixture) object.
The same way that when requesting all fixtures, the response will be a `FixtureCollection` object and the `getData()` method will return an array of [`Fixture`](05-entities.md#fixture) objects.
Check the [responses objects](05-entities.md#response-objects) for more information.
Check the [responses entities](05-entities.md#response-entities) for more information.

```php
// returns a FixtureItem object
Expand Down Expand Up @@ -1272,22 +1272,17 @@ $response = $api->tvStations()->getAllByFixtureId(1);
### Venues

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

#### `getAll`

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

Get all venues:

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

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

#### `getById`
Expand All @@ -1299,8 +1294,7 @@ getById(int $id): VenueItem
Get venue by id:

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

#### `getAllBySeasonId`
Expand All @@ -1312,27 +1306,19 @@ getAllBySeasonId(int $seasonId): VenueCollection
Get all venues by season id:

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

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

#### `getAllBySearchQuery`

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

Get all venues by search query:

```php
$venues = $sportMonksFootball->venues()->getAllBySearchQuery('alvalade');

foreach ($venues->getData() as $venue) {
echo $venue->getName();
}
$response = $api->venues()->getAllBySearchQuery('alvalade');
```

## Odds Endpoints
Expand Down
114 changes: 0 additions & 114 deletions src/Endpoint/VenueEndpoint.php

This file was deleted.

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

class VenueResource extends Resource
{
use PaginationTrait;

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

return new VenueCollection($data);
}

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

return new VenueItem($data);
}

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

return new VenueCollection($data);
}

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

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

return new VenueCollection($data);
}
}
9 changes: 5 additions & 4 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\TransferResource;
use ProgrammatorDev\SportMonksFootball\Resource\TvStationResource;
use ProgrammatorDev\SportMonksFootball\Resource\TypeResource;
use ProgrammatorDev\SportMonksFootball\Resource\VenueResource;

class SportMonksFootball extends Api
{
Expand Down Expand Up @@ -222,10 +223,10 @@ public function types(): TypeResource
return new TypeResource($this);
}

// public function venues(): VenueEndpoint
// {
// return new VenueEndpoint($this);
// }
public function venues(): VenueResource
{
return new VenueResource($this);
}

private function configureOptions(array $options): array
{
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/SportMonksFootballTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\TransferResource;
use ProgrammatorDev\SportMonksFootball\Resource\TvStationResource;
use ProgrammatorDev\SportMonksFootball\Resource\TypeResource;
use ProgrammatorDev\SportMonksFootball\Resource\VenueResource;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;

class SportMonksFootballTest extends AbstractTest
Expand Down Expand Up @@ -68,5 +69,6 @@ public function testMethods()
$this->assertInstanceOf(TransferResource::class, $this->api->transfers());
$this->assertInstanceOf(TvStationResource::class, $this->api->tvStations());
$this->assertInstanceOf(TypeResource::class, $this->api->types());
$this->assertInstanceOf(VenueResource::class, $this->api->venues());
}
}
62 changes: 62 additions & 0 deletions tests/Integration/VenueResourceTest.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\VenueCollection;
use ProgrammatorDev\SportMonksFootball\Entity\Response\VenueItem;
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 VenueResourceTest extends AbstractTest
{
use TestItemResponseTrait;
use TestCollectionResponseTrait;
use TestValidationExceptionTrait;

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

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

public static function provideValidationExceptionData(): \Generator
{
yield 'get all by search query, blank query' => [
'venues',
'getAllBySearchQuery',
['']
];
}
}
Loading

0 comments on commit f6fba6d

Please sign in to comment.