BodyPattern {webmockr} | R Documentation |
BodyPattern
Description
body matcher
Public fields
pattern
a list
Methods
Public methods
Method new()
Create a new BodyPattern
object
Usage
BodyPattern$new(pattern)
Arguments
pattern
(list) a body object
Returns
A new BodyPattern
object
Method matches()
Match a request body pattern against a pattern
Usage
BodyPattern$matches(body, content_type = "")
Arguments
body
(list) the body
content_type
(character) content type
Returns
a boolean
Method to_s()
Print pattern for easy human consumption
Usage
BodyPattern$to_s()
Returns
a string
Method clone()
The objects of this class are cloneable with this method.
Usage
BodyPattern$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
# make a request signature
bb <- RequestSignature$new(
method = "get",
uri = "https:/httpbin.org/get",
options = list(
body = list(foo = "bar", a = 5)
)
)
# make body pattern object
## FALSE
z <- BodyPattern$new(pattern = list(foo = "bar"))
z$pattern
z$matches(bb$body)
## TRUE
z <- BodyPattern$new(pattern = list(foo = "bar", a = 5))
z$pattern
z$matches(bb$body)
# uploads in bodies
## upload NOT in a list
bb <- RequestSignature$new(
method = "post", uri = "https:/httpbin.org/post",
options = list(body = crul::upload(system.file("CITATION"))))
bb$body
z <- BodyPattern$new(pattern =
crul::upload(system.file("CITATION")))
z$pattern
z$matches(bb$body)
## upload in a list
bb <- RequestSignature$new(
method = "post", uri = "https:/httpbin.org/post",
options = list(body = list(y = crul::upload(system.file("CITATION")))))
bb$body
z <- BodyPattern$new(pattern =
list(y = crul::upload(system.file("CITATION"))))
z$pattern
z$matches(bb$body)
[Package webmockr version 1.0.0 Index]