Skip to content

Commit

Permalink
feat: added transfer resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 22, 2024
1 parent 20b7b98 commit 826a12e
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 390 deletions.
44 changes: 11 additions & 33 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -1156,22 +1156,17 @@ $response = $api->topscorers()->getAllByStageId(1);
### Transfers

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

#### `getAll`

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

Get all transfers:

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

foreach ($transfers->getData() as $transfer) {
echo $transfer->getPlayerId();
}
$response = $api->transfers()->getAll();
```

#### `getById`
Expand All @@ -1183,72 +1178,55 @@ getById(int $id): TransferItem
Get transfer by id:

```php
$transfer = $sportMonksFootball->transfers()->getById(1);
echo $transfer->getData()->getPlayerId();
$response = $api->transfers()->getById(1);
```

#### `getAllLatest`

```php
getAllLatest(int $page = 1, int $perPage = 25, string $order = 'desc'): TransferCollection
getAllLatest(): TransferCollection
```

Get the latest transfers:

```php
$transfers = $sportMonksFootball->transfers()->getAllLatest();

foreach ($transfers->getData() as $transfer) {
echo $transfer->getPlayerId();
}
$response = $api->transfers()->getAllLatest();
```

#### `getAllByDateRange`

```php
getAllByDateRange(\DateTimeInterface $startDate, \DateTimeInterface $endDate, int $page = 1, int $perPage = 25, string $order = 'asc'): TransferCollection
getAllByDateRange(\DateTimeInterface $startDate, \DateTimeInterface $endDate): TransferCollection
```

Get all transfers by date range:

```php
$transfers = $sportMonksFootball->transfers()->getAllByDateRange(new DateTime('-7 days'), new DateTime('today'));

foreach ($transfers->getData() as $transfer) {
echo $transfer->getPlayerId();
}
$response = $api->transfers()->getAllByDateRange(new DateTime('-7 days'), new DateTime('today'));
```

#### `getAllByTeamId`

```php
getAllByTeamId(int $teamId, int $page = 1, int $perPage = 25, string $order = 'asc'): TransferCollection
getAllByTeamId(int $teamId): TransferCollection
```

Get all transfers by team id:

```php
$transfers = $sportMonksFootball->transfers()->getAllByTeamId(1);

foreach ($transfers->getData() as $transfer) {
echo $transfer->getPlayerId();
}
$response = $api->transfers()->getAllByTeamId(1);
```

#### `getAllByPlayerId`

```php
getAllByPlayerId(int $playerId, int $page = 1, int $perPage = 25, string $order = 'asc'): TransferCollection
getAllByPlayerId(int $playerId): TransferCollection
```

Get all transfers by player id:

```php
$transfers = $sportMonksFootball->transfers()->getAllByPlayerId(1);

foreach ($transfers->getData() as $transfer) {
echo $transfer->getPlayerId();
}
$response = $api->transfers()->getAllByPlayerId(1);
```

### TV Stations
Expand Down
184 changes: 0 additions & 184 deletions src/Endpoint/TransferEndpoint.php

This file was deleted.

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

namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Entity\Response\TransferCollection;
use ProgrammatorDev\SportMonksFootball\Entity\Response\TransferItem;
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait;
use ProgrammatorDev\Validator\Exception\ValidationException;
use Psr\Http\Client\ClientExceptionInterface;

class TransferResource extends Resource
{
use PaginationTrait;

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

return new TransferCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getById(int $id): TransferItem
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/transfers/{id}', [
'id' => $id
])
);

return new TransferItem($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllLatest(): TransferCollection
{
$data = $this->api->request(
method: 'GET',
path: '/v3/football/transfers/latest'
);

return new TransferCollection($data);
}

/**
* @throws ValidationException
* @throws ClientExceptionInterface
*/
public function getAllByDateRange(\DateTimeInterface $startDate, \DateTimeInterface $endDate): TransferCollection
{
$this->validateDateOrder($startDate, $endDate);

$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/transfers/between/{startDate}/{endDate}', [
'startDate' => $startDate->format('Y-m-d'),
'endDate' => $endDate->format('Y-m-d')
])
);

return new TransferCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllByTeamId(int $teamId): TransferCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/transfers/teams/{teamId}', [
'teamId' => $teamId
])
);

return new TransferCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllByPlayerId(int $playerId): TransferCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/transfers/players/{playerId}', [
'playerId' => $playerId
])
);

return new TransferCollection($data);
}
}
Loading

0 comments on commit 826a12e

Please sign in to comment.