diff --git a/docs/03-supported-endpoints.md b/docs/03-supported-endpoints.md index 9be3d3d..759092f 100644 --- a/docs/03-supported-endpoints.md +++ b/docs/03-supported-endpoints.md @@ -1661,22 +1661,17 @@ $response = $api->bookmakers()->getAllBySearchQuery('bet'); ### Markets - [Official documentation](https://docs.sportmonks.com/football/endpoints-and-entities/endpoints/markets) -- Cache default max age: `1 day` #### `getAll` ```php -getAll(int $page = 1, int $perPage = 25, string $order = 'asc'): MarketCollection +getAll(): MarketCollection ``` Get all markets: ```php -$markets = $sportMonksFootball->markets()->getAll(); - -foreach ($markets->getData() as $market) { - echo $market->getName(); -} +$response = $api->markets()->getAll(); ``` #### `getById` @@ -1688,24 +1683,19 @@ getById(int $id): MarketItem Get market by id: ```php -$market = $sportMonksFootball->markets()->getById(1); -echo $market->getData()->getName(); +$response = $api->markets()->getById(1); ``` #### `getAllBySearchQuery` ```php -getAllBySearchQuery(string $query, int $page = 1, int $perPage = 25, string $order = 'asc'): MarketCollection +getAllBySearchQuery(string $query): MarketCollection ``` Get all markets by search query: ```php -$markets = $sportMonksFootball->markets()->getAllBySearchQuery('goal'); - -foreach ($markets->getData() as $market) { - echo $market->getName(); -} +$response = $api->markets()->getAllBySearchQuery('goal'); ``` ### Pre-match Odds diff --git a/src/Endpoint/MarketEndpoint.php b/src/Endpoint/MarketEndpoint.php deleted file mode 100644 index 899fe8f..0000000 --- a/src/Endpoint/MarketEndpoint.php +++ /dev/null @@ -1,94 +0,0 @@ -validatePagination($page, $perPage, $order); - - $response = $this->sendRequest( - method: 'GET', - path: '/v3/odds/markets', - query: [ - 'page' => $page, - 'per_page' => $perPage, - 'order' => $order - ] - ); - - return new MarketCollection($response); - } - - /** - * @throws Exception - * @throws ApiErrorException - */ - public function getById(int $id): MarketItem - { - $response = $this->sendRequest( - method: 'GET', - path: $this->formatPath('/v3/odds/markets/{id}', [ - 'id' => $id - ]) - ); - - return new MarketItem($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 - ): MarketCollection - { - $this->validateSearchQuery($query); - $this->validatePagination($page, $perPage, $order); - - $response = $this->sendRequest( - method: 'GET', - path: $this->formatPath('/v3/odds/markets/search/{query}', [ - 'query' => $query - ]), - query: [ - 'page' => $page, - 'per_page' => $perPage, - 'order' => $order - ] - ); - - return new MarketCollection($response); - } -} \ No newline at end of file diff --git a/src/Resource/MarketResource.php b/src/Resource/MarketResource.php new file mode 100644 index 0000000..98e3835 --- /dev/null +++ b/src/Resource/MarketResource.php @@ -0,0 +1,60 @@ +api->request( + method: 'GET', + path: '/v3/odds/markets' + ); + + return new MarketCollection($data); + } + + /** + * @throws ClientExceptionInterface + */ + public function getById(int $id): MarketItem + { + $data = $this->api->request( + method: 'GET', + path: $this->api->buildPath('/v3/odds/markets/{id}', [ + 'id' => $id + ]) + ); + + return new MarketItem($data); + } + + /** + * @throws ValidationException + * @throws ClientExceptionInterface + */ + public function getAllBySearchQuery(string $query): MarketCollection + { + $this->validateQuery($query, 'query'); + + $data = $this->api->request( + method: 'GET', + path: $this->api->buildPath('/v3/odds/markets/search/{query}', [ + 'query' => $query + ]) + ); + + return new MarketCollection($data); + } +} \ No newline at end of file diff --git a/src/SportMonksFootball.php b/src/SportMonksFootball.php index 27df0a2..5f21841 100644 --- a/src/SportMonksFootball.php +++ b/src/SportMonksFootball.php @@ -37,6 +37,7 @@ use ProgrammatorDev\SportMonksFootball\Resource\FixtureResource; use ProgrammatorDev\SportMonksFootball\Resource\LeagueResource; use ProgrammatorDev\SportMonksFootball\Resource\LivescoreResource; +use ProgrammatorDev\SportMonksFootball\Resource\MarketResource; class SportMonksFootball extends Api { @@ -103,11 +104,11 @@ public function livescores(): LivescoreResource return new LivescoreResource($this); } -// public function markets(): MarketEndpoint -// { -// return new MarketEndpoint($this); -// } -// + public function markets(): MarketResource + { + return new MarketResource($this); + } + // public function players(): PlayerEndpoint // { // return new PlayerEndpoint($this); diff --git a/tests/Integration/MarketResourceTest.php b/tests/Integration/MarketResourceTest.php new file mode 100644 index 0000000..0866340 --- /dev/null +++ b/tests/Integration/MarketResourceTest.php @@ -0,0 +1,55 @@ + [ + MarketItem::class, + MockResponse::MARKET_ITEM_DATA, + 'markets', + 'getById', + [1] + ]; + } + + public static function provideCollectionResponseData(): \Generator + { + yield 'get all' => [ + MarketCollection::class, + MockResponse::MARKET_COLLECTION_DATA, + 'markets', + 'getAll' + ]; + yield 'get all by search query' => [ + MarketCollection::class, + MockResponse::MARKET_COLLECTION_DATA, + 'markets', + 'getAllBySearchQuery', + ['test'] + ]; + } + + public static function provideValidationExceptionData(): \Generator + { + yield 'get all by search query, blank query' => [ + 'markets', + 'getAllBySearchQuery', + [''] + ]; + } +} \ No newline at end of file diff --git a/tests/Integration/SportMonksFootballTest.php b/tests/Integration/SportMonksFootballTest.php index b06a40d..3c8e4f1 100644 --- a/tests/Integration/SportMonksFootballTest.php +++ b/tests/Integration/SportMonksFootballTest.php @@ -12,6 +12,7 @@ use ProgrammatorDev\SportMonksFootball\Resource\FixtureResource; use ProgrammatorDev\SportMonksFootball\Resource\LeagueResource; use ProgrammatorDev\SportMonksFootball\Resource\LivescoreResource; +use ProgrammatorDev\SportMonksFootball\Resource\MarketResource; use ProgrammatorDev\SportMonksFootball\Test\AbstractTest; class SportMonksFootballTest extends AbstractTest @@ -28,5 +29,6 @@ public function testMethods() $this->assertInstanceOf(FixtureResource::class, $this->api->fixtures()); $this->assertInstanceOf(LeagueResource::class, $this->api->leagues()); $this->assertInstanceOf(LivescoreResource::class, $this->api->livescores()); + $this->assertInstanceOf(MarketResource::class, $this->api->markets()); } } \ No newline at end of file diff --git a/tests/MarketEndpointTest_.php b/tests/MarketEndpointTest_.php deleted file mode 100644 index 3df53ba..0000000 --- a/tests/MarketEndpointTest_.php +++ /dev/null @@ -1,63 +0,0 @@ - [ - MockResponse::MARKET_ITEM_DATA, - 'markets', - 'getById', - [1] - ]; - } - - public static function provideEndpointCollectionResponseData(): \Generator - { - yield 'get all' => [ - MockResponse::MARKET_COLLECTION_DATA, - 'markets', - 'getAll', - [] - ]; - yield 'get all by search query' => [ - MockResponse::MARKET_COLLECTION_DATA, - 'markets', - 'getAllBySearchQuery', - ['test'] - ]; - } - - public static function provideEndpointInvalidPaginationData(): \Generator - { - yield 'get all' => ['markets', 'getAll', []]; - yield 'get all by search query' => ['markets', 'getAllBySearchQuery', ['test']]; - } - - public static function provideEndpointInvalidSearchQueryData(): \Generator - { - yield 'get all by search query' => ['markets', 'getAllBySearchQuery']; - } - - private function assertResponse(Market $market): void - { - $this->assertSame(1, $market->getId()); - $this->assertSame(1, $market->getLegacyId()); - $this->assertSame('Fulltime Result', $market->getName()); - $this->assertSame('FULLTIME_RESULT', $market->getDeveloperName()); - $this->assertSame(true, $market->hasWinningCalculations()); - } -} \ No newline at end of file diff --git a/tests/Unit/MarketTest.php b/tests/Unit/MarketTest.php new file mode 100644 index 0000000..0bca4d8 --- /dev/null +++ b/tests/Unit/MarketTest.php @@ -0,0 +1,26 @@ + 1, + 'legacy_id' => 1, + 'name' => 'name', + 'developer_name' => 'DEVELOPER_NAME', + 'has_winning_calculations' => true + ]); + + $this->assertSame(1, $entity->getId()); + $this->assertSame(1, $entity->getLegacyId()); + $this->assertSame('name', $entity->getName()); + $this->assertSame('DEVELOPER_NAME', $entity->getDeveloperName()); + $this->assertSame(true, $entity->hasWinningCalculations()); + } +} \ No newline at end of file