stuartmcgill / sumoapi-php
PHP包装器,用于https://sumo-api.com/
0.8.1
2024-09-14 13:37 UTC
Requires
- php: >=8.3
- guzzlehttp/guzzle: ^7.5
Requires (Dev)
- mockery/mockery: ^1.5
- php-parallel-lint/php-parallel-lint: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-mockery: ^1.1
- phpunit/phpunit: ^10.0
README
此库为https://sumo-api.com/提供了PHP包装器。目前有以下功能
- 获取所有力士
- 通过ID获取力士
- 获取力士的比赛
- 通过ID获取多个力士
- 通过部门获取多个力士
- 获取力士对决
- 获取角斗(按类型)
安装
composer require stuartmcgill/sumoapi-php
使用方法
有关API端点的详细信息,请参阅https://sumo-api.com/api-guide。
力士API
示例代码
#!/bin/env php <?php declare(strict_types=1); namespace StuartMcGill\SumoApiTester; require __DIR__ . '/../vendor/autoload.php'; use StuartMcGill\SumoApiPhp\Model\Rikishi; use StuartMcGill\SumoApiPhp\Model\RikishiMatch; use StuartMcGill\SumoApiPhp\Service\BashoService; use StuartMcGill\SumoApiPhp\Service\RikishiService; $bashoService = BashoService::factory(); $rikishiService = RikishiService::factory(); // Fetch rikishis from a particular basho $rikishisFromThePast = $bashoService->fetchRikishiIdsByBasho(2019, 3, 'Makuuchi'); echo 'Rikishi IDs from March 2019 are ' . implode(',', $rikishisFromThePast) . "\n"; // Fetch a single rikishi $rikishi = $rikishiService->fetch(1); echo $rikishi->shikonaJp . "\n"; // Fetch all rikishis $rikishis = $rikishiService->fetchAll(); $totalMass = array_reduce( array: $rikishis, callback: static fn (float $total, Rikishi $rikishi) => $total + $rikishi->weight, initial:0, ); echo "The total mass of all the wrestlers is $totalMass kg\n"; // Fetch all of a rikishi's matches $matches = $rikishiService->fetchMatches(1); $oshidashiWins = array_filter( array: $matches, callback: static fn (RikishiMatch $match) => $match->winnerId === 1 && $match->kimarite === 'oshidashi', ); echo 'Takakeisho has won by Oshidashi ' . count($oshidashiWins) . " times\n"; // Fetch some rikishi (by IDs) $someRikishi = $rikishiService->fetchSome([1, 2]); echo 'Fetched details for ' . count($someRikishi) . " wrestlers\n"; // Fetch rikishi and filter by division $someRikishi = $rikishiService->fetchDivision('Makuuchi'); echo 'Fetched details for ' . count($someRikishi) . " Makuuchi wrestlers\n"; // Fetch rikishi matchups (head-to-heads) $matchupSummary = $rikishiService->fetchMatchups(1, [2]); echo 'Takakeisho has fought Asanoyama ' . $matchupSummary->matchups[0]->total() . ' times';
输出
Rikishi IDs from March 2019 are 3081,44,43,1,26,674,9,16,3195,637,47,23,2,35,673,15,51,102,67,368,48,39,3181,3249,14,27,17,36,33,46,10,22,25,3142,3120,106,38,3248,29,3204,30,636
貴景勝 光信
The total mass of all the wrestlers is 83279.2 kg
Takakeisho has won by Oshidashi 193 times
Fetched details for 2 wrestlers
Fetched details for 42 Makuuchi wrestlers
Takakeisho has fought Asanoyama 9 times⏎
角斗API
示例代码
#!/bin/env php <?php declare(strict_types=1); namespace StuartMcGill\SumoApiTester; require __DIR__ . '/../vendor/autoload.php'; use StuartMcGill\SumoApiPhp\Service\KimariteService; $kimariteService = KimariteService::factory(); // Fetch last three matches where the kimarite was yorikiri $matches = $kimariteService->fetchByType(type: 'yorikiri', sortOrder: 'desc', limit: 3, skip: 0); foreach ($matches as $match) { $loser = $match->loserEn(); echo "$match->winnerEn defeated $loser by yorikiri in $match->division " . "on day $match->day of the $match->bashoId basho.\n"; }
输出
Onosato defeated Hiradoumi by yorikiri in Makuuchi on day 7 of the 202409 basho.
Sadanoumi defeated Shirokuma by yorikiri in Makuuchi on day 7 of the 202409 basho.
Ryuden defeated Kitanowaka by yorikiri in Makuuchi on day 7 of the 202409 basho.