diff --git a/R/content.R b/R/content.R index 4ba1ae6d..cfbedfc8 100644 --- a/R/content.R +++ b/R/content.R @@ -1444,10 +1444,12 @@ get_content_packages <- function(content) { #' @param include Comma-separated character string of values indicating additional #' details to include in the response. Values can be `owner` and `vanity_url`; #' both are included by default. -#' @param ... Extra arguments. Passing in `page_number` and `page_size` will -#' affect the internal pagination for Connect's content search API. Setting -#' `page_number` will change the page at which pagination *starts*, and -#' `page_size` will control the size of pages (max 500). +#' @param page_size The number of items to fetch per page. Maximum is 500. +#' @param limit Maximum number of items to return overall. Defaults to `Inf` (all items). +#' @param ... Additional query parameters passed to the API for future expansion. +#' Note: If you pass `page_number` here, it will affect the *starting* page +#' for pagination, but all subsequent pages will still be fetched. This is +#' usually not what you want. #' #' @return #' A list containing sub-fields: @@ -1585,6 +1587,8 @@ search_content <- function( client, q = NULL, include = "owner,vanity_url", + page_size = 500, + limit = Inf, ... ) { error_if_less_than(client$version, "2024.04.0") @@ -1595,20 +1599,20 @@ search_content <- function( client, q = q, include = include, - # page_size and page_number can be passed in via `...`. Since this call is - # still passed to page_offset, page_number affects the *starting* page, - # but pagination still continues. + page_size = page_size, ... - ) + ), + limit = limit ) } .search_content <- function( client, q, + include, page_number = 1, page_size = 500, - include + ... ) { path <- v1_url("search", "content") @@ -1616,7 +1620,8 @@ search_content <- function( q = q, page_number = page_number, page_size = page_size, - include = include + include = include, + ... ) client$GET(path, query = query) diff --git a/man/search_content.Rd b/man/search_content.Rd index 6f3881b2..ddb16076 100644 --- a/man/search_content.Rd +++ b/man/search_content.Rd @@ -4,7 +4,14 @@ \alias{search_content} \title{Search for content on the Connect server} \usage{ -search_content(client, q = NULL, include = "owner,vanity_url", ...) +search_content( + client, + q = NULL, + include = "owner,vanity_url", + page_size = 500, + limit = Inf, + ... +) } \arguments{ \item{client}{A Connect object} @@ -16,10 +23,14 @@ documentation on \href{https://docs.posit.co/connect/user/viewing-content/#searc details to include in the response. Values can be \code{owner} and \code{vanity_url}; both are included by default.} -\item{...}{Extra arguments. Passing in \code{page_number} and \code{page_size} will -affect the internal pagination for Connect's content search API. Setting -\code{page_number} will change the page at which pagination \emph{starts}, and -\code{page_size} will control the size of pages (max 500).} +\item{page_size}{The number of items to fetch per page. Maximum is 500.} + +\item{limit}{Maximum number of items to return overall. Defaults to \code{Inf} (all items).} + +\item{...}{Additional query parameters passed to the API for future expansion. +Note: If you pass \code{page_number} here, it will affect the \emph{starting} page +for pagination, but all subsequent pages will still be fetched. This is +usually not what you want.} } \value{ A list containing sub-fields: diff --git a/tests/testthat/test-content.R b/tests/testthat/test-content.R index 1197f9b3..aa1a57c0 100644 --- a/tests/testthat/test-content.R +++ b/tests/testthat/test-content.R @@ -496,17 +496,24 @@ with_mock_dir("2025.09.0", { ) }) - test_that("content search passes all parameters through correctly", { + test_that("content search uses default page_size of 500 and page_number of 1", { + without_internet( + expect_GET( + search_content(client, q = "bream"), + "https://connect.example/__api__/v1/search/content?q=bream&page_number=1&page_size=500&include=owner%2Cvanity_url" #nolint + ) + ) + }) + + test_that("content search passes arbitrary parameters through ... to query string", { without_internet( expect_GET( search_content( client, q = "bream", - page_number = 2, - page_size = 20, - include = "owner" + future_param = "value" ), - "https://connect.example/__api__/v1/search/content?q=bream&page_number=2&page_size=20&include=owner" + "https://connect.example/__api__/v1/search/content?q=bream&page_number=1&page_size=500&include=owner%2Cvanity_url&future_param=value" #nolint ) ) })