Title: | Interface to Open Collaboration Services (OCS) REST API |
---|---|
Description: | Provides an Interface to Open Collaboration Services 'OCS' (<https://www.open-collaboration-services.org/>) REST API. |
Authors: | Emmanuel Blondel [aut, cre] |
Maintainer: | Emmanuel Blondel <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3 |
Built: | 2025-03-08 06:02:27 UTC |
Source: | https://github.com/eblondel/ocs4r |
Provides an Interface to 'OCS' (<https://www.open-collaboration-services.org/>) REST API.
Emmanuel Blondel [email protected]
Useful links:
ocs4RLogger
ocs4RLogger
R6Class
object.
Object of R6Class
for modelling a simple logger
verbose.info
is info logger active?
verbose.debug
is debug logger active?
loggerType
logger type
new()
Initializes the logger
ocs4RLogger$new(logger = NULL)
logger
the type of logger. Default is NULL
, accepts INFO
or DEBUG
logger()
Logger function
ocs4RLogger$logger(type, text)
type
type of log
text
text
INFO()
Logger to report information. Used internally
ocs4RLogger$INFO(text)
text
text
WARN()
Logger to report warnings. Used internally
ocs4RLogger$WARN(text)
text
text
ERROR()
Logger to report errors Used internally
ocs4RLogger$ERROR(text)
text
text
getClassName()
Get class name
ocs4RLogger$getClassName()
the class name
getClass()
Get class
ocs4RLogger$getClass()
the class
clone()
The objects of this class are cloneable with this method.
ocs4RLogger$clone(deep = FALSE)
deep
Whether to make a deep clone.
Logger class used internally by ocs4R
ocsApiSharingManager
ocsApiSharingManager
R6Class
object.
Object of R6Class
for modelling an ocsManager for the Sharing API
ocs4R::ocs4RLogger
-> ocs4R::ocsManager
-> ocsApiSharingManager
ocs4R::ocs4RLogger$ERROR()
ocs4R::ocs4RLogger$INFO()
ocs4R::ocs4RLogger$WARN()
ocs4R::ocs4RLogger$getClass()
ocs4R::ocs4RLogger$getClassName()
ocs4R::ocs4RLogger$logger()
ocs4R::ocsManager$connect()
ocs4R::ocsManager$getAPISharingManager()
ocs4R::ocsManager$getAPIUserProvisioningManager()
ocs4R::ocsManager$getAPIWebdavManager()
ocs4R::ocsManager$getCapabilities()
ocs4R::ocsManager$getVersion()
new()
Initialize manager
ocsApiSharingManager$new(url, user, pwd, logger = NULL, keyring_backend = NULL)
url
url
user
user
pwd
pwd
logger
logger
keyring_backend
backend to use with keyring. Default is NULL
getShares()
Get list of shares as list
. To return as data.frame
,
set pretty = TRUE
. The method accepts additional parameters.
ocsApiSharingManager$getShares( path = NULL, reshares = FALSE, shared_with_me = NULL, state = NULL, subfiles = FALSE, pretty = FALSE )
path
path
reshares
reshares
shared_with_me
list only those shared with me?
state
state
subfiles
subfiles
pretty
pretty
the list of shares as list
or data.frame
createShare()
Creates a share for the path (file or folder), given a name. The shareType
should be among
values 'user','group','publiclink' or 'federated'.The shareWith
is required for shareType
'user' and 'group' and corresponds to the username or groupname. The permissions
can be set among
values 'read', 'update', 'create', 'delete', 'read-write', 'share', 'all'. By default the permissions will
be the default permissions set by the ocs server (by default 'all').
ocsApiSharingManager$createShare( path, name, shareType, shareWith, publicUpload = NULL, password = NULL, permissions = NULL, expireDate = NULL )
path
path
name
name
shareType
the type of share
shareWith
a list of users to share with
publicUpload
public upload
password
to set to access the share
permissions
permissions
expireDate
expire date
shareWithUser()
Shares a resource (file or folder) with a user given its username handled with argument username
.
The permissions
can be set among values 'read', 'update', 'create', 'delete', 'read-write', 'share',
'all'. By default the permissions will be the default permissions set by the ocs server (by default 'all').
Returns
ocsApiSharingManager$shareWithUser( path, name, username, permissions = NULL, pretty = FALSE )
path
path
name
name
username
username
permissions
permissions
pretty
pretty
group
group
the share properties as list
(or asdata.frame
if pretty
is set to TRUE).
shareWithGroup()
Shares a resource (file or folder) with a group given its name handled with argument group
.
The permissions
can be set among values 'read', 'update', 'create', 'delete', 'read-write', 'share',
'all'. By default the permissions will be the default permissions set by the ocs server (by default 'all').
ocsApiSharingManager$shareWithGroup( path, name, group, permissions = NULL, pretty = FALSE )
path
path
name
name
group
group
permissions
permissions
pretty
pretty
the share properties as list
(or asdata.frame
if pretty
is set to TRUE).
shareAsPublicLink()
Shares a resource (file or folder) as public link. The function returns the public link generated by ocs.
ocsApiSharingManager$shareAsPublicLink( path, name = NULL, publicUpload = FALSE, password = NULL, permissions = NULL, expireDate = NULL )
path
path
name
name
publicUpload
public upload?
password
password
permissions
permissions
expireDate
expire date
return
the public sharing link
clone()
The objects of this class are cloneable with this method.
ocsApiSharingManager$clone(deep = FALSE)
deep
Whether to make a deep clone.
Emmanuel Blondel <[email protected]>
ocsApiUserProvisioningManager
ocsApiUserProvisioningManager
R6Class
object.
Object of R6Class
for modelling an ocsManager for Webdav API
ocs4R::ocs4RLogger
-> ocs4R::ocsManager
-> ocsApiUserProvisioningManager
ocs4R::ocs4RLogger$ERROR()
ocs4R::ocs4RLogger$INFO()
ocs4R::ocs4RLogger$WARN()
ocs4R::ocs4RLogger$getClass()
ocs4R::ocs4RLogger$getClassName()
ocs4R::ocs4RLogger$logger()
ocs4R::ocsManager$connect()
ocs4R::ocsManager$getAPISharingManager()
ocs4R::ocsManager$getAPIUserProvisioningManager()
ocs4R::ocsManager$getAPIWebdavManager()
ocs4R::ocsManager$getCapabilities()
ocs4R::ocsManager$getVersion()
new()
Initialize manager
ocsApiUserProvisioningManager$new( url, user, pwd, logger = NULL, keyring_backend = "env" )
url
url
user
user
pwd
pwd
logger
logger
keyring_backend
backend to use with keyring. Default is NULL
addUser()
Adds a user given a userid
(required). All other fields (email, password, groups) are
optional for the user creation. Returns TRUE
if the user is added, FALSE
otherwise.
ocsApiUserProvisioningManager$addUser( userid, email = NULL, password = NULL, groups = NULL )
userid
user ID
email
password
user password
groups
groups
getUsers()
Get the list of users. This method returns a vector of class 'character' giving the user IDs available in the OCS cloud plateform.
ocsApiUserProvisioningManager$getUsers()
getUser()
Get the user details from its userid
. If the argument pretty
is set to TRUE,
this will return an object of class data.frame
, otherwise (by default) it returns
an object of class list
.
ocsApiUserProvisioningManager$getUser(userid, pretty = FALSE)
userid
user ID
pretty
pretty
editUser()
Edits a user, identifier by a userid. The user property to be edited should be set using its
key (eg display) and the value to be modified for this key. Returns TRUE
if the user
is edited, FALSE
otherwise.
ocsApiUserProvisioningManager$editUser(userid, key, value)
userid
user ID
key
key
value
value
editUserDisplayName()
Edits a user display name.
ocsApiUserProvisioningManager$editUserDisplayName(userid, displayName)
userid
user ID
displayName
display name
editUserEmail()
Edits a user email
ocsApiUserProvisioningManager$editUserEmail(userid, email)
userid
user ID
email
editUserPassword()
Edits a user password
ocsApiUserProvisioningManager$editUserPassword(userid, password)
userid
user ID
password
password
editUserQuota()
Edits a user quota
ocsApiUserProvisioningManager$editUserQuota(userid, quota)
userid
user ID
quota
quota
enableUser()
Enables a user
ocsApiUserProvisioningManager$enableUser(userid)
userid
user ID
TRUE
if enabled, FALSE
otherwise
disableUser()
Disables a user
ocsApiUserProvisioningManager$disableUser(userid)
userid
user ID
TRUE
if disabled, FALSE
otherwise
deleteUser()
Deletes a user
ocsApiUserProvisioningManager$deleteUser(userid)
userid
user ID
TRUE
if deleted, FALSE
otherwise
getUserGroups()
Get user groups
ocsApiUserProvisioningManager$getUserGroups(userid)
userid
user ID
the user groups
addToGroup()
Adds a user to a group.
ocsApiUserProvisioningManager$addToGroup(userid, groupid)
userid
user ID
groupid
group ID
TRUE
if added, FALSE
otherwise
removeFromGroup()
Removes a user from a group.
ocsApiUserProvisioningManager$removeFromGroup(userid, groupid)
userid
user ID
groupid
group ID
TRUE
if removed, FALSE
otherwise
createSubadmin()
Creates a subadmin
ocsApiUserProvisioningManager$createSubadmin()
removeSubadmin()
Removes a subadmin
ocsApiUserProvisioningManager$removeSubadmin()
getSubadminGroups()
Get subadmin groups
ocsApiUserProvisioningManager$getSubadminGroups()
getGroups()
Get the list of groups. This method returns a vector of class 'character' giving the usergroups IDs
ocsApiUserProvisioningManager$getGroups( search = NULL, limit = NULL, offset = NULL )
search
search
limit
limit
offset
offset
addGroup()
Adds a group
ocsApiUserProvisioningManager$addGroup(groupid)
groupid
group ID
TRUE
if added, FALSE
getGroup()
Gets a group
ocsApiUserProvisioningManager$getGroup(groupid)
groupid
group ID
the group as list
including the group ID and the list of users
deleteGroup()
Deletes a group
ocsApiUserProvisioningManager$deleteGroup(groupid)
groupid
group ID
TRUE
if deleted, FALSE
getSubadmins()
Get subadmins
ocsApiUserProvisioningManager$getSubadmins()
clone()
The objects of this class are cloneable with this method.
ocsApiUserProvisioningManager$clone(deep = FALSE)
deep
Whether to make a deep clone.
Emmanuel Blondel <[email protected]>
ocsApiWebdavManager
ocsApiWebdavManager
R6Class
object.
Object of R6Class
for modelling an ocsManager for Webdav API
ocs4R::ocs4RLogger
-> ocs4R::ocsManager
-> ocsApiWebdavManager
ocs4R::ocs4RLogger$ERROR()
ocs4R::ocs4RLogger$INFO()
ocs4R::ocs4RLogger$WARN()
ocs4R::ocs4RLogger$getClass()
ocs4R::ocs4RLogger$getClassName()
ocs4R::ocs4RLogger$logger()
ocs4R::ocsManager$connect()
ocs4R::ocsManager$getAPISharingManager()
ocs4R::ocsManager$getAPIUserProvisioningManager()
ocs4R::ocsManager$getAPIWebdavManager()
ocs4R::ocsManager$getCapabilities()
ocs4R::ocsManager$getVersion()
new()
Initialize manager
ocsApiWebdavManager$new(url, user, pwd, logger = NULL, keyring_backend = NULL)
url
url
user
user
pwd
pwd
logger
logger
keyring_backend
backend to use with keyring. Default is NULL
getWebdavRoot()
Get the 'ocs' WebDAV root URL
ocsApiWebdavManager$getWebdavRoot()
listFiles()
WebDAV method to list folders/files given a relative path. The relative path is set
to "/"
by default, which corresponds to the root of the 'ocs' repository.
ocsApiWebdavManager$listFiles(relPath = "/")
relPath
relative path
the list of files
makeCollection()
WebDAV method to make a collection. By default relPath
is set to "/"
(root).
The name
is the name of the new collection to be created. The function is recursive
in the sense that a name
can be provided as relative path of a collection tree
(eg newfolder1/newfolder2/newfolder3
), the function will create recursively as
many collections are handled in the name.
ocsApiWebdavManager$makeCollection(name, relPath = "/")
name
name
relPath
relative path
uploadFile()
WebDAV method to upload a file. By default relPath
is set to "/"
(root).
ocsApiWebdavManager$uploadFile( filename, relPath = "/", delete_if_existing = FALSE )
filename
file name
relPath
relative path
delete_if_existing
delete if existing file? Default is FALSE
deleteFile()
WebDAV method to delete a file. By default relPath
is set to "/"
(root).
ocsApiWebdavManager$deleteFile(filename, relPath = "/")
filename
file name
relPath
relative path
downloadFile()
Downloads a file
ocsApiWebdavManager$downloadFile(relPath, filename, outdir = ".")
relPath
relative path
filename
file name
outdir
the out directory where to download the file
getPublicFile()
Get details of a shared public file given its share token
ocsApiWebdavManager$getPublicFile(share_token)
share_token
the share token
clone()
The objects of this class are cloneable with this method.
ocsApiWebdavManager$clone(deep = FALSE)
deep
Whether to make a deep clone.
Emmanuel Blondel <[email protected]>
ocsManager
ocsManager
R6Class
object.
Object of R6Class
for modelling an ocsManager
ocs4R::ocs4RLogger
-> ocsManager
apis
list of APIs
new()
This method is used to instantiate an ocsManager. The user/pwd are mandatory in order to connect to 'ocs'. The logger can be either NULL, "INFO" (with minimum logs), or "DEBUG" (for complete curl http calls logs).
The keyring_backend
can be set to use a different backend for storing
the user password with keyring (Default value is NULL, meaning the password
is stored as private field).
ocsManager$new(url, user, pwd, logger = NULL, keyring_backend = NULL)
url
url
user
user
pwd
pwd
logger
logger type
keyring_backend
keyring back-end. Default is NULL
connect()
Method to connect to 'ocs' and set version/capabilities
ocsManager$connect()
getVersion()
Get the 'ocs' server version
ocsManager$getVersion()
getCapabilities()
Get the 'ocs' server capabilities
ocsManager$getCapabilities()
getAPIWebdavManager()
Get the Webdav API manager
ocsManager$getAPIWebdavManager()
an instance of ocsApiWebdavManager
getAPISharingManager()
Get the Sharing API manager
ocsManager$getAPISharingManager()
an instance of ocsApiSharingManager
getAPIUserProvisioningManager()
Get the User Provisioning API manager
ocsManager$getAPIUserProvisioningManager()
an instance of ocsApiUserProvisioningManager
clone()
The objects of this class are cloneable with this method.
ocsManager$clone(deep = FALSE)
deep
Whether to make a deep clone.
Emmanuel Blondel <[email protected]>
## Not run: #Not Run: #Connect to an OCS API OCS <- ocsManager$new(url = ocs_url, user = ocs_user, pwd = ocs_pwd, logger = "DEBUG") version <- OCS$getVersion() caps <- OCS$getCapabilities() #OCS User Provisioning API #------------------------------------- #users users <- OCS$getUsers() #get users user <- OCS$getUser("admin") #get a user user.df <- OCS$getUser("admin", TRUE) #the same user as data.frame added <- OCS$addUser("john.doe", password = "ocs4john") #add a user disabled <- OCS$disableUser("john.doe") #disable a user enabled <- OCS$enableUser("john.doe") #enable auser edited <- OCS$editUser("john.doe", key = "display", value = "John Doe") #edit user #edit some user field edited2 <- OCS$editUserDisplayName("john.doe", displayName = "John Doe Jr.") deleted <- OCS$deleteUser("john.doe") #groups admingroups <- OCS$getUserGroups("admin") groups <- OCS$getGroups() added <- OCS$addGroup("scientists") #add a new group sc_group <- OCS$getGroup("scientists") #get group details added <- OCS$addToGroup("john.doe", "scientists") #add user to group removed <- OCS$removeFromGroup("john.doe", "scientists") #remove user from group deleted <- OCS$deleteGroup("scientists") #OCS Webdav API #------------------------------------- #list files files <- OCS$listFiles() subfiles <- OCS$listFiles("Documents") #make collection OCS$makeCollection("myfolder") subfiles <- OCS$listFiles("myfolder") #upload a file? filename <- "magic.txt" file.create(filename); writeLines("ocs4R is great", filename) #we upload the file in 'Documents' folder OCS$uploadFile(filename, "/Documents") #check if file is uploaded OCS$listFiles('Documents') #OCS Sharing API #------------------------------------- #let's add a user with User provisioning API added <- OCS$addUser("john.doe", password = "ocs4john") #add a user #let's share the previously uploaded file with John Doe OCS$shareWithUser("/Documents", filename, "john.doe") ## End(Not run)
## Not run: #Not Run: #Connect to an OCS API OCS <- ocsManager$new(url = ocs_url, user = ocs_user, pwd = ocs_pwd, logger = "DEBUG") version <- OCS$getVersion() caps <- OCS$getCapabilities() #OCS User Provisioning API #------------------------------------- #users users <- OCS$getUsers() #get users user <- OCS$getUser("admin") #get a user user.df <- OCS$getUser("admin", TRUE) #the same user as data.frame added <- OCS$addUser("john.doe", password = "ocs4john") #add a user disabled <- OCS$disableUser("john.doe") #disable a user enabled <- OCS$enableUser("john.doe") #enable auser edited <- OCS$editUser("john.doe", key = "display", value = "John Doe") #edit user #edit some user field edited2 <- OCS$editUserDisplayName("john.doe", displayName = "John Doe Jr.") deleted <- OCS$deleteUser("john.doe") #groups admingroups <- OCS$getUserGroups("admin") groups <- OCS$getGroups() added <- OCS$addGroup("scientists") #add a new group sc_group <- OCS$getGroup("scientists") #get group details added <- OCS$addToGroup("john.doe", "scientists") #add user to group removed <- OCS$removeFromGroup("john.doe", "scientists") #remove user from group deleted <- OCS$deleteGroup("scientists") #OCS Webdav API #------------------------------------- #list files files <- OCS$listFiles() subfiles <- OCS$listFiles("Documents") #make collection OCS$makeCollection("myfolder") subfiles <- OCS$listFiles("myfolder") #upload a file? filename <- "magic.txt" file.create(filename); writeLines("ocs4R is great", filename) #we upload the file in 'Documents' folder OCS$uploadFile(filename, "/Documents") #check if file is uploaded OCS$listFiles('Documents') #OCS Sharing API #------------------------------------- #let's add a user with User provisioning API added <- OCS$addUser("john.doe", password = "ocs4john") #add a user #let's share the previously uploaded file with John Doe OCS$shareWithUser("/Documents", filename, "john.doe") ## End(Not run)
ocsRequest
ocsRequest
R6Class
object.
Object of R6Class
for modelling a generic 'ocs' web-service request
new(type, url, request, user, pwd, token, cookies,
format, namedParams, content, contentType, filename, logger, ...)
This method is used to instantiate a object for doing an 'ocs' web-service request
getRequest()
Get the request payload
getRequestHeaders()
Get the request headers
getStatus()
Get the request status code
getResponse()
Get the request response
getException()
Get the exception (in case of request failure)
getResult()
Get the result TRUE
if the request is successful, FALSE
otherwise
ocs4R::ocs4RLogger
-> ocsRequest
new()
This method is used to instantiate a object for doing an 'ocs' web-service request
ocsRequest$new( type, url, request, user = NULL, pwd = NULL, token = NULL, cookies = NULL, format = "json", namedParams = list(), content = NULL, contentType = "text/plain", filename = NULL, logger = NULL, ... )
type
type of request
url
url
request
request
user
user
pwd
pwd
token
token
cookies
cookies
format
format. Default is "json"
namedParams
a list of named parameters
content
content
contentType
content type. Default is "text/plain"
filename
file name
logger
logger
...
additional parameters
execute()
Executes the request
ocsRequest$execute()
getRequest()
Get request
ocsRequest$getRequest()
getRequestHeaders()
Get request headers
ocsRequest$getRequestHeaders()
getStatus()
Get status
ocsRequest$getStatus()
getResponse()
Get response
ocsRequest$getResponse()
getException()
Get exception
ocsRequest$getException()
getResult()
Get result
ocsRequest$getResult()
setResult()
Set result
ocsRequest$setResult(result)
result
result
clone()
The objects of this class are cloneable with this method.
ocsRequest$clone(deep = FALSE)
deep
Whether to make a deep clone.
Abstract class used internally by ocs4R
Emmanuel Blondel <[email protected]>