File: CRUDProtocol-class.R

package info (click to toggle)
r-cran-restfulr 0.0.15-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 200 kB
  • sloc: ansic: 67; sh: 13; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 982 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
### =========================================================================
### CRUDProtocol objects
### -------------------------------------------------------------------------

### Implements a specific REST protocol (like HTTP).

.CRUDProtocol <- setRefClass("CRUDProtocol")

.CRUDProtocol$methods(create = function(x, ..., value) {
  unimplemented("create")
})

unimplemented <- function(x) {
  stop("This protocol does not implement the '", x, "' operation")
}

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Constructor
###

### FIXME: may be incomplete
availableCRUDProtocols <- function() {
  names(getClass("CRUDProtocol")@subclasses)
}

CRUDProtocol <- function(uri, ...) {
  if (!isSingleString(uri)) {
    stop("'uri' must be a single, non-NA string")
  }
  protocol <- toupper(parseURI(uri)$scheme)
  if (!protocol %in% availableCRUDProtocols()) {
    stop("Unsupported CRUD protocol: ", protocol)
  }
  match.fun(protocol)(...)
}