kurn77/nextcloud-api-wrapper

nextcloud用户配置API的简单封装

2.0 2023-08-28 16:47 UTC

This package is not auto-updated.

Last update: 2024-09-24 19:45:50 UTC


README

这是一个围绕用户配置API、共享API的简单PHP封装,允许您动态管理您的nextcloud实例。它旨在尽可能接近API,每个参数都可用,方法名称应该足够易懂,不要犹豫使用API文档来寻求帮助,了解每个方法可用的参数。

这允许您动态地管理您的nextcloud实例。它旨在尽可能接近API,每个参数都是可用的,方法名称应该足够易懂,不要犹豫使用API文档来寻求帮助,了解每个方法可用的参数。

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

警告

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

安装

使用composer安装

composer require sysmoh/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