gman98ish/ukfast-simple-php-sdk

UKFast PHP SDK 的简化版本。

v0.2.1 2023-04-26 12:56 UTC

README

composer require gman98ish/ukfast-simple-php-sdk

这并不是要取代 UKFast SDK,而仅仅是一种概念验证,展示我们可以如何以另一种方式实现。

与 SDK 作为我们 API 的抽象不同,这提供了一个薄薄的包装。

客户端提供了访问我们 5 种不同类型端点的方法

  • 获取物品页面
  • 获取单个物品
  • 创建物品
  • 更新物品
  • 删除物品

您可以直接将 API 路径传递给此 SDK,使用 developers.ukfast.io 作为参考,例如。

<?php

$ukfast = new \UKFast\SimpleSDK\Client;
$ukfast->auth('my-ukfast-key');

$page = $ukfast->get('/pss/v1/requests'); // returns a Page class

echo $page->getItems()[0]->author->id . "\n";


// can also do concurrent requests
[$requests, $replies] = $ukfast->concurrently(fn ($ukfast) => [
    $ukfast->get('/pss/v1/requests'),
    $ukfast->get('/pss/v1/replies'),
]);

echo $requests->getItems()[0]->author->id . "\n";
echo $replies->getItems()[0]->author->id . "\n";

这种方法的优点是,这就是我们与整个 API 接口所需的所有代码。