File: Credentials-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 (53 lines) | stat: -rw-r--r-- 1,770 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
### =========================================================================
### Credentials objects
### -------------------------------------------------------------------------

setClass("Credentials",
         representation(username = "character_OR_NULL",
                        password = "character_OR_NULL"),
         validity = function(object) {
             c(if (!is.null(object@username) &&
                   !isSingleString(object@username))
                   "username must be NULL or a single string",
               if (!is.null(object@password) &&
                   !isSingleString(object@password))
                   "password must be NULL or a single string")
         })

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Accessors
###

setGeneric("username", function(x) standardGeneric("username"))
setMethod("username", "Credentials", function(x) x@username)

setGeneric("password", function(x) standardGeneric("password"))
setMethod("password", "Credentials", function(x) x@password)

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

Credentials <- function(username, password) {
    new("Credentials", username=username, password=password)
}

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Coerce
###

as.list.Credentials <- function(x) {
    as.list(x)
}

setMethod("as.list", "Credentials", function(x)
    list(username=username(x), password=password(x)))

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Show
###

setMethod("show", "Credentials", function(object) {
              cat("A", class(object), "object\n")
              cat("username:", username(object), "\n")
          })