R/CRUDProtocol-class.R

Defines functions CRUDProtocol availableCRUDProtocols unimplemented

### =========================================================================
### 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)(...)
}

Try the restfulr package in your browser

Any scripts or data that you put into this service are public.

restfulr documentation built on June 16, 2022, 5:10 p.m.