sn-chernyshev/nextcloud-api-wrapper

nextcloud用户配置API的一个简单包装器

dev-master 2022-08-10 15:42 UTC

This package is auto-updated.

Last update: 2024-09-10 20:16:08 UTC


README

这是一个围绕用户配置API和共享API的简单PHP包装器

允许您动态管理您的Nextcloud实例。它的设计尽可能接近API,每个参数都是可用的,方法名称应该足够易于理解,不要犹豫,利用API文档来查找每个方法可用的参数。

这个库在部分测试了Nextcloud 12和13。它是为了满足我的需求而开发的,但我实现了所有剩余的方法。如果您发现任何错误,请毫不犹豫地提出问题。

警告

Nextcloud API使用基本HTTP认证,这意味着用户名和密码不会被编码,并且以最清晰的方式在互联网上传输。请确保使用SSL强制执行。

安装

使用composer安装

composer require SNChernyshev/nextcloud-api-wrapper

基本用法

该库依赖于Guzzle进行请求和Symfony的选项解析器。

use NextcloudApiWrapper\Wrapper;

//The base path to Nextcloud api entry point, dont forget the last '/'
$basePath   = 'http://my.domain.com/nextcloud/ocs/';
$username   = 'admin';
$password   = 'potatoes';

$wrapper    = Wrapper::build($basePath, $username, $password);

// https://docs.nextcloud.com/server/12/admin_manual/configuration_user/user_provisioning_api.html
$userClient                 = $wrapper->getUsersClient();
$groupsClient               = $wrapper->getGroupsClient();
$appsClient                 = $wrapper->getAppsClient();

// https://docs.nextcloud.com/server/12/developer_manual/core/ocs-share-api.html
$sharesClient               = $wrapper->getSharesClient();
$federatedCloudSharesClient = $wrapper->getFederatedCloudSharesClient();

//Instance of \NextcloudApiWrapper\NextcloudResponse
$response   = $userClient->getUsers();
$code       = $response->getStatusCode();   //status code
$users      = $response->getData();         //data as array
$message    = $response->getStatus();       //status message
$guzzle     = $response->getRawResponse();  //Guzzle response

自定义请求

如果您想执行自己的请求,您可以使用底层的Nextcloud连接类来执行它们。

$connection = new \NextcloudApiWrapper\Connection($basePath, $username, $password);

//To perform simple requests
$response   = $connection->request('GET', 'cloud/users');

//To perform requests which needs the 'application/x-www-form-urlencoded' header
//and are not performed in POST
$response   = $connection->pushDataRequest('PUT', 'cloud/' . $username . '/disable');

//To perform requests which holds some values to submit
$response   = $connection->submitRequest('POST', 'cloud/users', [
    'userid'    => 'potatoes',
    'password'  => 'tortilla'
]);

许可证

MIT