*#*
.DS_Store
.vscode
+.Rproj.user
--- /dev/null
+^.*\.Rproj$
+^\.Rproj\.user$
--- /dev/null
+Version: 1.0
+
+RestoreWorkspace: Default
+SaveWorkspace: Default
+AlwaysSaveHistory: Default
+
+EnableCodeIndexing: Yes
+UseSpacesForTab: Yes
+NumSpacesForTab: 4
+Encoding: UTF-8
+
+RnwWeave: Sweave
+LaTeX: pdfLaTeX
+
+AutoAppendNewline: Yes
+StripTrailingWhitespace: Yes
+
+BuildType: Package
+PackageUseDevtools: Yes
+PackageInstallArgs: --no-multiarch --with-keep.source
--- /dev/null
+Package: ArvadosSDK
+Type: Package
+Title: What the Package Does (Title Case)
+Version: 0.1.0
+Author: Who wrote it
+Maintainer: The package maintainer <yourself@somewhere.net>
+Description: More about what it does (maybe more than one line)
+ Use four spaces when indenting paragraphs within the Description.
+License: What license is it under?
+Encoding: UTF-8
+LazyData: true
+RoxygenNote: 6.0.1.9000
+Imports:
+ httr,
+ stringr,
+ jsonlite,
+ curl,
+ XML
--- /dev/null
+# Generated by roxygen2: do not edit by hand
+
+export(Arvados)
+export(Collection)
--- /dev/null
+source("./R/HttpRequest.R")
+source("./R/HttpParser.R")
+source("./R/custom_classes.R")
+
+#' Arvados SDK Object
+#'
+#' All Arvados logic is inside this class
+#'
+#' @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(
+
+ "Arvados",
+
+ fields = list(
+ token = "ANY",
+ host = "ANY"
+ ),
+
+ methods = list(
+
+ initialize = function(auth_token = NULL, host_name = NULL)
+ {
+ version <- "v1"
+ #Todo(Fudo): Set environment variables
+ token <<- auth_token
+ host <<- paste0("https://", host_name, "/arvados/", version, "/")
+ }
+ )
+)
+
+#' collection_get
+#'
+#' Get Arvados collection
+#'
+#' @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_relative_url <- paste0("collections/", uuid)
+ http_request <- HttpRequest("GET", 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_list
+#'
+#' Retreive list of collections based on provided filter.
+#'
+#' @name collection_list
+#' @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,
+ body = NULL, filters, limit, offset)
+
+ server_response <- http_request$execute()
+
+ httpParser <- HttpParser()
+ collection <- httpParser$parseCollectionGet(server_response)
+
+ if(!is.null(collection$errors))
+ stop(collection$errors)
+
+ class(collection) <- "ArvadosCollectionList"
+
+ 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)
+ }
+)
--- /dev/null
+source("./R/Arvados.R")
+source("./R/HttpParser.R")
+
+#' Collection Object
+#'
+#' @details
+#' Todo: Update description
+#' Collection
+#'
+#' @param uuid Object ID
+#' @param etag Object version
+#' @param owner_uuid No description
+#' @param created_at No description
+#' @param modified_by_client_uuid No description
+#' @param modified_by_user_uuid No description
+#' @param modified_at No description
+#' @param portable_data_hash No description
+#' @param replication_desired No description
+#' @param replication_confirmed_at No description
+#' @param replication_confirmed No description
+#' @param updated_at No description
+#' @param manifest_text No description
+#' @param name No description
+#' @param description No description
+#' @param properties No description
+#' @param delete_at No description
+#' @param file_names No description
+#' @param trash_at No description
+#' @param is_trashed No description
+#'
+#' @export
+Collection <- setRefClass(
+
+ "Collection",
+
+ #NOTE(Fudo): Fix types!
+ fields = list(uuid = "ANY",
+ items = "ANY",
+ etag = "ANY",
+ owner_uuid = "ANY",
+ created_at = "ANY",
+ modified_by_client_uuid = "ANY",
+ modified_by_user_uuid = "ANY",
+ modified_at = "ANY",
+ portable_data_hash = "ANY",
+ replication_desired = "ANY",
+ replication_confirmed_at = "ANY",
+ replication_confirmed = "ANY",
+ updated_at = "ANY",
+ manifest_text = "ANY",
+ name = "ANY",
+ description = "ANY",
+ properties = "ANY",
+ delete_at = "ANY",
+ file_names = "ANY",
+ trash_at = "ANY",
+ is_trashed = "ANY",
+ arvados_api = "Arvados"
+ ),
+
+ methods = list(
+
+ initialize = function(api, uuid)
+ {
+ arvados_api <<- api
+ result <- arvados_api$collection_get(uuid)
+
+ uuid <<- result$uuid
+ etag <<- result$etag
+ owner_uuid <<- result$owner_uuid
+ created_at <<- result$created_at
+ modified_by_client_uuid <<- result$modified_by_client_uuid
+ modified_by_user_uuid <<- result$modified_by_user_uuid
+ modified_at <<- result$modified_at
+ portable_data_hash <<- result$portable_data_hash
+ replication_desired <<- result$replication_desired
+ replication_confirmed_at <<- result$replication_confirmed_at
+ replication_confirmed <<- result$replication_confirmed
+ updated_at <<- result$updated_at
+ manifest_text <<- result$manifest_text
+ name <<- result$name
+ description <<- result$description
+ properties <<- result$properties
+ delete_at <<- result$delete_at
+ file_names <<- result$file_names
+ trash_at <<- result$trash_at
+ is_trashed <<- result$is_trashed
+
+ items <<- getCollectionContent()
+ },
+
+ getCollectionContent = function()
+ {
+ #IMPORTANT(Fudo): This url is hardcoded for now. Fix it later.
+ uri <- URLencode("https://collections.4xphq.arvadosapi.com/c=4xphq-4zz18-9d5b0qm4fgijeyi/_/")
+
+ # fetch directory listing via curl and parse XML response
+ h <- curl::new_handle()
+ curl::handle_setopt(h, customrequest = "PROPFIND")
+
+ #IMPORTANT(Fudo): Token is hardcoded as well. Write it properly.
+ curl::handle_setheaders(h, "Authorization" = paste("OAuth2 4invqy35tf70t7hmvdc83ges8ug9cklhgqq1l8gj2cjn18teuq"))
+ response <- curl::curl_fetch_memory(uri, h)
+
+ HttpParser()$parseWebDAVResponse(response, uri)
+ }
+ )
+)
--- /dev/null
+#' HttpParser
+#'
+HttpParser <- setRefClass(
+
+ "HttrParser",
+
+ fields = list(
+ ),
+
+ methods = list(
+ initialize = function()
+ {
+ },
+
+ parseCollectionGet = function(server_response)
+ {
+ parsed_response <- httr::content(server_response, as = "parsed", type = "application/json")
+
+ #Todo(Fudo): Create new Collection object and populate it
+ },
+
+ parseWebDAVResponse = function(response, uri)
+ {
+ #Todo(Fudo): Move this to HttpParser.
+ text <- rawToChar(response$content)
+ doc <- XML::xmlParse(text, asText=TRUE)
+
+ # calculate relative paths
+ base <- paste(paste("/", strsplit(uri, "/")[[1]][-1:-3], sep="", collapse=""), "/", sep="")
+ result <- unlist(
+ XML::xpathApply(doc, "//D:response/D:href", function(node) {
+ sub(base, "", URLdecode(xmlValue(node)), fixed=TRUE)
+ })
+ )
+ result[result != ""]
+ }
+
+ )
+)
--- /dev/null
+source("./R/custom_classes.R")
+
+HttpRequest <- setRefClass(
+
+ "HttrRequest",
+
+ fields = list(
+ send_method = "character",
+ server_base_url = "character",
+ server_relative_url = "character",
+ auth_token = "character",
+ allowed_methods = "list",
+ request_body = "ANY",
+ query_filters = "ANY",
+ response_limit = "ANY",
+ query_offset = "ANY"
+ ),
+
+ methods = list(
+ initialize = function(method,
+ token,
+ base_url,
+ relative_url,
+ body = NULL,
+ filters = NULL,
+ limit = 100,
+ offset = 0)
+ {
+ send_method <<- method
+ 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,
+ "PUT" = .self$putRequest,
+ "DELETE" = .self$deleteRequest,
+ "PATCH" = .self$pathcRequest)
+ http_method()
+ },
+
+ getRequest = function()
+ {
+ requestHeaders <- httr::add_headers(Authorization = .self$getAuthHeader())
+ requestQuery <- .self$generateQuery()
+ url <- paste0(server_base_url, server_relative_url, requestQuery)
+
+ server_data <- httr::GET(url = url,
+ config = requestHeaders)
+ },
+
+ #Todo(Fudo): Try to make this more generic
+ postRequest = function()
+ {
+ 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()
+ {
+ 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()
+ {
+ 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()
+ {
+ #Todo(Fudo): Implement this later on.
+ print("PATCH method")
+ },
+
+ getAuthHeader = function()
+ {
+ auth_method <- "OAuth2"
+ auth_header <- paste(auth_method, auth_token)
+ },
+
+ generateQuery = function()
+ {
+ #Todo(Fudo): This function is a mess, refactor it
+ finalQuery <- "?alt=json"
+
+ if(!is.null(query_filters))
+ {
+ filters <- sapply(query_filters, function(filter)
+ {
+ if(length(filter) != 3)
+ stop("Filter list must have exacthey 3 elements.")
+
+ attributeAndOperator = filter[c(1, 2)]
+ filterList = filter[[3]]
+ filterListIsPrimitive = TRUE
+ if(length(filterList) > 1)
+ filterListIsPrimitive = FALSE
+
+ attributeAndOperator <- sapply(attributeAndOperator, function(component) {
+ component <- paste0("\"", component, "\"")
+ })
+
+ filterList <- sapply(unlist(filterList), function(filter) {
+ filter <- paste0("\"", filter, "\"")
+ })
+
+ filterList <- paste(filterList, collapse = ",+")
+
+ if(!filterListIsPrimitive)
+ filterList <- paste0("[", filterList, "]")
+
+ filter <- c(attributeAndOperator, filterList)
+
+ queryParameter <- paste(filter, collapse = ",+")
+ queryParameter <- paste0("[", queryParameter, "]")
+
+ })
+
+ filters <- paste(filters, collapse = ",+")
+ filters <- paste0("[", filters, "]")
+
+ encodedQuery <- URLencode(filters, reserved = T, repeated = T)
+
+ finalQuery <- paste0(finalQuery, "&filters=", encodedQuery)
+
+ #Todo(Fudo): This is a hack for now. Find a proper solution.
+ finalQuery <- stringr::str_replace_all(finalQuery, "%2B", "+")
+ }
+
+ if(!is.null(response_limit))
+ {
+ if(!is.numeric(response_limit))
+ stop("Limit must be a numeric type.")
+
+ finalQuery <- paste0(finalQuery, "&limit=", response_limit)
+ }
+
+ if(!is.null(query_offset))
+ {
+ if(!is.numeric(query_offset))
+ stop("Offset must be a numeric type.")
+
+ finalQuery <- paste0(finalQuery, "&offset=", query_offset)
+ }
+
+ finalQuery
+ }
+ )
+)
--- /dev/null
+#Study(Fudo): For some reason this doesnt seem to work,
+#see what seems to be a problem.
+
+setOldClass("characterOrNULL")
+setClassUnion("characterOrNULL", c("character", "NULL"))
+
+setClassUnion("listOrNULL", c("list", "NULL"))
+setOldClass("listOrNULL")
+
+setOldClass("numericOrNULL")
+setClassUnion("numericOrNULL", c("numeric", "NULL"))
--- /dev/null
+R SDK for Arvados
\ No newline at end of file
--- /dev/null
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/Arvados.R
+\docType{class}
+\name{Arvados-class}
+\alias{Arvados-class}
+\alias{Arvados}
+\title{Arvados SDK Object}
+\description{
+All Arvados logic is inside this class
+}
+\section{Fields}{
+
+\describe{
+\item{\code{token}}{Token represents user authentification token.}
+
+\item{\code{host}}{Host represents server name we wish to connect to.}
+}}
+
+
+\examples{
+arv = Arvados("token", "host_name")
+}
--- /dev/null
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/arvados_objects.R
+\name{Collection}
+\alias{Collection}
+\title{Collection Object}
+\usage{
+Collection(uuid = NULL, etag = NULL, owner_uuid = NULL,
+ created_at = NULL, modified_by_client_uuid = NULL,
+ modified_by_user_uuid = NULL, modified_at = NULL,
+ portable_data_hash = NULL, replication_desired = NULL,
+ replication_confirmed_at = NULL, replication_confirmed = NULL,
+ updated_at = NULL, manifest_text = NULL, name = NULL,
+ description = NULL, properties = NULL, delete_at = NULL,
+ file_names = NULL, trash_at = NULL, is_trashed = NULL)
+}
+\arguments{
+\item{uuid}{Object ID}
+
+\item{etag}{Object version}
+
+\item{owner_uuid}{No description}
+
+\item{created_at}{No description}
+
+\item{modified_by_client_uuid}{No description}
+
+\item{modified_by_user_uuid}{No description}
+
+\item{modified_at}{No description}
+
+\item{portable_data_hash}{No description}
+
+\item{replication_desired}{No description}
+
+\item{replication_confirmed_at}{No description}
+
+\item{replication_confirmed}{No description}
+
+\item{updated_at}{No description}
+
+\item{manifest_text}{No description}
+
+\item{name}{No description}
+
+\item{description}{No description}
+
+\item{properties}{No description}
+
+\item{delete_at}{No description}
+
+\item{file_names}{No description}
+
+\item{trash_at}{No description}
+
+\item{is_trashed}{No description}
+}
+\value{
+Collection object
+}
+\description{
+Collection Object
+}
+\details{
+Todo: Update description
+Collection
+}
+\concept{Collection functions}
--- /dev/null
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/HttpParser.R
+\docType{class}
+\name{HttrParser-class}
+\alias{HttrParser-class}
+\alias{HttpParser}
+\title{HttpParser}
+\description{
+HttpParser
+}
+
--- /dev/null
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/Arvados.R
+\name{collection_create}
+\alias{collection_create}
+\title{collection_create}
+\description{
+Create Arvados collection
+}
+\section{Fields}{
+
+\describe{
+\item{\code{body}}{Structure of the collection we want to create.}
+}}
+
+\examples{
+arv = Arvados("token", "host_name")
+arv$collection_create(list(collection = list(name = "myCollection")))
+}
--- /dev/null
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/Arvados.R
+\name{collection_delete}
+\alias{collection_delete}
+\title{collection_delete}
+\description{
+Delete Arvados collection
+
+Delete Arvados collection
+}
+\section{Fields}{
+
+\describe{
+\item{\code{uuid}}{UUID of the collection we want to delete.}
+
+\item{\code{uuid}}{UUID of the collection we want to delete.}
+}}
+
+\examples{
+arv = Arvados("token", "host_name")
+arv$collection_delete(uuid = "aaaaa-bbbbb-ccccccccccccccc")
+arv = Arvados("token", "host_name")
+arv$collection_delete(uuid = "aaaaa-bbbbb-ccccccccccccccc")
+}
--- /dev/null
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/Arvados.R
+\name{collection_get}
+\alias{collection_get}
+\title{collection_get}
+\description{
+Get Arvados collection
+}
+\section{Fields}{
+
+\describe{
+\item{\code{uuid}}{UUID of the given collection}
+}}
+
+\examples{
+arv = Arvados("token", "host_name")
+arv$collection_get("uuid")
+}
--- /dev/null
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/Arvados.R
+\name{collection_list}
+\alias{collection_list}
+\title{collection_list}
+\description{
+Retreive list of collections based on provided filter.
+}
+\section{Fields}{
+
+\describe{
+\item{\code{filters}}{List of filters we want to use to retreive list of collections.}
+
+\item{\code{limit}}{Limits the number of result returned by server.}
+
+\item{\code{offset}}{Offset from beginning of the result set.}
+}}
+
+\examples{
+arv = Arvados("token", "host_name")
+arv$collection_list(list("uuid", "=" "aaaaa-bbbbb-ccccccccccccccc"))
+}