@@ -114,9 +114,15 @@ RequestPattern <- R6::R6Class(
114114 # ' @param basic_auth (list) vector of length 2 (username, password),
115115 # ' optional
116116 # ' @return A new `RequestPattern` object
117- initialize = function (method , uri = NULL , uri_regex = NULL ,
118- query = NULL , body = NULL , headers = NULL ,
119- basic_auth = NULL ) {
117+ initialize = function (
118+ method ,
119+ uri = NULL ,
120+ uri_regex = NULL ,
121+ query = NULL ,
122+ body = NULL ,
123+ headers = NULL ,
124+ basic_auth = NULL
125+ ) {
120126 if (is.null(uri ) && is.null(uri_regex )) {
121127 abort(" one of uri or uri_regex is required" )
122128 }
@@ -148,31 +154,31 @@ RequestPattern <- R6::R6Class(
148154 if (! is.null(c_type )) c_type <- strsplit(c_type , " ;" )[[1 ]][1 ]
149155 self $ method_pattern $ matches(request_signature $ method ) &&
150156 self $ uri_pattern $ matches(request_signature $ uri ) &&
151- (
152- is.null(self $ body_pattern ) ||
153- self $ body_pattern $ matches(request_signature $ body , c_type %|| % " " )
154- ) &&
155- (
156- is.null(self $ headers_pattern ) ||
157- self $ headers_pattern $ matches(request_signature $ headers )
158- )
157+ (is.null(self $ body_pattern ) ||
158+ self $ body_pattern $ matches(request_signature $ body , c_type %|| % " " )) &&
159+ (is.null(self $ headers_pattern ) ||
160+ self $ headers_pattern $ matches(request_signature $ headers ))
159161 },
160162
161163 # ' @description Print pattern for easy human consumption
162164 # ' @return a string
163165 to_s = function () {
164- gsub(" ^\\ s+|\\ s+$" , " " , paste(
165- toupper(self $ method_pattern $ to_s()),
166- self $ uri_pattern $ to_s(),
167- if (! is.null(self $ body_pattern )) {
168- if (! is.null(self $ body_pattern $ pattern )) {
169- paste0(" with body " , self $ body_pattern $ to_s())
166+ gsub(
167+ " ^\\ s+|\\ s+$" ,
168+ " " ,
169+ paste(
170+ toupper(self $ method_pattern $ to_s()),
171+ self $ uri_pattern $ to_s(),
172+ if (! is.null(self $ body_pattern )) {
173+ if (! is.null(self $ body_pattern $ pattern )) {
174+ paste0(" with body " , self $ body_pattern $ to_s())
175+ }
176+ },
177+ if (! is.null(self $ headers_pattern )) {
178+ paste0(" with headers " , self $ headers_pattern $ to_s())
170179 }
171- },
172- if (! is.null(self $ headers_pattern )) {
173- paste0(" with headers " , self $ headers_pattern $ to_s())
174- }
175- ))
180+ )
181+ )
176182 }
177183 ),
178184 private = list (
@@ -306,7 +312,8 @@ HeadersPattern <- R6::R6Class(
306312 headers <- private $ normalize_headers(headers )
307313 out <- c()
308314 for (i in seq_along(self $ pattern )) {
309- out [i ] <- names(self $ pattern )[i ] %in% names(headers ) &&
315+ out [i ] <- names(self $ pattern )[i ] %in%
316+ names(headers ) &&
310317 self $ pattern [[i ]] == headers [[names(self $ pattern )[i ]]]
311318 }
312319 all(out )
@@ -454,15 +461,16 @@ BodyPattern <- R6::R6Class(
454461 )
455462 } else {
456463 # FIXME: add partial approach later
457- (private $ empty_string(self $ pattern ) && private $ empty_string(body )) || {
458- if (xor(is_na(self $ pattern ), is_na(body ))) {
459- return (FALSE )
460- }
461- if (xor(is_null(self $ pattern ), is_null(body ))) {
462- return (FALSE )
464+ (private $ empty_string(self $ pattern ) && private $ empty_string(body )) ||
465+ {
466+ if (xor(is_na(self $ pattern ), is_na(body ))) {
467+ return (FALSE )
468+ }
469+ if (xor(is_null(self $ pattern ), is_null(body ))) {
470+ return (FALSE )
471+ }
472+ all(self $ pattern == body )
463473 }
464- all(self $ pattern == body )
465- }
466474 }
467475 },
468476
@@ -489,14 +497,14 @@ BodyPattern <- R6::R6Class(
489497 body_char <- rapply(body , as.character , how = " replace" )
490498
491499 if (self $ partial ) {
492- names_values_check <- switch (self $ partial_type ,
500+ names_values_check <- switch (
501+ self $ partial_type ,
493502 # unname() here not needed for R < 4.5, but is needed for R 4.5
494503 # because intersect changes to output unnamed lists
495- include =
496- identical(
497- unname(intersect(pattern_char , body_char )),
498- unname(pattern_char )
499- ),
504+ include = identical(
505+ unname(intersect(pattern_char , body_char )),
506+ unname(pattern_char )
507+ ),
500508 exclude = length(intersect(pattern_char , body_char )) == 0
501509 )
502510 if (! names_values_check ) {
@@ -551,25 +559,30 @@ BodyPattern <- R6::R6Class(
551559)
552560
553561BODY_FORMATS <- list (
554- " text/xml" = " xml" ,
555- " application/xml" = " xml" ,
556- " application/json" = " json" ,
557- " text/json" = " json" ,
558- " application/javascript" = " json" ,
559- " text/javascript" = " json" ,
562+ " text/xml" = " xml" ,
563+ " application/xml" = " xml" ,
564+ " application/json" = " json" ,
565+ " text/json" = " json" ,
566+ " application/javascript" = " json" ,
567+ " text/javascript" = " json" ,
560568 " application/x-amz-json-1.1" = " json" , # AWS
561- " text/html" = " html" ,
562- " application/x-yaml" = " yaml" ,
563- " text/yaml" = " yaml" ,
564- " text/plain" = " plain"
569+ " text/html" = " html" ,
570+ " application/x-yaml" = " yaml" ,
571+ " text/yaml" = " yaml" ,
572+ " text/plain" = " plain"
565573)
566574
567575# remove_reserved & promote_attr from
568576# https://www.garrickadenbuie.com/blog/recursive-xml-workout/
569577remove_reserved <- function (this_attr ) {
570578 reserved_attr <- c(
571- " class" , " comment" , " dim" , " dimnames" ,
572- " names" , " row.names" , " tsp"
579+ " class" ,
580+ " comment" ,
581+ " dim" ,
582+ " dimnames" ,
583+ " names" ,
584+ " row.names" ,
585+ " tsp"
573586 )
574587 if (! any(reserved_attr %in% names(this_attr ))) {
575588 return (this_attr )
@@ -753,7 +766,8 @@ UriPattern <- R6::R6Class(
753766 bools [i ] <- qp %in% uri_qp
754767 }
755768 }
756- out <- switch (self $ partial_type ,
769+ out <- switch (
770+ self $ partial_type ,
757771 include = any(bools ),
758772 exclude = ! any(bools )
759773 )
@@ -790,10 +804,14 @@ UriPattern <- R6::R6Class(
790804 inherits(query_params , " list" ) ||
791805 inherits(query_params , " character" )
792806 ) {
793- pars <- paste0(unname(Map(
794- function (x , y ) paste(x , esc(y ), sep = " =" ),
795- names(query_params ), query_params
796- )), collapse = " &" )
807+ pars <- paste0(
808+ unname(Map(
809+ function (x , y ) paste(x , esc(y ), sep = " =" ),
810+ names(query_params ),
811+ query_params
812+ )),
813+ collapse = " &"
814+ )
797815 self $ pattern <- paste0(self $ pattern , " ?" , pars )
798816 }
799817 }
@@ -856,7 +874,8 @@ parse_a_url <- function(url) {
856874 if (! is.na(tmp $ parameter )) {
857875 tmp $ parameter <- unlist(
858876 lapply(
859- strsplit(tmp $ parameter , " &" )[[1 ]], function (x ) {
877+ strsplit(tmp $ parameter , " &" )[[1 ]],
878+ function (x ) {
860879 z <- strsplit(x , split = " =" )[[1 ]]
861880 as.list(stats :: setNames(z [2 ], z [1 ]))
862881 }
0 commit comments