Merge branch 'master' of git.curoverse.com:arvados into 11876-r-sdk
[arvados.git] / sdk / R / R / HttpParser.R
1 #' HttpParser
2 #'
3 HttpParser <- R6::R6Class(
4
5     "HttrParser",
6
7     public = list(
8         initialize = function() 
9         {
10         },
11
12         parseJSONResponse = function(serverResponse) 
13         {
14             parsed_response <- httr::content(serverResponse, as = "parsed", type = "application/json")
15         },
16
17         #Todo(Fudo): Test this.
18         parseWebDAVResponse = function(response, uri)
19         {
20             text <- rawToChar(response$content)
21             doc <- XML::xmlParse(text, asText=TRUE)
22
23             # calculate relative paths
24             base <- paste(paste("/", strsplit(uri, "/")[[1]][-1:-3], sep="", collapse=""), "/", sep="")
25             result <- XML::xpathApply(doc, "//D:response", function(node) {
26                 result = list()
27                 children = XML::xmlChildren(node)
28
29                 result$name = sub(base, "", URLdecode(XML::xmlValue(children$href)), fixed=TRUE)
30                 sizeXMLNode = XML::xmlChildren(XML::xmlChildren(children$propstat)$prop)$getcontentlength
31                 result$fileSize = as.numeric(XML::xmlValue(sizeXMLNode))
32
33                 result
34             })
35
36             result
37         }
38     )
39 )