rgarman/sdk-stats

Stats.com 统计信息 SDK

1.2.0 2019-09-04 16:38 UTC

This package is auto-updated.

Last update: 2024-09-05 03:44:23 UTC


README

关于

sdk-stats 包是用于各种 stats.com API 端点的软件开发工具包。此 SDK 的工作方式是通过用户自定义要使用的端点,并为它们分配自己的名称,以简化开发者的体验并提高效率。

安装

在您的 composer.json 中要求 rgarman/sdk-stats 包并更新您的依赖项

composer require rgarman/sdk-stats

创建客户端

我建议创建一个包含您的登录凭据的关联数组,以便以后使用。这还将有助于同时创建具有不同 API 的多个不同实例。创建 ClientCore() 类的实例

use RGarman\Stats\statsClient;

// A config of ["{your username}", "{your password}"] would work too!
$Configs = [
    "Stats" => [
        "{USERNAME}",
        "{PASSWORD}"
    ],
    ...
]

$StatsClient = new ClientCore();

添加资源

要添加要使用的资源,只需从 ClientCore 调用 AddResource() 方法,并传递一个 Route 或 Cache 的实例

参数包括:名称和选择的实例 Route 参数

  1. 端点(字符串)
  2. 参数(数组)
  3. 配置凭据
// Generate a new endpoint resource
$StatsClient->AddResource("SquadList", new Route("api/RU/clubSquads/", ["Competition ID", "Season ID", "Team ID"], $Configs["Stats"]));

//Generate a new Cache interface
$StatsClient->AddResource("Caching", new Cache());

使用资源

使用您分配的资源名称,只需将其用作属性并使用以下列出的任何函数

//This outputs the Squad List for England in the Six Nations 2019 and generates a cache containing the response from the API
var_dump($StatsClient->SquadList->getAndCache([301, 2019, 1114]));


//Using the "Caching" resource (previously created), we can see all of the cached data using:
var_dump($StatsClient->Caching->get("*"));

//The name of the above cache is called "api-RU-clubSquads-301-2019-1114", so to get this data, we use the following:
var_dump($StatsClient->Caching->get("api-RU-clubSquads-301-2019-1114"));

函数列表

路由实例

get( $Parameters (数组/字符串) )

使用提供的参数作为数组或字符串调用当前选定的 API 端点
以数组形式返回 API 的响应

getAndCache ( $Parameters (数组/字符串) )

基本上与 get 具有相同的功能,但会创建一个以原始 JSON 形式的缓存
以数组形式返回 API 的响应(除缓存外)

setMethod( $Method (字符串) )

设置要使用的 HTTP 协议类型,例如 GET、POST、PUT 等。接受所有 7 种类型

setBase( $Base (字符串) )

设置要使用的 API 的基础 URI,因此可以在同一 SDK 中使用其他 API!

缓存实例

get( $Cache (字符串) )

检索给定的缓存,使用 "*" 获取所有存储的缓存数据的名称

更多示例请参阅