Skip to content

Commit

Permalink
feat: added continent resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 20, 2024
1 parent f82ed55 commit 3683d3f
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 129 deletions.
12 changes: 3 additions & 9 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -1943,22 +1943,17 @@ $response = $api->cities()->getAllBySearchQuery('lisbon');
### Continents

- [Official documentation](https://docs.sportmonks.com/football/v/core-api/endpoints/continents)
- Cache default max age: `1 day`

#### `getAll`

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

Get all continents:

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

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

#### `getById`
Expand All @@ -1970,8 +1965,7 @@ getById(int $id): ContinentItem
Get continent by id:

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

### Countries
Expand Down
68 changes: 0 additions & 68 deletions src/Endpoint/ContinentEndpoint.php

This file was deleted.

41 changes: 41 additions & 0 deletions src/Resource/ContinentResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Entity\Response\ContinentCollection;
use ProgrammatorDev\SportMonksFootball\Entity\Response\ContinentItem;
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait;
use Psr\Http\Client\ClientExceptionInterface;

class ContinentResource extends Resource
{
use PaginationTrait;

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

return new ContinentCollection($data);
}

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

return new ContinentItem($data);
}
}
11 changes: 6 additions & 5 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\CityResource;
use ProgrammatorDev\SportMonksFootball\Resource\CoachResource;
use ProgrammatorDev\SportMonksFootball\Resource\CommentaryResource;
use ProgrammatorDev\SportMonksFootball\Resource\ContinentResource;

class SportMonksFootball extends Api
{
Expand Down Expand Up @@ -67,11 +68,11 @@ public function commentaries(): CommentaryResource
return new CommentaryResource($this);
}

// public function continents(): ContinentEndpoint
// {
// return new ContinentEndpoint($this);
// }
//
public function continents(): ContinentResource
{
return new ContinentResource($this);
}

// public function countries(): CountryEndpoint
// {
// return new CountryEndpoint($this);
Expand Down
47 changes: 0 additions & 47 deletions tests/ContinentEndpointTest_.php

This file was deleted.

37 changes: 37 additions & 0 deletions tests/Integration/ContinentResourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Test\Integration;

use ProgrammatorDev\SportMonksFootball\Entity\Response\ContinentCollection;
use ProgrammatorDev\SportMonksFootball\Entity\Response\ContinentItem;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;
use ProgrammatorDev\SportMonksFootball\Test\MockResponse;
use ProgrammatorDev\SportMonksFootball\Test\Util\TestCollectionResponseTrait;
use ProgrammatorDev\SportMonksFootball\Test\Util\TestItemResponseTrait;

class ContinentResourceTest extends AbstractTest
{
use TestItemResponseTrait;
use TestCollectionResponseTrait;

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

public static function provideCollectionResponseData(): \Generator
{
yield 'get all' => [
ContinentCollection::class,
MockResponse::CONTINENT_COLLECTION_DATA,
'continents',
'getAll'
];
}
}
2 changes: 2 additions & 0 deletions tests/Integration/SportMonksFootballTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\CityResource;
use ProgrammatorDev\SportMonksFootball\Resource\CoachResource;
use ProgrammatorDev\SportMonksFootball\Resource\CommentaryResource;
use ProgrammatorDev\SportMonksFootball\Resource\ContinentResource;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;

class SportMonksFootballTest extends AbstractTest
Expand All @@ -16,5 +17,6 @@ public function testMethods()
$this->assertInstanceOf(CityResource::class, $this->api->cities());
$this->assertInstanceOf(CoachResource::class, $this->api->coaches());
$this->assertInstanceOf(CommentaryResource::class, $this->api->commentaries());
$this->assertInstanceOf(ContinentResource::class, $this->api->continents());
}
}

0 comments on commit 3683d3f

Please sign in to comment.