Skip to content

Commit

Permalink
feat: added livescore resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 21, 2024
1 parent a10682f commit 25f2cfa
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 144 deletions.
23 changes: 3 additions & 20 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -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`
Expand All @@ -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`
Expand All @@ -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)
Expand Down
64 changes: 0 additions & 64 deletions src/Endpoint/LivescoreEndpoint.php

This file was deleted.

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

namespace ProgrammatorDev\SportMonksFootball\Resource;

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

class LivescoreResource extends Resource
{
/**
* @throws ClientExceptionInterface
*/
public function getAll(): FixtureCollection
{
$data = $this->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);
}
}
11 changes: 6 additions & 5 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down
37 changes: 37 additions & 0 deletions tests/Integration/LivescoreResourceTest.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\BookmakerCollection;
use ProgrammatorDev\SportMonksFootball\Entity\Response\BookmakerItem;
use ProgrammatorDev\SportMonksFootball\Entity\Response\FixtureCollection;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;
use ProgrammatorDev\SportMonksFootball\Test\MockResponse;
use ProgrammatorDev\SportMonksFootball\Test\Util\TestCollectionResponseTrait;

class LivescoreResourceTest extends AbstractTest
{
use TestCollectionResponseTrait;

public static function provideCollectionResponseData(): \Generator
{
yield 'get all' => [
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'
];
}
}
2 changes: 2 additions & 0 deletions tests/Integration/SportMonksFootballTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
55 changes: 0 additions & 55 deletions tests/LivescoreEndpointTest_.php

This file was deleted.

0 comments on commit 25f2cfa

Please sign in to comment.