Skip to content

Commit

Permalink
Add function to get users workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-hannah committed May 9, 2024
1 parent 03dca36 commit 14ec9bc
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(asset_info)
export(create_folder)
export(download_file)
export(my_user_id)
export(my_workspaces)
export(new_document)
export(new_document_version)
export(objectiveR)
Expand Down
44 changes: 44 additions & 0 deletions R/my_workspaces.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#' Get workspaces the current user is a member of
#'
#' @param workgroup_uuid UUID of workgroup to filter by
#' @param page Page number of responses to return (0..N).
#' @param size Number of results to be returned per page.
#' @inheritParams objectiveR
#'
#' @return Data frame
#'
#' @export

my_workspaces <- function(workgroup_uuid = NULL,
page = NULL,
size = NULL,
use_proxy = FALSE) {

response <- objectiveR(
endpoint = "myworkspaces",
url_query = list(workgroupUuid = workgroup_uuid,
page = page,
size = size)
)

content <-
httr2::resp_body_json(response)$content |>
lapply(
\(content) {
data.frame(
workspace_name = content$name,
workspace_uuid = content$uuid,
participant_uuid = content$participant$uuid,
owner_name = paste(content$owner$givenName,
content$owner$familyName),
owner_email = content$owner$email,
owner_uuid = content$owner$uuid,
workgroup_name = content$workgroup$name,
workgroup_uuid = content$workgroup$uuid
)
}
)

Reduce(dplyr::bind_rows, content)

}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ reference:
Workspaces are the containers that connect a collection of documents and
folders (Assets) with a collection of Users (Participants)
contents:
- my_workspaces
- participants

- subtitle: Assets
Expand Down
28 changes: 28 additions & 0 deletions man/my_workspaces.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/testthat/api/myworkspaces-0ccf8b.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
structure(list(method = "GET", url = "https://api/myworkspaces?workgroupUuid=df05-8377-f703-4ce8-a163-9104-2bc6-64e5",
status_code = 200L, headers = structure(list(Date = "Thu, 09 May 2024 15:49:51 GMT",
`Content-Type` = "application/json", `Transfer-Encoding` = "chunked",
Connection = "keep-alive", `X-CONNECT-MDC` = "apipGcxcEvR",
`X-Frame-Options` = "deny", `X-XSS-Protection` = "1; mode=block",
`Cache-Control` = "no-cache, no-store", Expires = "0",
Pragma = "no-cache", `Strict-Transport-Security` = "max-age=31536000 ; includeSubDomains",
`Content-Security-Policy` = "script-src 'self' 'unsafe-inline'",
`X-Content-Type-Options` = "nosniff", `Referrer-Policy` = "strict-origin-when-cross-origin",
`Feature-Policy` = "vibrate 'none'; geolocation 'none'",
Authorization = "REDACTED", `Set-Cookie` = "REDACTED"), class = "httr2_headers"),
body = charToRaw("{\"content\":[{\"uuid\":\"test_workspace_uuid\",\"name\":\"test_workspace_name\",\"participant\":{\"uuid\":\"test_participant_uuid\"},\"owner\":{\"uuid\":\"test_owner_uuid\",\"email\":\"test_owner_email\",\"givenName\":\"test_owner_name\",\"familyName\":\"test_owener_surname\"},\"workgroup\":{\"uuid\":\"test_workgroup_uuid\",\"name\":\"test_workgroup_name\"}}]}"),
cache = new.env(parent = emptyenv())), class = "httr2_response")
48 changes: 48 additions & 0 deletions tests/testthat/test-my_workspaces.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

without_internet({

test_that("Valid request created", {

expect_GET(
my_workspaces(),
"https://secure.objectiveconnect.co.uk/publicapi/1/myworkspaces"
)

expect_GET(
my_workspaces(workgroup_uuid = "test_workgroup"),
paste0("https://secure.objectiveconnect.co.uk/publicapi/1/myworkspaces?",
"workgroupUuid=test_workgroup")
)

})

})

with_mock_api({

with_envvar(

new = c("OBJECTIVER_USR" = "test_usr",
"OBJECTIVER_PWD" = "test_pwd"),

code = {

test_that("Function returns dataframe", {

expect_s3_class(
my_workspaces(workgroup_uuid = "test_workgroup_uuid"),
"data.frame"
)

})

expect_equal(
unique(
my_workspaces(workgroup_uuid = "test_workgroup_uuid")$workgroup_uuid
),
"test_workgroup_uuid"
)

})

})

0 comments on commit 14ec9bc

Please sign in to comment.