#'
#' All Arvados logic is inside this class
#'
-#' @field token represents user authentification token.
-#' @field host represents server name we wish to connect to.
+#' @field token Token represents user authentification token.
+#' @field host Host represents server name we wish to connect to.
+#' @examples arv = Arvados("token", "host_name")
#' @export Arvados
Arvados <- setRefClass(
initialize = function(auth_token, host_name)
{
+ version <- "v1"
#Todo(Fudo): Validate token
token <<- auth_token
- host <<- host_name
+ host <<- paste0("https://", host_name, "/arvados/", version, "/")
}
)
)
#'
#' @name collection_get
#' @field uuid UUID of the given collection
+#' @examples arv = Arvados("token", "hostName")
+#' @examples arv$collection_get("uuid")
Arvados$methods(
collection_get = function(uuid)
#' collection_list
#'
-#' List Arvados collections based on filter matching
+#' Retreive list of collections based on provided filter.
#'
#' @name collection_list
-#' @field uuid UUID of the given collection
+#' @field filters List of filters we want to use to retreive list of collections.
+#' @field limit Limits the number of result returned by server.
+#' @field offset Offset from beginning of the result set.
+#' @examples arv = Arvados("token", "hostName")
+#' @examples arv$collection_list(list("uuid", "=" "aaaaa-bbbbb-ccccccccccccccc"))
Arvados$methods(
collection_list = function(filters = NULL, limit = NULL, offset = NULL)
{
#Todo(Fudo): Implement limit and offset
collection_relative_url <- "collections"
- http_request <- HttpRequest("GET", token, host, collection_relative_url, filters, limit, offset)
+ http_request <- HttpRequest("GET", token, host, collection_relative_url,
+ body = NULL, filters, limit, offset)
+
server_response <- http_request$execute()
httpParser <- HttpParser()
return(collection)
}
)
+
+#' collection_create
+#'
+#' Create Arvados collection
+#'
+#' @name collection_create
+#' @field body Structure of the collection we want to create.
+#' @examples arv = Arvados("token", "hostName")
+#' @examples arv$collection_create(list(collection = list(name = "myCollection")))
+Arvados$methods(
+
+ collection_create = function(body)
+ {
+ collection_relative_url <- paste0("collections/", "/?alt=json")
+ body = jsonlite::toJSON(body, auto_unbox = T)
+
+ http_request <- HttpRequest("POST", token, host, collection_relative_url, body)
+ server_response <- http_request$execute()
+
+ httpParser <- HttpParser()
+ collection <- httpParser$parseCollectionGet(server_response)
+
+ if(!is.null(collection$errors))
+ stop(collection$errors)
+
+ class(collection) <- "ArvadosCollection"
+
+ return(collection)
+ }
+)
+
+#' collection_delete
+#'
+#' Delete Arvados collection
+#'
+#' @name collection_delete
+#' @field uuid UUID of the collection we want to delete.
+#' @examples arv = Arvados("token", "hostName")
+#' @examples arv$collection_delete(uuid = "aaaaa-bbbbb-ccccccccccccccc")
+Arvados$methods(
+
+ collection_delete = function(uuid)
+ {
+ collection_relative_url <- paste0("collections/", uuid, "/?alt=json")
+
+ http_request <- HttpRequest("DELETE", token, host, collection_relative_url)
+ server_response <- http_request$execute()
+
+ httpParser <- HttpParser()
+ collection <- httpParser$parseCollectionGet(server_response)
+
+ if(!is.null(collection$errors))
+ stop(collection$errors)
+
+ class(collection) <- "ArvadosCollection"
+
+ return(collection)
+ }
+)
+
+#' collection_update
+#'
+#' Update Arvados collection
+#'
+#' @name collection_update
+#' @field uuid UUID of the collection we want to update.
+#' @field body New structure of the collection.
+#' @examples arv = Arvados("token", "hostName")
+#' @examples arv$collection_update(uuid = "aaaaa-bbbbb-ccccccccccccccc", list(collection = list(name = "newName")))
+Arvados$methods(
+
+ collection_update = function(uuid, body)
+ {
+ collection_relative_url <- paste0("collections/", uuid, "/?alt=json")
+ body = jsonlite::toJSON(body, auto_unbox = T)
+
+ http_request <- HttpRequest("PUT", token, host, collection_relative_url, body)
+ server_response <- http_request$execute()
+
+ httpParser <- HttpParser()
+ collection <- httpParser$parseCollectionGet(server_response)
+
+ if(!is.null(collection$errors))
+ stop(collection$errors)
+
+ class(collection) <- "ArvadosCollection"
+
+ return(collection)
+ }
+)
server_relative_url = "character",
auth_token = "character",
allowed_methods = "list",
+ request_body = "ANY",
query_filters = "ANY",
response_limit = "ANY",
query_offset = "ANY"
token,
base_url,
relative_url,
+ body = NULL,
filters = NULL,
limit = 100,
offset = 0)
auth_token <<- token
server_base_url <<- base_url
server_relative_url <<- relative_url
+ request_body <<- body
query_filters <<- filters
response_limit <<- limit
query_offset <<- offset
execute = function()
{
+ #Todo(Fudo): Get rid of the switch and make this module more general.
http_method <- switch(send_method,
"GET" = .self$getRequest,
"POST" = .self$postRequest,
#Todo(Fudo): Try to make this more generic
postRequest = function()
{
- #Todo(Fudo): Implement this later on.
- print("POST method")
+ url <- paste0(server_base_url, server_relative_url)
+ requestHeaders <- httr::add_headers("Authorization" = .self$getAuthHeader(),
+ "Content-Type" = "application/json")
+ response <- POST(url, body = request_body, config = requestHeaders)
},
putRequest = function()
{
- #Todo(Fudo): Implement this later on.
- print("PUT method")
+ url <- paste0(server_base_url, server_relative_url)
+ requestHeaders <- httr::add_headers("Authorization" = .self$getAuthHeader(),
+ "Content-Type" = "application/json")
+
+ response <- PUT(url, body = request_body, config = requestHeaders)
},
deleteRequest = function()
{
- #Todo(Fudo): Implement this later on.
- print("DELETE method")
+ url <- paste0(server_base_url, server_relative_url)
+ requestHeaders <- httr::add_headers("Authorization" = .self$getAuthHeader(),
+ "Content-Type" = "application/json")
+ response <- DELETE(url, config = requestHeaders)
},
pathcRequest = function()