1 source("./R/RESTService.R")
2 source("./R/HttpRequest.R")
3 source("./R/HttpParser.R")
7 #' All Arvados logic is inside this class
9 #' @field token Token represents user authentification token.
10 #' @field host Host represents server name we wish to connect to.
11 #' @examples arv = Arvados$new("token", "host_name")
13 Arvados <- R6::R6Class(
19 initialize = function(authToken = NULL, hostName = NULL, numRetries = 0)
21 if(!is.null(hostName))
22 Sys.setenv(ARVADOS_API_HOST = hostName)
24 if(!is.null(authToken))
25 Sys.setenv(ARVADOS_API_TOKEN = authToken)
27 hostName <- Sys.getenv("ARVADOS_API_HOST");
28 token <- Sys.getenv("ARVADOS_API_TOKEN");
30 if(hostName == "" | token == "")
31 stop(paste("Please provide host name and authentification token",
32 "or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
33 "environment variables."))
35 private$numRetries <- numRetries
36 private$REST <- RESTService$new(token, hostName,
37 HttpRequest$new(), HttpParser$new(),
40 private$token <- private$REST$token
41 private$host <- private$REST$hostName
44 getToken = function() private$REST$token,
45 getHostName = function() private$REST$hostName,
46 getWebDavHostName = function() private$REST$getWebDavHostName(),
47 getRESTService = function() private$REST,
48 setRESTService = function(newRESTService) private$REST <- newRESTService,
50 getNumRetries = function() private$REST$numRetries,
51 setNumRetries = function(newNumOfRetries)
53 private$REST$setNumRetries(newNumOfRetries)
56 getCollection = function(uuid)
58 collection <- private$REST$getResource("collections", uuid)
62 listCollections = function(filters = NULL, limit = 100, offset = 0)
65 names(filters) <- c("collection")
67 collections <- private$REST$listResources("collections", filters,
72 listAllCollections = function(filters = NULL)
75 names(filters) <- c("collection")
77 collectionURL <- paste0(private$host, "collections")
78 allCollection <- private$REST$fetchAllItems(collectionURL, filters)
82 deleteCollection = function(uuid)
84 removedCollection <- private$REST$deleteResource("collections", uuid)
88 updateCollection = function(uuid, newContent)
91 names(body) <- c("collection")
92 body$collection <- newContent
94 updatedCollection <- private$REST$updateResource("collections",
99 createCollection = function(content)
102 names(body) <- c("collection")
103 body$collection <- content
105 newCollection <- private$REST$createResource("collections", body)
109 getProject = function(uuid)
111 project <- private$REST$getResource("groups", uuid)
115 createProject = function(content)
118 names(body) <- c("group")
119 body$group <- c("group_class" = "project", content)
121 newProject <- private$REST$createResource("groups", body)
125 updateProject = function(uuid, newContent)
128 names(body) <- c("group")
129 body$group <- newContent
131 updatedProject <- private$REST$updateResource("groups", uuid, body)
135 listProjects = function(filters = NULL, limit = 100, offset = 0)
137 if(!is.null(filters))
138 names(filters) <- c("groups")
140 filters[[length(filters) + 1]] <- list("group_class", "=", "project")
142 projects <- private$REST$listResources("groups", filters, limit, offset)
146 listAllProjects = function(filters = NULL)
148 if(!is.null(filters))
149 names(filters) <- c("groups")
151 filters[[length(filters) + 1]] <- list("group_class", "=", "project")
153 projectURL <- paste0(private$host, "groups")
155 result <- private$REST$fetchAllItems(projectURL, filters)
159 deleteProject = function(uuid)
161 removedProject <- private$REST$deleteResource("groups", uuid)
177 #' @export print.Arvados
178 print.Arvados = function(arvados)
180 cat(paste0("Type: ", "\"", "Arvados", "\""), sep = "\n")
181 cat(paste0("Host: ", "\"", arvados$getHostName(), "\""), sep = "\n")
182 cat(paste0("Token: ", "\"", arvados$getToken(), "\""), sep = "\n")