stevenbuehner/sb-churchtools-api

ChurchTools Api 包装器

3.111.2 2024-07-11 14:25 UTC

This package is auto-updated.

Last update: 2024-09-11 14:48:31 UTC


README

  1. ChurchTools 使用 openapi.json 文件来指定其 API v2。从这个文件中可以生成不同编程语言的 API。此存储库包含用于 PHP 的生成 API 版本,我将其用于我的项目。

  2. 由于 Churchtools 的 openapi.json 经常与实际 API 存在差异,且论坛支持通常非常缓慢或根本不响应,我被迫创建一个 openapi.json 文件的副本,并从中生成此 API。我经常将原始更改合并进来,并生成 API 的更新版本。

  3. 如果你在 openapi.json 中发现错误,请随时纠正并使用 Push-Request 提交。

安装

composer require stevenbuehner/sb-churchtools-api dev-master

示例

使用用户名和密码创建客户端

require_once __DIR__ . '/../vendor/autoload.php';

use GuzzleHttp\Cookie\CookieJar;
use StevenBuehner\ChurchTools\Api\PersonApi;
use StevenBuehner\ChurchTools\ApiException;
use StevenBuehner\ChurchTools\Configuration;
use StevenBuehner\ChurchToolsApi\ChurchToolsUserAuthenticatedClient;

// Create Config
$config = Configuration::getDefaultConfiguration();
$config->setHost('https://slug.church.tools/api');
$config->setUsername('username');
$config->setPassword('password');

// Create Client with Autthentication
$cookieJar = new CookieJar();
$client    = new ChurchToolsUserAuthenticatedClient($config, $cookieJar);
$success   = $client->login();
// $client->logout();

$personApi = new PersonApi($client, $config);
try {
	$test = $personApi->getAllPersons()->getData();
} catch (ApiException $e) {
}

使用访问令牌创建客户端

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use GuzzleHttp\Cookie\CookieJar;
use StevenBuehner\ChurchTools\Api\GroupApi;
use StevenBuehner\ChurchTools\Api\PersonApi;
use StevenBuehner\ChurchTools\ApiException;
use StevenBuehner\ChurchTools\Configuration;
use StevenBuehner\ChurchToolsApi\ChurchToolsTokenAuthenticatedClient;
use StevenBuehner\ChurchToolsApi\ChurchToolsUserAuthenticatedClient;

// Create Config
$config = Configuration::getDefaultConfiguration();
$config->setHost('https://slug.church.tools/api');
$config->setAccessToken('token');

// Create Client with Token
$cookieJar = new CookieJar();
$client  = new ChurchToolsTokenAuthenticatedClient($config, $cookieJar);
$success = $client->login(); // Not neccessary with token
// $client->logout(); // For cleanup


// Create an api
$groupApi  = new GroupApi($client, $config);
$personApi = new PersonApi($client, $config);
// ...

迭代示例

// Iteration Example
$hasMore = TRUE;
$page    = 1;
$limit   = 100;

while ($hasMore === TRUE) {
	try {
		$response = $personApi
			->getAllPersons(NULL, NULL, NULL, NULL, NULL, FALSE, $page, $limit);
	} catch (ApiException $e) {
	}

	// do Something with persons ...

	// get next batch of persons
	$hasMore = $response->getMeta()->getPagination()->getLastPage() > $page;
	$page++;
}

考虑使用