Skip to content

Commit

Permalink
feat: added timezone resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 22, 2024
1 parent 12fbf2e commit 3785a0e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 62 deletions.
7 changes: 1 addition & 6 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,6 @@ $response = $api->regions()->getAllBySearchQuery('lisboa');
### Timezones

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

#### `getAll`

Expand All @@ -1714,11 +1713,7 @@ getAll(): TimezoneCollection
Get all timezones:

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

foreach ($timezones->getData() as $timezone) {
echo $timezone;
}
$response = $api->timezones()->getAll();
```

### Types
Expand Down
26 changes: 0 additions & 26 deletions src/Endpoint/TimezoneEndpoint.php

This file was deleted.

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

namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Entity\Response\TimezoneCollection;
use Psr\Http\Client\ClientExceptionInterface;

class TimezoneResource extends Resource
{
/**
* @throws ClientExceptionInterface
*/
public function getAll(): TimezoneCollection
{
$data = $this->api->request(
method: 'GET',
path: '/v3/core/timezones'
);

return new TimezoneCollection($data);
}
}
11 changes: 6 additions & 5 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\StatisticResource;
use ProgrammatorDev\SportMonksFootball\Resource\TeamResource;
use ProgrammatorDev\SportMonksFootball\Resource\TeamSquadResource;
use ProgrammatorDev\SportMonksFootball\Resource\TimezoneResource;

class SportMonksFootball extends Api
{
Expand Down Expand Up @@ -192,11 +193,11 @@ public function teamSquads(): TeamSquadResource
return new TeamSquadResource($this);
}

// public function timezones(): TimezoneEndpoint
// {
// return new TimezoneEndpoint($this);
// }
//
public function timezones(): TimezoneResource
{
return new TimezoneResource($this);
}

// public function topscorers(): TopscorerEndpoint
// {
// return new TopscorerEndpoint($this);
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/SportMonksFootballTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\StatisticResource;
use ProgrammatorDev\SportMonksFootball\Resource\TeamResource;
use ProgrammatorDev\SportMonksFootball\Resource\TeamSquadResource;
use ProgrammatorDev\SportMonksFootball\Resource\TimezoneResource;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;

class SportMonksFootballTest extends AbstractTest
Expand Down Expand Up @@ -58,5 +59,6 @@ public function testMethods()
$this->assertInstanceOf(StatisticResource::class, $this->api->statistics());
$this->assertInstanceOf(TeamResource::class, $this->api->teams());
$this->assertInstanceOf(TeamSquadResource::class, $this->api->teamSquads());
$this->assertInstanceOf(TimezoneResource::class, $this->api->timezones());
}
}
23 changes: 23 additions & 0 deletions tests/Integration/TimezoneResourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Test\Integration;

use ProgrammatorDev\SportMonksFootball\Entity\Response\TimezoneCollection;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;
use ProgrammatorDev\SportMonksFootball\Test\MockResponse;
use ProgrammatorDev\SportMonksFootball\Test\Util\TestCollectionResponseTrait;

class TimezoneResourceTest extends AbstractTest
{
use TestCollectionResponseTrait;

public static function provideCollectionResponseData(): \Generator
{
yield 'get all' => [
TimezoneCollection::class,
MockResponse::TIMEZONE_COLLECTION_DATA,
'timezones',
'getAll'
];
}
}
25 changes: 0 additions & 25 deletions tests/TimezoneEndpointTest_.php

This file was deleted.

0 comments on commit 3785a0e

Please sign in to comment.