Merge branch 'master' of git.curoverse.com:arvados into 11876-r-sdk
[arvados.git] / sdk / R / R / HttpParser.R
1 #' HttpParser
2 #'
3 HttpParser <- setRefClass(
4
5     "HttrParser",
6
7     fields = list(
8     ),
9
10     methods = list(
11         initialize = function() 
12         {
13         },
14
15         parseCollectionGet = function(server_response) 
16         {
17             parsed_response <- httr::content(server_response, as = "parsed", type = "application/json")
18
19             #Todo(Fudo): Create new Collection object and populate it
20         },
21
22         parseWebDAVResponse = function(response, uri)
23         {
24             #Todo(Fudo): Move this to HttpParser.
25             text <- rawToChar(response$content)
26             doc <- XML::xmlParse(text, asText=TRUE)
27
28             # calculate relative paths
29             base <- paste(paste("/", strsplit(uri, "/")[[1]][-1:-3], sep="", collapse=""), "/", sep="")
30             result <- unlist(
31                 XML::xpathApply(doc, "//D:response/D:href", function(node) {
32                     sub(base, "", URLdecode(xmlValue(node)), fixed=TRUE)
33                 })
34             )
35             result[result != ""]
36         }
37
38     )
39 )