Skip to content

Commit

Permalink
feat: added bookmaker resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 15, 2024
1 parent db9bc93 commit 8fc4afe
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 210 deletions.
123 changes: 0 additions & 123 deletions src/Endpoint/BookmakerEndpoint.php

This file was deleted.

141 changes: 54 additions & 87 deletions src/Resource/BookmakerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,105 +3,72 @@
namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Entity\Response\BookmakerCollection;
use ProgrammatorDev\SportMonksFootball\Pagination\Pagination;
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
use ProgrammatorDev\SportMonksFootball\Entity\Response\BookmakerItem;
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait;
use ProgrammatorDev\Validator\Exception\ValidationException;
use Psr\Http\Client\ClientExceptionInterface;

class BookmakerResource extends Resource
{
use PaginationTrait;

/**
* @throws ClientExceptionInterface
*/
public function getAll(
int $page = 1,
int $perPage = Pagination::PER_PAGE,
string $order = Pagination::ORDER_ASC
): BookmakerCollection
public function getAll(): BookmakerCollection
{
$data = $this->api->request(
method: 'GET',
path: '/v3/odds/bookmakers',
query: [
'page' => $page,
'per_page' => $perPage,
'order' => $order
]
path: '/v3/odds/bookmakers'
);
return new BookmakerCollection($data);
}

// /**
// * @throws Exception
// * @throws ApiErrorException
// */
// public function getById(int $id): BookmakerItem
// {
// $response = $this->sendRequest(
// method: 'GET',
// path: $this->formatPath('/v3/odds/bookmakers/{id}', [
// 'id' => $id
// ])
// );
//
// return new BookmakerItem($response);
// }
//
// /**
// * @throws Exception
// * @throws ValidationException
// * @throws ApiErrorException
// */
// public function getAllByFixtureId(
// int $fixtureId,
// int $page = 1,
// int $perPage = Pagination::PER_PAGE,
// string $order = Pagination::ORDER_ASC
// ): BookmakerCollection
// {
// $this->validatePagination($page, $perPage, $order);
//
// $response = $this->sendRequest(
// method: 'GET',
// path: $this->formatPath('/v3/odds/bookmakers/fixtures/{fixtureId}', [
// 'fixtureId' => $fixtureId
// ]),
// query: [
// 'page' => $page,
// 'per_page' => $perPage,
// 'order' => $order
// ]
// );
//
// return new BookmakerCollection($response);
// }
//
// /**
// * @throws Exception
// * @throws ValidationException
// * @throws ApiErrorException
// */
// public function getAllBySearchQuery(
// string $query,
// int $page = 1,
// int $perPage = Pagination::PER_PAGE,
// string $order = Pagination::ORDER_ASC
// ): BookmakerCollection
// {
// $this->validateSearchQuery($query);
// $this->validatePagination($page, $perPage, $order);
//
// $response = $this->sendRequest(
// method: 'GET',
// path: $this->formatPath('/v3/odds/bookmakers/search/{query}', [
// 'query' => $query
// ]),
// query: [
// 'page' => $page,
// 'per_page' => $perPage,
// 'order' => $order
// ]
// );
//
// return new BookmakerCollection($response);
// }
/**
* @throws ClientExceptionInterface
*/
public function getById(int $id): BookmakerItem
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/odds/bookmakers/{id}', [
'id' => $id
])
);

return new BookmakerItem($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllByFixtureId(int $fixtureId): BookmakerCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/odds/bookmakers/fixtures/{fixtureId}', [
'fixtureId' => $fixtureId
])
);

return new BookmakerCollection($data);
}

/**
* @throws ValidationException
* @throws ClientExceptionInterface
*/
public function getAllBySearchQuery(string $query): BookmakerCollection
{
$this->validateQuery($query, 'query');

$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/odds/bookmakers/search/{query}', [
'query' => $query
])
);

return new BookmakerCollection($data);
}
}
7 changes: 7 additions & 0 deletions src/Resource/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Resource\Util\LanguageTrait;
use ProgrammatorDev\SportMonksFootball\Resource\Util\TimezoneTrait;
use ProgrammatorDev\SportMonksFootball\Resource\Util\ValidationTrait;
use ProgrammatorDev\SportMonksFootball\SportMonksFootball;

class Resource
{
use TimezoneTrait;
use LanguageTrait;
use ValidationTrait;

public function __construct(protected SportMonksFootball $api) {}
}

0 comments on commit 8fc4afe

Please sign in to comment.