-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to get users workspaces
- Loading branch information
1 parent
03dca36
commit 14ec9bc
Showing
6 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
|
||
}) | ||
|
||
}) |