From 5a9268d64a7b874f73bff200b75eefcae6ac7bdc Mon Sep 17 00:00:00 2001 From: Toph Allen Date: Wed, 8 Oct 2025 15:52:26 -0400 Subject: [PATCH 1/5] adjust parameters for search_content --- R/content.R | 25 +++++++++++++++---------- man/search_content.Rd | 21 ++++++++++++++++----- tests/testthat/test-content.R | 21 ++++++++++++++++----- 3 files changed, 47 insertions(+), 20 deletions(-) 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..5108c9ec 100644 --- a/tests/testthat/test-content.R +++ b/tests/testthat/test-content.R @@ -496,17 +496,28 @@ with_mock_dir("2025.09.0", { ) }) - test_that("content search passes all parameters through correctly", { + test_that("content search respects explicit page_size parameter", { + # This test also confirms the behavior that page_number is passed down via + # ..., even though this isn't behavior we *require*. without_internet( expect_GET( search_content( client, q = "bream", - page_number = 2, - page_size = 20, - include = "owner" + page_size = 100, + include = "owner", + page_number = 2 ), - "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=2&page_size=100&include=owner" + ) + ) + }) + + 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" ) ) }) From e8e8fd6d5ce28435676a437b014c0a9b7c5046a2 Mon Sep 17 00:00:00 2001 From: Toph Allen Date: Wed, 8 Oct 2025 15:58:45 -0400 Subject: [PATCH 2/5] add test of future param --- tests/testthat/test-content.R | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/testthat/test-content.R b/tests/testthat/test-content.R index 5108c9ec..0085951d 100644 --- a/tests/testthat/test-content.R +++ b/tests/testthat/test-content.R @@ -522,6 +522,20 @@ with_mock_dir("2025.09.0", { ) }) + test_that("content search passes arbitrary parameters through ... to query + string", { + without_internet( + expect_GET( + search_content( + client, + q = "bream", + future_param = "value" + ), + "https://connect.example/__api__/v1/search/content?q=bream&page_number=1&page_size=500&include=owner%2Cvanity_url&future_param=value" + ) + ) + }) + test_that("the inner .search_content() func calls the endpoint correctly", { without_internet( expect_GET( From b8d19e4ec9129b1d493653ffe12acccdfabbe1da Mon Sep 17 00:00:00 2001 From: Toph Allen Date: Wed, 8 Oct 2025 16:29:34 -0400 Subject: [PATCH 3/5] nolint long lines --- tests/testthat/test-content.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-content.R b/tests/testthat/test-content.R index 0085951d..e96369b7 100644 --- a/tests/testthat/test-content.R +++ b/tests/testthat/test-content.R @@ -508,7 +508,7 @@ with_mock_dir("2025.09.0", { include = "owner", page_number = 2 ), - "https://connect.example/__api__/v1/search/content?q=bream&page_number=2&page_size=100&include=owner" + "https://connect.example/__api__/v1/search/content?q=bream&page_number=2&page_size=100&include=owner" #nolint ) ) }) @@ -517,7 +517,7 @@ with_mock_dir("2025.09.0", { 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" + "https://connect.example/__api__/v1/search/content?q=bream&page_number=1&page_size=500&include=owner%2Cvanity_url" #nolint ) ) }) @@ -531,7 +531,7 @@ with_mock_dir("2025.09.0", { q = "bream", future_param = "value" ), - "https://connect.example/__api__/v1/search/content?q=bream&page_number=1&page_size=500&include=owner%2Cvanity_url&future_param=value" + "https://connect.example/__api__/v1/search/content?q=bream&page_number=1&page_size=500&include=owner%2Cvanity_url&future_param=value" #nolint ) ) }) From b34a09351b226667095692b627ac23b4f37c07e3 Mon Sep 17 00:00:00 2001 From: Toph Allen Date: Thu, 9 Oct 2025 13:41:25 -0400 Subject: [PATCH 4/5] fix linting --- tests/testthat/test-content.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/testthat/test-content.R b/tests/testthat/test-content.R index e96369b7..a44d741d 100644 --- a/tests/testthat/test-content.R +++ b/tests/testthat/test-content.R @@ -522,8 +522,7 @@ with_mock_dir("2025.09.0", { ) }) - test_that("content search passes arbitrary parameters through ... to query - string", { + test_that("content search passes arbitrary parameters through ... to query string", { without_internet( expect_GET( search_content( From fd385de72506d3a0f998b2a2d12dc2e5c7091878 Mon Sep 17 00:00:00 2001 From: Toph Allen Date: Thu, 9 Oct 2025 13:46:32 -0400 Subject: [PATCH 5/5] remove unnecessary test --- tests/testthat/test-content.R | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tests/testthat/test-content.R b/tests/testthat/test-content.R index a44d741d..aa1a57c0 100644 --- a/tests/testthat/test-content.R +++ b/tests/testthat/test-content.R @@ -496,23 +496,6 @@ with_mock_dir("2025.09.0", { ) }) - test_that("content search respects explicit page_size parameter", { - # This test also confirms the behavior that page_number is passed down via - # ..., even though this isn't behavior we *require*. - without_internet( - expect_GET( - search_content( - client, - q = "bream", - page_size = 100, - include = "owner", - page_number = 2 - ), - "https://connect.example/__api__/v1/search/content?q=bream&page_number=2&page_size=100&include=owner" #nolint - ) - ) - }) - test_that("content search uses default page_size of 500 and page_number of 1", { without_internet( expect_GET(