concrete5 / community_api_client
dev-master
2022-05-19 01:21 UTC
Requires
This package is auto-updated.
Last update: 2022-05-19 01:22:24 UTC
README
这是用于与社区网站通信的官方API客户端。
目前功能非常有限,但很快将会扩展。
您可以使用API客户端分配成就。
要求
- PHP 7.1
- 只能在Concrete CMS环境中运行
安装
社区API客户端可以使用Composer安装。
安装请运行 composer require concrete5/community_api_client
配置
没有用于配置API客户端的界面。但是有多种方法可以实现。
选项1:编程方式
如果您想以编程方式设置凭据,可以这样做
use Concrete\Core\Support\Facade\Application; use PortlandLabs\CommunityApiClient\ApiClient; /** @var ApiClient $apiClient */ $apiClient = $app->make(ApiClient::class); $apiClient ->setEndpoint("your_endpoint") ->setClientId("your_client_id") ->setClientSecret("your_client_secret");
选项2:使用配置文件
您也可以使用配置文件。
您只需要创建一个位于 application/config/community_api_client.php
的文件,并包含以下内容
<?php return [ 'endpoint' => 'your_endpoint', 'client_id' => 'your_client_id', 'client_secret' => 'your_client_secret' ];
选项3:使用Concrete CMS CLI应用程序
您也可以使用CLI应用程序来配置API客户端。
concrete/bin/concrete5 c5:config set community_api_client.endpoint your_endpoint concrete/bin/concrete5 c5:config set community_api_client.client_id your_client_id concrete/bin/concrete5 c5:config set community_api_client.client_secret your_client_secret
选项4:使用环境变量
您也可以使用环境变量来设置凭据。以下变量被使用。
API_COMMUNITY_ENDPOINT
API_COMMUNITY_CLIENT_ID
API_COMMUNITY_CLIENT_SECRET
如果配置了环境变量,则忽略Concrete CMS配置。
用法
在配置了端点后,您可以与API接口通信。
以下代码片段演示了如何处理它。
use Concrete\Core\Support\Facade\Application; use PortlandLabs\CommunityApiClient\Models\Achievements; $app = Application::getFacadeApplication(); /** @var Achievements $achievements */ $achievements = $app->make(Achievements::class); $success = $achievements->assign("test_handle");
目前没有可用的API文档。因此,如果您想了解哪些功能可用,需要查看此存储库中的models文件夹。