Skip to content

Commit

Permalink
feat: added standing resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 22, 2024
1 parent b01cc74 commit 5b2a4c2
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 161 deletions.
42 changes: 6 additions & 36 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -857,24 +857,17 @@ $response = $api->stages()->getAllBySearchQuery('champions');
### Standings

- [Official documentation](https://docs.sportmonks.com/football/endpoints-and-entities/endpoints/standings)
- Cache default max age: `1 hour`
- `getAllLiveByLeagueId` cache max age: `1 minute`

#### `getAll`

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

Get all standings:

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

foreach ($standings->getData() as $standing) {
echo $standing->getPosition();
echo $standing->getPoints();
}
$response = $api->standings()->getAll();
```

#### `getAllBySeasonId`
Expand All @@ -886,12 +879,7 @@ getAllBySeasonId(int $seasonId): StandingCollection
Get all standings by season id:

```php
$standings = $sportMonksFootball->standings()->getAllBySeasonId(1);

foreach ($standings->getData() as $standing) {
echo $standing->getPosition();
echo $standing->getPoints();
}
$response = $api->standings()->getAllBySeasonId(1);
```

#### `getAllCorrectionsBySeasonId`
Expand All @@ -903,12 +891,7 @@ getAllCorrectionsBySeasonId(int $seasonId): StandingCorrectionCollection
Get all standing corrections by season id:

```php
$standingCorrections = $sportMonksFootball->standings()->getAllCorrectionsBySeasonId(1);

foreach ($standingCorrections->getData() as $standingCorrection) {
echo $standingCorrection->getValue();
echo $standingCorrection->getCalcType();
}
$response = $api->standings()->getAllCorrectionsBySeasonId(1);
```

#### `getAllByRoundId`
Expand All @@ -920,12 +903,7 @@ getAllByRoundId(int $roundId): StandingCollection
Get all standings by round id:

```php
$standings = $sportMonksFootball->standings()->getAllByRoundId(1);

foreach ($standings->getData() as $standing) {
echo $standing->getPosition();
echo $standing->getPoints();
}
$response = $api->standings()->getAllByRoundId(1);
```

#### `getAllLiveByLeagueId`
Expand All @@ -937,17 +915,9 @@ getAllLiveByLeagueId(int $leagueId): StandingCollection
Get all live standings by league id:

```php
$standings = $sportMonksFootball->standings()->getAllLiveByLeagueId(1);

foreach ($standings->getData() as $standing) {
echo $standing->getPosition();
echo $standing->getPoints();
}
$response = $api->standings()->getAllLiveByLeagueId(1);
```

> **Note**
> Cache max age is forced to `1 minute` on this endpoint.
### States

- [Official documentation](https://docs.sportmonks.com/football/endpoints-and-entities/endpoints/states)
Expand Down
119 changes: 0 additions & 119 deletions src/Endpoint/StandingEndpoint.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Entity/Standing.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(array $data, string $timezone)
$this->group = isset($data['group']) ? new Group($data['group']) : null;
$this->round = isset($data['round']) ? new Round($data['round'], $timezone) : null;
$this->sport = isset($data['sport']) ? new Sport($data['sport']) : null;
$this->rule = isset($data['rule']) ? new StandingRule($data['rule'], $timezone) : null;
$this->rule = isset($data['rule']) ? new StandingRule($data['rule']) : null;
$this->details = isset($data['details']) ? $this->createEntityCollection(StandingDetail::class, $data['details']) : null;
$this->form = isset($data['form']) ? $this->createEntityCollection(StandingForm::class, $data['form'], $timezone) : null;
}
Expand Down
86 changes: 86 additions & 0 deletions src/Resource/StandingResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Entity\Response\StandingCollection;
use ProgrammatorDev\SportMonksFootball\Entity\Response\StandingCorrectionCollection;
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait;
use Psr\Http\Client\ClientExceptionInterface;

class StandingResource extends Resource
{
use PaginationTrait;

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

return new StandingCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllBySeasonId(int $seasonId): StandingCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/standings/seasons/{seasonId}', [
'seasonId' => $seasonId
])
);

return new StandingCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllCorrectionsBySeasonId(int $seasonId): StandingCorrectionCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/standings/corrections/seasons/{seasonId}', [
'seasonId' => $seasonId
])
);

return new StandingCorrectionCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllByRoundId(int $roundId): StandingCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/standings/rounds/{roundId}', [
'roundId' => $roundId
])
);

return new StandingCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllLiveByLeagueId(int $leagueId): StandingCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/standings/live/leagues/{leagueId}', [
'leagueId' => $leagueId
])
);

return new StandingCollection($data);
}
}
11 changes: 6 additions & 5 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\ScheduleResource;
use ProgrammatorDev\SportMonksFootball\Resource\SeasonResource;
use ProgrammatorDev\SportMonksFootball\Resource\StageResource;
use ProgrammatorDev\SportMonksFootball\Resource\StandingResource;

class SportMonksFootball extends Api
{
Expand Down Expand Up @@ -162,11 +163,11 @@ public function stages(): StageResource
return new StageResource($this);
}

// public function standings(): StandingEndpoint
// {
// return new StandingEndpoint($this);
// }
//
public function standings(): StandingResource
{
return new StandingResource($this);
}

// public function states(): StateEndpoint
// {
// return new StateEndpoint($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 @@ -22,6 +22,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\ScheduleResource;
use ProgrammatorDev\SportMonksFootball\Resource\SeasonResource;
use ProgrammatorDev\SportMonksFootball\Resource\StageResource;
use ProgrammatorDev\SportMonksFootball\Resource\StandingResource;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;

class SportMonksFootballTest extends AbstractTest
Expand All @@ -48,5 +49,6 @@ public function testMethods()
$this->assertInstanceOf(ScheduleResource::class, $this->api->schedules());
$this->assertInstanceOf(SeasonResource::class, $this->api->seasons());
$this->assertInstanceOf(StageResource::class, $this->api->stages());
$this->assertInstanceOf(StandingResource::class, $this->api->standings());
}
}
Loading

0 comments on commit 5b2a4c2

Please sign in to comment.