Skip to content

Commit

Permalink
Merge pull request #20 from ThinkR-open/19-endpoint-with-path
Browse files Browse the repository at this point in the history
fix: add_endpoint can now take x/y/z
  • Loading branch information
ColinFay authored Dec 10, 2024
2 parents 585b891 + 0bc26bf commit 4ead370
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mariobox
Title: A Framework For Packaging {plumber} APIs
Version: 0.0.1.9001
Version: 0.0.1.9002
Authors@R: c(
person("Antoine", "Languillaume", , "[email protected]", role = "aut"),
person("Colin", "Fay", , "[email protected]", role = c("aut", "cre"))
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# mariobox (development version)

* fix: add_endpoint can now take path of the form x/y/z.

* First version
28 changes: 16 additions & 12 deletions R/manage_endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ add_endpoint <- function(
open = TRUE,
pkg = "."
) {
clean_name <- gsub(
"/",
"_",
name
)

name_yaml <- sprintf(
"%s_%s",
name,
clean_name,
tolower(method)
)

Expand All @@ -66,7 +72,7 @@ add_endpoint <- function(
fct_name <- sprintf(
"%s_%s",
tolower(method),
name
clean_name
)

if (is.null(yml$handles[[name_yaml]])) {
Expand All @@ -90,7 +96,6 @@ add_endpoint <- function(
mariobox_yaml_path
)


usethis_use_r(
name = fct_name,
open = open,
Expand All @@ -110,19 +115,19 @@ add_endpoint <- function(
sprintf(
"#' %s %s",
method,
name
clean_name
)
)

write_there("#' ")
write_there("#' @param req,res HTTP objects")
write_there("#' ")
write_there("#' @export")
write_there("#' ")
write_there(
sprintf(
"%s_%s <- function(req, res){",
tolower(method),
name
"%s <- function(req, res){",
fct_name
)
)
write_there(
Expand Down Expand Up @@ -154,17 +159,16 @@ add_endpoint <- function(
sprintf(
"#' %s %s internal",
method,
name
fct_name
)
)
write_there("#' ")
write_there("#' @noRd")
write_there("#' ")
write_there(
sprintf(
"%s_%s_f <- function(){",
tolower(method),
name
"%s_f <- function(){",
fct_name
)
)
write_there(" return('ok')")
Expand All @@ -175,8 +179,8 @@ add_endpoint <- function(
open = open,
pkg = pkg
)

cat_green_tick("Endpoint added")

}

#' @name manage_endpoints
Expand Down

0 comments on commit 4ead370

Please sign in to comment.