Fixed some bugs and improved error handling.
[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         parseWebDAVResponse = function(response, uri)
18         {
19             text <- rawToChar(response$content)
20             doc <- XML::xmlParse(text, asText=TRUE)
21             base <- paste(paste("/", strsplit(uri, "/")[[1]][-1:-3], sep="", collapse=""), "/", sep="")
22             result <- unlist(
23                 XML::xpathApply(doc, "//D:response/D:href", function(node) {
24                     sub(base, "", URLdecode(XML::xmlValue(node)), fixed=TRUE)
25                 })
26             )
27             result <- result[result != ""]
28             result
29         },
30
31         extractFileSizeFromWebDAVResponse = function(response, uri)    
32         {
33             text <- rawToChar(response$content)
34             doc <- XML::xmlParse(text, asText=TRUE)
35
36             base <- paste(paste("/", strsplit(uri, "/")[[1]][-1:-3], sep="", collapse=""), "/", sep="")
37             result <- XML::xpathApply(doc, "//D:response/D:propstat/D:prop/D:getcontentlength", function(node) {
38               XML::xmlValue(node)
39             })
40
41             unlist(result)
42         }
43     )
44 )