body matcher
Methods
Method matches()
Match a request body pattern against a pattern
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
#> $foo
#> [1] "bar"
#>
z$matches(bb$body)
#> [1] FALSE
## TRUE
z <- BodyPattern$new(pattern = list(foo = "bar", a = 5))
z$pattern
#> $foo
#> [1] "bar"
#>
#> $a
#> [1] 5
#>
z$matches(bb$body)
#> [1] TRUE
# 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
#> Form file: CITATION (type: text/plain)
z <- BodyPattern$new(pattern =
crul::upload(system.file("CITATION")))
z$pattern
#> $path
#> [1] "/usr/lib/R/library/base/CITATION"
#>
#> $type
#> [1] "text/plain"
#>
#> $name
#> NULL
#>
z$matches(bb$body)
#> [1] TRUE
## 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
#> $y
#> Form file: CITATION (type: text/plain)
#>
z <- BodyPattern$new(pattern =
list(y = crul::upload(system.file("CITATION"))))
z$pattern
#> $y
#> Form file: CITATION (type: text/plain)
#>
z$matches(bb$body)
#> [1] TRUE