1 source("./R/RESTService.R")
2 source("./R/HttpRequest.R")
3 source("./R/HttpParser.R")
7 #' Arvados class gives users ability to manipulate collections and projects.
10 #' \preformatted{arv = Arvados$new(authToken = NULL, hostName = NULL, numRetries = 0)}
12 #' @section Arguments:
14 #' \item{authToken}{Authentification token. If not specified ARVADOS_API_TOKEN environment variable will be used.}
15 #' \item{hostName}{Host name. If not specified ARVADOS_API_HOST environment variable will be used.}
16 #' \item{numRetries}{Number which specifies how many times to retry failed service requests.}
21 #' \item{getToken()}{Returns authentification token currently in use.}
22 #' \item{getHostName()}{Returns host name currently in use.}
23 #' \item{getNumRetries()}{Returns number which specifies how many times to retry failed service requests.}
24 #' \item{setNumRetries(newNumOfRetries)}{Sets number which specifies how many times to retry failed service requests.}
25 #' \item{getCollection(uuid)}{Get collection with specified UUID.}
26 #' \item{listCollections(filters = NULL, limit = 100, offset = 0)}{Returns list of collections based on filters parameter.}
27 #' \item{listAllCollections(filters = NULL)}{Lists all collections, based on filters parameter, even if the number of items is greater than maximum API limit.}
28 #' \item{deleteCollection(uuid)}{Deletes collection with specified UUID.}
29 #' \item{updateCollection(uuid, newContent)}{Updates collection with specified UUID.}
30 #' \item{createCollection(content)}{Creates new collection.}
31 #' \item{getProject(uuid)}{Get project with specified UUID.}
32 #' \item{listProjects(filters = NULL, limit = 100, offset = 0)}{Returns list of projects based on filters parameter.}
33 #' \item{listAllProjects(filters = NULL)}{Lists all projects, based on filters parameter, even if the number of items is greater than maximum API limit.}
34 #' \item{deleteProject(uuid)}{Deletes project with specified UUID.}
35 #' \item{updateProject(uuid, newContent)}{Updates project with specified UUID.}
36 #' \item{createProject(content)}{Creates new project.}
42 #' arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
44 #' collection <- arv$getCollection("uuid")
46 #' collectionList <- arv$listCollections(list(list("name", "like", "Test%")))
47 #' collectionList <- arv$listAllCollections(list(list("name", "like", "Test%")))
49 #' deletedCollection <- arv$deleteCollection("uuid")
51 #' updatedCollection <- arv$updateCollection("uuid", list(name = "New name",
52 #' description = "New description"))
54 #' createdCollection <- arv$createCollection(list(name = "Example",
55 #' description = "This is a test collection"))
60 Arvados <- R6::R6Class(
66 initialize = function(authToken = NULL, hostName = NULL, numRetries = 0)
68 if(!is.null(hostName))
69 Sys.setenv(ARVADOS_API_HOST = hostName)
71 if(!is.null(authToken))
72 Sys.setenv(ARVADOS_API_TOKEN = authToken)
74 hostName <- Sys.getenv("ARVADOS_API_HOST");
75 token <- Sys.getenv("ARVADOS_API_TOKEN");
77 if(hostName == "" | token == "")
78 stop(paste("Please provide host name and authentification token",
79 "or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
80 "environment variables."))
82 private$numRetries <- numRetries
83 private$REST <- RESTService$new(token, hostName,
84 HttpRequest$new(), HttpParser$new(),
87 private$token <- private$REST$token
88 private$host <- private$REST$hostName
91 getToken = function() private$REST$token,
92 getHostName = function() private$REST$hostName,
93 getWebDavHostName = function() private$REST$getWebDavHostName(),
94 getRESTService = function() private$REST,
95 setRESTService = function(newRESTService) private$REST <- newRESTService,
97 getNumRetries = function() private$REST$numRetries,
98 setNumRetries = function(newNumOfRetries)
100 private$REST$setNumRetries(newNumOfRetries)
103 getCollection = function(uuid)
105 collection <- private$REST$getResource("collections", uuid)
109 listCollections = function(filters = NULL, limit = 100, offset = 0)
111 if(!is.null(filters))
112 names(filters) <- c("collection")
114 collections <- private$REST$listResources("collections", filters,
119 listAllCollections = function(filters = NULL)
121 if(!is.null(filters))
122 names(filters) <- c("collection")
124 collectionURL <- paste0(private$host, "collections")
125 allCollection <- private$REST$fetchAllItems(collectionURL, filters)
129 deleteCollection = function(uuid)
131 removedCollection <- private$REST$deleteResource("collections", uuid)
135 updateCollection = function(uuid, newContent)
138 names(body) <- c("collection")
139 body$collection <- newContent
141 updatedCollection <- private$REST$updateResource("collections",
146 createCollection = function(content)
149 names(body) <- c("collection")
150 body$collection <- content
152 newCollection <- private$REST$createResource("collections", body)
156 getProject = function(uuid)
158 project <- private$REST$getResource("groups", uuid)
162 createProject = function(content)
165 names(body) <- c("group")
166 body$group <- c("group_class" = "project", content)
168 newProject <- private$REST$createResource("groups", body)
172 updateProject = function(uuid, newContent)
175 names(body) <- c("group")
176 body$group <- newContent
178 updatedProject <- private$REST$updateResource("groups", uuid, body)
182 listProjects = function(filters = NULL, limit = 100, offset = 0)
184 if(!is.null(filters))
185 names(filters) <- c("groups")
187 filters[[length(filters) + 1]] <- list("group_class", "=", "project")
189 projects <- private$REST$listResources("groups", filters, limit, offset)
193 listAllProjects = function(filters = NULL)
195 if(!is.null(filters))
196 names(filters) <- c("groups")
198 filters[[length(filters) + 1]] <- list("group_class", "=", "project")
200 projectURL <- paste0(private$host, "groups")
202 result <- private$REST$fetchAllItems(projectURL, filters)
206 deleteProject = function(uuid)
208 removedProject <- private$REST$deleteResource("groups", uuid)
226 #' Custom print function for Arvados class
228 #' @param x Instance of Arvados class
229 #' @param ... Optional arguments.
231 print.Arvados = function(x, ...)
233 cat(paste0("Type: ", "\"", "Arvados", "\""), sep = "\n")
234 cat(paste0("Host: ", "\"", x$getHostName(), "\""), sep = "\n")
235 cat(paste0("Token: ", "\"", x$getToken(), "\""), sep = "\n")