From 3785a0e7c63ed37188d7244e793181e14576918e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Pimpa=CC=83o?= Date: Wed, 22 May 2024 18:26:42 +0100 Subject: [PATCH] feat: added timezone resource --- docs/03-supported-endpoints.md | 7 +----- src/Endpoint/TimezoneEndpoint.php | 26 -------------------- src/Resource/TimezoneResource.php | 22 +++++++++++++++++ src/SportMonksFootball.php | 11 +++++---- tests/Integration/SportMonksFootballTest.php | 2 ++ tests/Integration/TimezoneResourceTest.php | 23 +++++++++++++++++ tests/TimezoneEndpointTest_.php | 25 ------------------- 7 files changed, 54 insertions(+), 62 deletions(-) delete mode 100644 src/Endpoint/TimezoneEndpoint.php create mode 100644 src/Resource/TimezoneResource.php create mode 100644 tests/Integration/TimezoneResourceTest.php delete mode 100644 tests/TimezoneEndpointTest_.php diff --git a/docs/03-supported-endpoints.md b/docs/03-supported-endpoints.md index 3913bba..e2291ee 100644 --- a/docs/03-supported-endpoints.md +++ b/docs/03-supported-endpoints.md @@ -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` @@ -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 diff --git a/src/Endpoint/TimezoneEndpoint.php b/src/Endpoint/TimezoneEndpoint.php deleted file mode 100644 index ba14f9b..0000000 --- a/src/Endpoint/TimezoneEndpoint.php +++ /dev/null @@ -1,26 +0,0 @@ -sendRequest( - method: 'GET', - path: '/v3/core/timezones' - ); - - return new TimezoneCollection($response); - } -} \ No newline at end of file diff --git a/src/Resource/TimezoneResource.php b/src/Resource/TimezoneResource.php new file mode 100644 index 0000000..85d3632 --- /dev/null +++ b/src/Resource/TimezoneResource.php @@ -0,0 +1,22 @@ +api->request( + method: 'GET', + path: '/v3/core/timezones' + ); + + return new TimezoneCollection($data); + } +} \ No newline at end of file diff --git a/src/SportMonksFootball.php b/src/SportMonksFootball.php index f9c150a..d02c142 100644 --- a/src/SportMonksFootball.php +++ b/src/SportMonksFootball.php @@ -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 { @@ -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); diff --git a/tests/Integration/SportMonksFootballTest.php b/tests/Integration/SportMonksFootballTest.php index 71efaf7..f02eea3 100644 --- a/tests/Integration/SportMonksFootballTest.php +++ b/tests/Integration/SportMonksFootballTest.php @@ -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 @@ -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()); } } \ No newline at end of file diff --git a/tests/Integration/TimezoneResourceTest.php b/tests/Integration/TimezoneResourceTest.php new file mode 100644 index 0000000..a0d9121 --- /dev/null +++ b/tests/Integration/TimezoneResourceTest.php @@ -0,0 +1,23 @@ + [ + TimezoneCollection::class, + MockResponse::TIMEZONE_COLLECTION_DATA, + 'timezones', + 'getAll' + ]; + } +} \ No newline at end of file diff --git a/tests/TimezoneEndpointTest_.php b/tests/TimezoneEndpointTest_.php deleted file mode 100644 index da1a5e3..0000000 --- a/tests/TimezoneEndpointTest_.php +++ /dev/null @@ -1,25 +0,0 @@ - [ - MockResponse::TIMEZONE_COLLECTION_DATA, - 'timezones', - 'getAll', - [] - ]; - } - - private function assertResponse(string $timezone): void - { - $this->assertSame('Africa/Abidjan', $timezone); - } -} \ No newline at end of file