1 source("./R/HttpRequest.R")
2 source("./R/HttpParser.R")
6 #' All Arvados logic is inside this class
8 #' @field token Token represents user authentification token.
9 #' @field host Host represents server name we wish to connect to.
10 #' @examples arv = Arvados$new("token", "host_name")
12 Arvados <- R6::R6Class(
18 initialize = function(auth_token = NULL, host_name = NULL)
20 if(!is.null(host_name))
21 Sys.setenv(ARVADOS_API_HOST = host_name)
23 if(!is.null(auth_token))
24 Sys.setenv(ARVADOS_API_TOKEN = auth_token)
26 host <- Sys.getenv("ARVADOS_API_HOST");
27 token <- Sys.getenv("ARVADOS_API_TOKEN");
29 if(host == "" | token == "")
30 stop("Please provide host name and authentification token or set ARVADOS_API_HOST and ARVADOS_API_TOKEN environmental variables.")
32 discoveryDocumentURL <- paste0("https://", host, "/discovery/v1/apis/arvados/v1/rest")
35 host <- paste0("https://", host, "/arvados/", version, "/")
37 private$http <- HttpRequest$new()
38 private$httpParser <- HttpParser$new()
39 private$token <- token
42 headers <- list(Authorization = paste("OAuth2", private$token))
44 serverResponse <- private$http$GET(discoveryDocumentURL, headers)
46 discoveryDocument <- private$httpParser$parseJSONResponse(serverResponse)
47 private$webDavHostName <- discoveryDocument$keepWebServiceUrl
50 getToken = function() private$token,
51 getHostName = function() private$host,
53 #Todo(Fudo): Hardcoded credentials to WebDAV server. Remove them later
54 getWebDavHostName = function() private$webDavHostName,
56 getCollection = function(uuid)
58 collectionURL <- paste0(private$host, "collections/", uuid)
59 headers <- list(Authorization = paste("OAuth2", private$token))
61 serverResponse <- private$http$GET(collectionURL, headers)
63 collection <- private$httpParser$parseJSONResponse(serverResponse)
65 if(!is.null(collection$errors))
66 stop(collection$errors)
71 listCollections = function(filters = NULL, limit = 100, offset = 0)
73 collectionURL <- paste0(private$host, "collections")
74 headers <- list(Authorization = paste("OAuth2", private$token))
76 serverResponse <- private$http$GET(collectionURL, headers, filters, limit, offset)
77 collection <- private$httpParser$parseJSONResponse(serverResponse)
79 if(!is.null(collection$errors))
80 stop(collection$errors)
85 deleteCollection = function(uuid)
87 collectionURL <- paste0(private$host, "collections/", uuid)
88 headers <- list("Authorization" = paste("OAuth2", private$token),
89 "Content-Type" = "application/json")
91 serverResponse <- private$http$DELETE(collectionURL, headers)
93 collection <- private$httpParser$parseJSONResponse(serverResponse)
95 if(!is.null(collection$errors))
96 stop(collection$errors)
101 updateCollection = function(uuid, body)
103 collectionURL <- paste0(private$host, "collections/", uuid)
104 headers <- list("Authorization" = paste("OAuth2", private$token),
105 "Content-Type" = "application/json")
107 body <- jsonlite::toJSON(body, auto_unbox = T)
109 serverResponse <- private$http$PUT(collectionURL, headers, body)
111 collection <- private$httpParser$parseJSONResponse(serverResponse)
113 if(!is.null(collection$errors))
114 stop(collection$errors)
119 createCollection = function(body)
121 collectionURL <- paste0(private$host, "collections")
122 headers <- list("Authorization" = paste("OAuth2", private$token),
123 "Content-Type" = "application/json")
124 body <- jsonlite::toJSON(body, auto_unbox = T)
126 serverResponse <- private$http$POST(collectionURL, headers, body)
128 collection <- private$httpParser$parseJSONResponse(serverResponse)
130 if(!is.null(collection$errors))
131 stop(collection$errors)
142 webDavHostName = NULL,