Skip to content

Commit e8c8075

Browse files
authored
feat: include vanity urls in get_content (#399)
1 parent 2cea9c0 commit e8c8075

File tree

8 files changed

+113
-6
lines changed

8 files changed

+113
-6
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# connectapi (development version)
22

3+
34
## Enhancements and fixes
45

56
- `get_groups()` now paginates through all results when a `prefix` is provided,
67
if the Connect server API version supports pagination. (#328)
78
- Timestamps from the Connect server are now displayed in your local time zone,
89
rather than in UTC. (#400)
10+
- `get_content()` now includes vanity URLs in the returned data frame on Connect
11+
v2024.06.0 and later. (#398)
912

1013
# connectapi 0.7.0
1114

R/get.R

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ get_users <- function(
174174
#' Applies only to executable content types - not static.
175175
#' * `owner_guid`: The unique identifier for the owner
176176
#' * `content_url`: The URL associated with this content. Computed
177-
#' from the associated vanity URL or GUID for this content.
177+
#' from the GUID for this content.
178178
#' * `dashboard_url`: The URL within the Connect dashboard where
179179
#' this content can be configured. Computed from the GUID for this content.
180180
#' * `role`: The relationship of the accessing user to this
@@ -183,7 +183,24 @@ get_users <- function(
183183
#' permitted to view the content. A none role is returned for
184184
#' administrators who cannot view the content but are permitted to view
185185
#' its configuration. Computed at the time of the request.
186-
#' * `id`: The internal numeric identifier of this content item
186+
#' * `vanity_url`: The vanity URL associated with this content item.
187+
#' * `id`: The internal numeric identifier of this content item.
188+
#' * `tags`: Tags associated with this content item. Each entry is a list
189+
#' with the following fields:
190+
#' * `id`: The identifier for the tag.
191+
#' * `name`: The name of the tag.
192+
#' * `parent_id`: The identifier for the parent tag. Null if the tag is a
193+
#' top-level tag.
194+
#' * `created_time`: The timestamp (RFC3339) indicating when the tag was
195+
#' created.
196+
#' * `updated_time`: The timestamp (RFC3339) indicating when the tag was
197+
#' last updated.
198+
#' * `owner`: Basic details about the owner of this content item. Each entry
199+
#' is a list with the following fields:
200+
#' * `guid`: The user's GUID, or unique identifier, in UUID RFC4122 format.
201+
#' * `username`: The user's username.
202+
#' * `first_name`: The user's first name.
203+
#' * `last_name`: The user's last name.
187204
#'
188205
#' @details
189206
#' Please see https://docs.posit.co/connect/api/#get-/v1/content for more
@@ -208,7 +225,24 @@ get_content <- function(
208225
) {
209226
validate_R6_class(src, "Connect")
210227

211-
res <- src$content(guid = guid, owner_guid = owner_guid, name = name)
228+
# The capability to return vanity URLs `vanity_url` was added in Connect
229+
# v2024.06.0.
230+
if (compare_connect_version(src$version, "2024.06.0") < 0) {
231+
include <- "tags,owner"
232+
content_ptype <- connectapi_ptypes$content[,
233+
names(connectapi_ptypes$content) != "vanity_url"
234+
]
235+
} else {
236+
include <- "tags,owner,vanity_url"
237+
content_ptype <- connectapi_ptypes$content
238+
}
239+
240+
res <- src$content(
241+
guid = guid,
242+
owner_guid = owner_guid,
243+
name = name,
244+
include = include
245+
)
212246

213247
if (!is.null(guid)) {
214248
# convert a single item to a list
@@ -219,7 +253,7 @@ get_content <- function(
219253
res <- res %>% purrr::keep(.p = .p)
220254
}
221255

222-
out <- parse_connectapi_typed(res, connectapi_ptypes$content)
256+
out <- parse_connectapi_typed(res, content_ptype)
223257

224258
return(out)
225259
}

R/ptype.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ connectapi_ptypes <- list(
6969
"content_url" = NA_character_,
7070
"dashboard_url" = NA_character_,
7171
"app_role" = NA_character_,
72+
"vanity_url" = NA_character_,
7273
"id" = NA_character_,
7374
"owner" = NA_list_,
75+
"tags" = NA_list_,
7476
),
7577
content_old = tibble::tibble(
7678
"id" = NA_integer_,

man/get_content.Rd

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "2024.05.0"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "2024.06.0"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "2024.07.0"
3+
}

tests/testthat/test-get.R

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,41 @@ test_that("get_packages() works as expected with `content_guid` names in API res
327327
)
328328
)
329329
})
330+
331+
test_that("get_content only requests vanity URLs for Connect 2024.06.0 and up", {
332+
with_mock_dir("2024.05.0", {
333+
client <- Connect$new(server = "http://connect.example", api_key = "not-a-key")
334+
# `$version` is lazy, so we need to call it before `without_internet()`.
335+
client$version
336+
})
337+
without_internet({
338+
expect_GET(
339+
get_content(client),
340+
"http://connect.example/__api__/v1/content?include=tags%2Cowner"
341+
)
342+
})
343+
344+
with_mock_dir("2024.06.0", {
345+
client <- Connect$new(server = "http://connect.example", api_key = "not-a-key")
346+
# `$version` is lazy, so we need to call it before `without_internet()`.
347+
client$version
348+
})
349+
without_internet({
350+
expect_GET(
351+
get_content(client),
352+
"http://connect.example/__api__/v1/content?include=tags%2Cowner"
353+
)
354+
})
355+
356+
with_mock_dir("2024.07.0", {
357+
client <- Connect$new(server = "http://connect.example", api_key = "not-a-key")
358+
# `$version` is lazy, so we need to call it before `without_internet()`.
359+
client$version
360+
})
361+
without_internet({
362+
expect_GET(
363+
get_content(client),
364+
"http://connect.example/__api__/v1/content?include=tags%2Cowner%2Cvanity_url"
365+
)
366+
})
367+
})

0 commit comments

Comments
 (0)