Skip to content

Commit

Permalink
feat: added country resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 20, 2024
1 parent 3683d3f commit cace46d
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 190 deletions.
20 changes: 5 additions & 15 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -1971,22 +1971,17 @@ $response = $api->continents()->getById(1);
### Countries

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

#### `getAll`

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

Get all countries:

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

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

#### `getById`
Expand All @@ -1998,24 +1993,19 @@ getById(int $id): CountryItem
Get country by id:

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

#### `getAllBySearchQuery`

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

Get all countries by search query:

```php
$countries = $sportMonksFootball->countries()->getAllBySearchQuery('portugal');

foreach ($countries->getData() as $country) {
echo $country->getName();
}
$response = $api->countries()->getAllBySearchQuery('country');
```

### Filters
Expand Down
98 changes: 0 additions & 98 deletions src/Endpoint/CountryEndpoint.php

This file was deleted.

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

namespace ProgrammatorDev\SportMonksFootball\Resource;

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

class CountryResource extends Resource
{
use PaginationTrait;

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

return new CountryCollection($data);
}

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

return new CountryItem($data);
}

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

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

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

class SportMonksFootball extends Api
{
Expand Down Expand Up @@ -73,11 +74,11 @@ public function continents(): ContinentResource
return new ContinentResource($this);
}

// public function countries(): CountryEndpoint
// {
// return new CountryEndpoint($this);
// }
//
public function countries(): CountryResource
{
return new CountryResource($this);
}

// public function filters(): FilterEndpoint
// {
// return new FilterEndpoint($this);
Expand Down
69 changes: 0 additions & 69 deletions tests/CountryEndpointTest_.php

This file was deleted.

6 changes: 5 additions & 1 deletion tests/Integration/BookmakerResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public static function provideCollectionResponseData(): \Generator

public static function provideValidationExceptionData(): \Generator
{
yield 'get all by search query, blank query' => ['bookmakers', 'getAllBySearchQuery', ['']];
yield 'get all by search query, blank query' => [
'bookmakers',
'getAllBySearchQuery',
['']
];
}
}
6 changes: 5 additions & 1 deletion tests/Integration/CityResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static function provideCollectionResponseData(): \Generator

public static function provideValidationExceptionData(): \Generator
{
yield 'get all by search query, blank query' => ['cities', 'getAllBySearchQuery', ['']];
yield 'get all by search query, blank query' => [
'cities',
'getAllBySearchQuery',
['']
];
}
}
6 changes: 5 additions & 1 deletion tests/Integration/CoachResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public static function provideCollectionResponseData(): \Generator

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

0 comments on commit cace46d

Please sign in to comment.