b44e105af7ce711bb7629b94f22a2e52dd51e53a
[arvados.git] / sdk / R / R / Arvados.R
1 source("./R/HttpRequest.R")
2 source("./R/HttpParser.R")
3
4 #' Arvados SDK Object
5 #'
6 #' All Arvados logic is inside this class
7 #'
8 #' @field token represents user authentification token.
9 #' @field host represents server name we wish to connect to.
10 #' @export Arvados
11 Arvados <- setRefClass(
12
13     "Arvados",
14
15     fields = list(
16         token = "character",
17         host  = "character"
18     ),
19
20     methods = list(
21
22         initialize = function(auth_token, host_name) 
23         {
24             #Todo(Fudo): Validate token
25             token <<- auth_token
26             host  <<- host_name
27         }
28     )
29 )
30
31 #' collection_get
32 #'
33 #' Get Arvados collection
34 #'
35 #' @name collection_get
36 #' @field uuid UUID of the given collection
37 Arvados$methods(
38
39     collection_get = function(uuid) 
40     {
41         collection_relative_url <- paste0("collections/", uuid)
42         http_request <- HttpRequest("GET", token, host, collection_relative_url) 
43         server_response <- http_request$execute()
44
45         httpParser <- HttpParser()
46         collection <- httpParser$parseCollectionGet(server_response)
47         class(collection) <- "ArvadosCollection"
48
49         return(collection)
50     }
51 )
52
53 #' collection_list
54 #'
55 #' List Arvados collections based on filter matching
56 #'
57 #' @name collection_list
58 #' @field uuid UUID of the given collection
59 Arvados$methods(
60
61     collection_list = function(filters = NULL, limit = NULL, offset = NULL) 
62     {
63         #Todo(Fudo): Implement limit and offset
64         collection_relative_url <- "collections"
65         http_request <- HttpRequest("GET", token, host, collection_relative_url, filters) 
66         server_response <- http_request$execute()
67
68         httpParser <- HttpParser()
69         collection <- httpParser$parseCollectionGet(server_response)
70         class(collection) <- "ArvadosCollectionList"
71
72         return(collection)
73     }
74 )