diff --git a/docs/03-supported-endpoints.md b/docs/03-supported-endpoints.md index 6a075f5..9be3d3d 100644 --- a/docs/03-supported-endpoints.md +++ b/docs/03-supported-endpoints.md @@ -465,8 +465,6 @@ $response = $api->leagues()->getAllCurrentByTeamId(1); ### Livescores - [Official documentation](https://docs.sportmonks.com/football/endpoints-and-entities/endpoints/livescores) -- Cache default max age: `1 minute` - - `getAllLastUpdated` cache max age: `10 seconds` #### `getAll` @@ -477,11 +475,7 @@ getAll(): FixtureCollection Get all fixtures of the current day: ```php -$fixtures = $sportMonksFootball->livescores()->getAll(); - -foreach ($fixtures->getData() as $fixture) { - echo $fixture->getName(); -} +$response = $api->livescores()->getAll(); ``` #### `getAllInplay` @@ -493,11 +487,7 @@ getAllInplay(): FixtureCollection Get all fixtures that are already live, that will start within 15 minutes or that have finished in the past 15 minutes: ```php -$fixtures = $sportMonksFootball->livescores()->getAllInplay(); - -foreach ($fixtures->getData() as $fixture) { - echo $fixture->getName(); -} +$response = $api->livescores()->getAllInplay(); ``` #### `getAllLastUpdated` @@ -509,16 +499,9 @@ getAllLastUpdated(): FixtureCollection Get all fixtures that received updates in the last 10 seconds: ```php -$fixtures = $sportMonksFootball->livescores()->getAllLastUpdated(); - -foreach ($fixtures->getData() as $fixture) { - echo $fixture->getName(); -} +$response = $api->livescores()->getAllLastUpdated(); ``` -> **Note** -> Cache max age is forced to `10 seconds` on this endpoint. - ### Players - [Official documentation](https://docs.sportmonks.com/football/endpoints-and-entities/endpoints/players) diff --git a/src/Endpoint/LivescoreEndpoint.php b/src/Endpoint/LivescoreEndpoint.php deleted file mode 100644 index 12c3270..0000000 --- a/src/Endpoint/LivescoreEndpoint.php +++ /dev/null @@ -1,64 +0,0 @@ -sendRequest( - method: 'GET', - path: '/v3/football/livescores' - ); - - return new FixtureCollection($response); - } - - /** - * @throws Exception - * @throws ApiErrorException - */ - public function getAllInplay(): FixtureCollection - { - $response = $this->sendRequest( - method: 'GET', - path: '/v3/football/livescores/inplay' - ); - - return new FixtureCollection($response); - } - - /** - * @throws Exception - * @throws ApiErrorException - */ - public function getAllLastUpdated(): FixtureCollection - { - // Force cache max age - $this->cacheTtl = 10; - - $response = $this->sendRequest( - method: 'GET', - path: '/v3/football/livescores/latest' - ); - - return new FixtureCollection($response); - } -} \ No newline at end of file diff --git a/src/Resource/LivescoreResource.php b/src/Resource/LivescoreResource.php new file mode 100644 index 0000000..71e59a2 --- /dev/null +++ b/src/Resource/LivescoreResource.php @@ -0,0 +1,48 @@ +api->request( + method: 'GET', + path: '/v3/football/livescores' + ); + + return new FixtureCollection($data); + } + + /** + * @throws ClientExceptionInterface + */ + public function getAllInplay(): FixtureCollection + { + $data = $this->api->request( + method: 'GET', + path: '/v3/football/livescores/inplay' + ); + + return new FixtureCollection($data); + } + + /** + * @throws ClientExceptionInterface + */ + public function getAllLastUpdated(): FixtureCollection + { + $data = $this->api->request( + method: 'GET', + path: '/v3/football/livescores/latest' + ); + + return new FixtureCollection($data); + } +} \ No newline at end of file diff --git a/src/SportMonksFootball.php b/src/SportMonksFootball.php index 3507de0..27df0a2 100644 --- a/src/SportMonksFootball.php +++ b/src/SportMonksFootball.php @@ -36,6 +36,7 @@ use ProgrammatorDev\SportMonksFootball\Resource\FilterResource; use ProgrammatorDev\SportMonksFootball\Resource\FixtureResource; use ProgrammatorDev\SportMonksFootball\Resource\LeagueResource; +use ProgrammatorDev\SportMonksFootball\Resource\LivescoreResource; class SportMonksFootball extends Api { @@ -97,11 +98,11 @@ public function leagues(): LeagueResource return new LeagueResource($this); } -// public function livescores(): LivescoreEndpoint -// { -// return new LivescoreEndpoint($this); -// } -// + public function livescores(): LivescoreResource + { + return new LivescoreResource($this); + } + // public function markets(): MarketEndpoint // { // return new MarketEndpoint($this); diff --git a/tests/Integration/LivescoreResourceTest.php b/tests/Integration/LivescoreResourceTest.php new file mode 100644 index 0000000..681a3e1 --- /dev/null +++ b/tests/Integration/LivescoreResourceTest.php @@ -0,0 +1,37 @@ + [ + FixtureCollection::class, + MockResponse::FIXTURE_COLLECTION_DATA, + 'livescores', + 'getAll' + ]; + yield 'get all inplay' => [ + FixtureCollection::class, + MockResponse::FIXTURE_COLLECTION_DATA, + 'livescores', + 'getAllInplay' + ]; + yield 'get all last updated' => [ + FixtureCollection::class, + MockResponse::FIXTURE_COLLECTION_DATA, + 'livescores', + 'getAllLastUpdated' + ]; + } +} \ No newline at end of file diff --git a/tests/Integration/SportMonksFootballTest.php b/tests/Integration/SportMonksFootballTest.php index bd8cac9..b06a40d 100644 --- a/tests/Integration/SportMonksFootballTest.php +++ b/tests/Integration/SportMonksFootballTest.php @@ -11,6 +11,7 @@ use ProgrammatorDev\SportMonksFootball\Resource\FilterResource; use ProgrammatorDev\SportMonksFootball\Resource\FixtureResource; use ProgrammatorDev\SportMonksFootball\Resource\LeagueResource; +use ProgrammatorDev\SportMonksFootball\Resource\LivescoreResource; use ProgrammatorDev\SportMonksFootball\Test\AbstractTest; class SportMonksFootballTest extends AbstractTest @@ -26,5 +27,6 @@ public function testMethods() $this->assertInstanceOf(FilterResource::class, $this->api->filters()); $this->assertInstanceOf(FixtureResource::class, $this->api->fixtures()); $this->assertInstanceOf(LeagueResource::class, $this->api->leagues()); + $this->assertInstanceOf(LivescoreResource::class, $this->api->livescores()); } } \ No newline at end of file diff --git a/tests/LivescoreEndpointTest_.php b/tests/LivescoreEndpointTest_.php deleted file mode 100644 index fa7b13b..0000000 --- a/tests/LivescoreEndpointTest_.php +++ /dev/null @@ -1,55 +0,0 @@ - [ - MockResponse::FIXTURE_COLLECTION_DATA, - 'livescores', - 'getAll', - [] - ]; - yield 'get all inplay' => [ - MockResponse::FIXTURE_COLLECTION_DATA, - 'livescores', - 'getAllInplay', - [] - ]; - yield 'get all last updated' => [ - MockResponse::FIXTURE_COLLECTION_DATA, - 'livescores', - 'getAllLastUpdated', - [] - ]; - } - - private function assertResponse(Fixture $fixture): void - { - $this->assertSame(216268, $fixture->getId()); - $this->assertSame(1, $fixture->getSportId()); - $this->assertSame(271, $fixture->getLeagueId()); - $this->assertSame(1273, $fixture->getSeasonId()); - $this->assertSame(1086, $fixture->getStageId()); - $this->assertSame(null, $fixture->getGroupId()); - $this->assertSame(null, $fixture->getAggregateId()); - $this->assertSame(23332, $fixture->getRoundId()); - $this->assertSame(5, $fixture->getStateId()); - $this->assertSame(618, $fixture->getVenueId()); - $this->assertSame('Esbjerg vs OB', $fixture->getName()); - $this->assertSame('2006-03-25 16:00:00', $fixture->getStartingAt()->format('Y-m-d H:i:s')); - $this->assertSame('Esbjerg won after full-time.', $fixture->getResultInfo()); - $this->assertSame('1/1', $fixture->getLeg()); - $this->assertSame(null, $fixture->getDetails()); - $this->assertSame(90, $fixture->getLength()); - $this->assertSame(false, $fixture->isPlaceholder()); - $this->assertSame(false, $fixture->hasOdds()); - } -} \ No newline at end of file