Added function to work with projects.
authorFuad Muhic <fmuhic@capeannenterprises.com>
Tue, 19 Dec 2017 17:02:45 +0000 (18:02 +0100)
committerFuad Muhic <fmuhic@capeannenterprises.com>
Tue, 19 Dec 2017 17:02:45 +0000 (18:02 +0100)
Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic@capeannenterprises.com>

sdk/R/R/Arvados.R
sdk/R/README

index 7d61d773c03b44d3914e57e53ece449d0d5c3c8e..2c9d003be99febed023885f173c62f22d1fa582b 100644 (file)
@@ -73,6 +73,8 @@ Arvados <- R6::R6Class(
             collectionURL <- paste0(private$host, "collections")
             headers <- list(Authorization = paste("OAuth2", private$token))
 
+            names(filters) <- c("collection")
+
             serverResponse <- private$http$GET(collectionURL, headers, filters, limit, offset)
             collection <- private$httpParser$parseJSONResponse(serverResponse)
 
@@ -104,6 +106,7 @@ Arvados <- R6::R6Class(
             headers <- list("Authorization" = paste("OAuth2", private$token),
                             "Content-Type"  = "application/json")
 
+            names(body) <- c("collection")
             body <- jsonlite::toJSON(body, auto_unbox = T)
 
             serverResponse <- private$http$PUT(collectionURL, headers, body)
@@ -121,6 +124,8 @@ Arvados <- R6::R6Class(
             collectionURL <- paste0(private$host, "collections")
             headers <- list("Authorization" = paste("OAuth2", private$token),
                             "Content-Type"  = "application/json")
+
+            names(body) <- c("collection")
             body <- jsonlite::toJSON(body, auto_unbox = T)
 
             serverResponse <- private$http$POST(collectionURL, headers, body)
@@ -131,8 +136,92 @@ Arvados <- R6::R6Class(
                 stop(collection$errors)       
 
             collection
-        }
+        },
+
+        getProject = function(uuid)
+        {
+            projectURL <- paste0(private$host, "groups/", uuid)
+            headers <- list(Authorization = paste("OAuth2", private$token))
+
+            serverResponse <- private$http$GET(projectURL, headers)
+
+            project <- private$httpParser$parseJSONResponse(serverResponse)
+
+            if(!is.null(project$errors))
+                stop(project$errors)       
+
+            project
+        },
+
+        createProject = function(body) 
+        {
+            projectURL <- paste0(private$host, "groups")
+            headers <- list("Authorization" = paste("OAuth2", private$token),
+                            "Content-Type"  = "application/json")
+
+            names(body) <- c("group")
+            body <- jsonlite::toJSON(body, auto_unbox = T)
+
+            serverResponse <- private$http$POST(projectURL, headers, body)
+
+            project <- private$httpParser$parseJSONResponse(serverResponse)
+
+            if(!is.null(project$errors))
+                stop(project$errors)       
+
+            project
+        },
+
+        updateProject = function(uuid, body) 
+        {
+            projectURL <- paste0(private$host, "groups/", uuid)
+            headers <- list("Authorization" = paste("OAuth2", private$token),
+                            "Content-Type"  = "application/json")
+
+            names(body) <- c("group")
+            body <- jsonlite::toJSON(body, auto_unbox = T)
+
+            serverResponse <- private$http$PUT(projectURL, headers, body)
+
+            project <- private$httpParser$parseJSONResponse(serverResponse)
+
+            if(!is.null(project$errors))
+                stop(project$errors)       
+
+            project
+        },
+
+        listProjects = function(filters = NULL, limit = 100, offset = 0) 
+        {
+            projectURL <- paste0(private$host, "groups")
+            headers <- list(Authorization = paste("OAuth2", private$token))
+
+            names(filters) <- c("groups")
 
+            serverResponse <- private$http$GET(projectURL, headers, filters, limit, offset)
+            projects <- private$httpParser$parseJSONResponse(serverResponse)
+
+            if(!is.null(projects$errors))
+                stop(projects$errors)       
+
+            projects
+        },
+
+        deleteProject = function(uuid) 
+        {
+            projectURL <- paste0(private$host, "groups/", uuid)
+            headers <- list("Authorization" = paste("OAuth2", private$token),
+                            "Content-Type"  = "application/json")
+
+            serverResponse <- private$http$DELETE(projectURL, headers)
+
+            project <- private$httpParser$parseJSONResponse(serverResponse)
+
+            if(!is.null(project$errors))
+                stop(project$errors)       
+
+            project
+        }
     ),
     
     private = list(
index a59e9b576b3631e0d32b0ae06b5c7cc75fa4f392..2e2298e1876ddd4dca8bb5d07d38520aadb07b9d 100644 (file)
@@ -30,19 +30,19 @@ deletedCollection <- arv$deleteCollection("uuid")
 
 #Update collection:
 
-updatedCollection <- arv$updateCollection("uuid", list(collection = list(name = "new_name", description = "new_desciption")))
+updatedCollection <- arv$updateCollection("uuid", list((name = "new_name", description = "new_desciption")))
 
 --------------------------------------------------------------------------------------------------------------------------------
 
 #Create collection:
 
-updatedCollection <- arv$createCollection("uuid", list(collection = list(name = "new_name", description = "new_desciption")))
+cratedCollection <- arv$createCollection(list(list(name = "new_name", description = "new_desciption")))
 
 --------------------------------------------------------------------------------------------------------------------------------
 
 --------------------------------------------------------------------------------------------------------------------------------
 
-#Collection manipulation:
+#Collection content manipulation:
 
 --------------------------------------------------------------------------------------------------------------------------------
 
@@ -137,3 +137,35 @@ collection$remove(file)
 collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
 
 --------------------------------------------------------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------------------------------------------------------
+
+#Get project:
+
+arv$getProject("uuid")
+
+--------------------------------------------------------------------------------------------------------------------------------
+
+#List projects:
+
+projects <- arv$listProjects(list("uuid", "=" "aaaaa-bbbbb-ccccccccccccccc"), limit = 10, offset = 2)
+
+--------------------------------------------------------------------------------------------------------------------------------
+
+#Delete project:
+
+deletedProject <- arv$deleteProject("uuid")
+
+--------------------------------------------------------------------------------------------------------------------------------
+
+#Update project:
+
+updatedProject <- arv$updateProject("uuid", list((name = "new_name", description = "new_desciption")))
+
+--------------------------------------------------------------------------------------------------------------------------------
+
+#Create project:
+
+cratedProject <- arv$createProject(list(list(name = "project_name", description = "project_desciption")))
+
+--------------------------------------------------------------------------------------------------------------------------------