ptrtn/battlerite

基于 PHP 的客户端,封装了 battlerite API

v1.7 2017-12-26 18:56 UTC

README

Battlerite API 的 PHP-based SDK

Build Status Code Coverage Scrutinizer Code Quality

功能

  • 通过查询检索比赛数据
  • 检索特定比赛的具体数据
  • 通过查询检索玩家数据
  • 检索特定玩家的详细数据
  • 检索特定玩家和赛季的队伍数据
  • 检索 API 状态

要求

  • Php 7.1 或更高版本

安装

composer require ptrtn/battlerite-sdk

使用

检索数据可以简单到一次方法调用。如果没有指定搜索查询,则使用 API 默认值。

API 状态

以下示例返回 API 状态、补丁版本和其他数据

$client = \PtrTn\Battlerite\Client::create('your-api-key');
$status = $client->getStatus();

检索比赛数据

使用 API 默认值检索比赛数据

$client = \PtrTn\Battlerite\Client::create('your-api-key');
$matches = $client->getMatches();
echo $matches[0]->map->type;
// QUICK2V2

检索队伍数据

$client = \PtrTn\Battlerite\Client::create('your-api-key');
$teams = $client->getTeams(
    TeamsQuery::create()
    ->forPlayerIds(['322'])
    ->forSeason(5)
);

检索详细比赛数据

$client = \PtrTn\Battlerite\Client::create('your-api-key');
$match = $client->getMatch('AB9C81FABFD748C8A7EC545AA6AF97CC');

检索详细玩家数据

$client = \PtrTn\Battlerite\Client::create('your-api-key');
$match = $client->getPlayer('934791968557563904');

自定义查询

可以使用自定义搜索查询来检索所需的确切数据。

比赛

对于比赛,以下查询选项可用

  • 偏移量
  • 限制
  • 开始日期
  • 结束日期
  • 玩家 ID
  • 团队名称
  • 游戏模式
  • 升序排序
  • 降序排序
$client = \PtrTn\Battlerite\Client::create('your-api-key');
// Retrieve matches for a specific player for the last 24 hours
$matches = $client->getMatches(
    MatchesQuery::create()
    ->forPlayerIds(['934791968557563904'])
    ->withStartDate(new DateTime('-1 day'))
);

玩家

对于玩家,以下查询选项可用

  • 玩家名称
  • Steam ID
  • 玩家 ID
$client = \PtrTn\Battlerite\Client::create('your-api-key');
// Retrieve a list of players for a specific player name
$players = $client->getPlayers(
    PlayersQuery::create()
    ->forPlayerNames(['PlakkeStrasser'])
);

注意:对于特定玩家名称,最多可以找到 6 个玩家(每个地区 1 个)。

队伍

对于队伍,以下查询选项可用

  • 赛季
  • 玩家 ID
$client = \PtrTn\Battlerite\Client::create('your-api-key');
$teams = $client->getTeams(
    TeamsQuery::create()
    ->forPlayerIds(['322'])
    ->forSeason(5)
);

缓存

在发送大量请求时,默认的每分钟 10 个请求的限制将引发问题。为了避免这种情况,可以为玩家详细信息和比赛详细信息端点启用缓存。

// Create client using default filesystem cache
$client = ClientWithCache::create('your-api-key');

可选地,可以配置替代缓存生命周期或实现 Doctrine\Common\Cache\Cache 接口的缓存系统。

// Create a client using custom configured cache
$client = ClientWithCache::createWithCache(
    'your-api-key',
    new RedisCache(),
    300
);

如何获取 API 密钥?

  1. 为了获取 API 密钥,您应该 创建一个开发者账户和一个应用
  2. 创建后,登录并浏览到 https://developer.battlerite.com/apps/your-app
  3. 滚动到 DEVELOPMENT API KEY THIS APP USES,它应该看起来像:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9G9lIiwiYWRtaW4iOnRydWV9G9lIiwiYWRtaW4iOnRydWV9G9lIiwiYWRtaW4iOnRydWV9TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ

API 文档

Battlerite API 的文档可以在 http://battlerite-docs.readthedocs.io/en/latest/ 找到