Skip to content

Commit

Permalink
feat: add tags to workbooks and views
Browse files Browse the repository at this point in the history
  • Loading branch information
tin900 committed Nov 2, 2023
1 parent 907e24a commit 776f524
Show file tree
Hide file tree
Showing 27 changed files with 359 additions and 23 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(add_tags_to_view)
export(add_tags_to_workbook)
export(adjust_tableau_font_style)
export(adjust_tableau_size)
export(authenticate_server)
Expand Down Expand Up @@ -30,6 +32,7 @@ export(get_server_user_favorites)
export(get_server_users)
export(get_server_views)
export(get_server_workbooks)
export(get_table_assets)
export(get_tableau_data_source)
export(get_variable_folders)
export(get_variables)
Expand Down
50 changes: 50 additions & 0 deletions R/add_tags_to_view.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#' Add tags to a view in Tableau Server.
#'
#' Adds one or more tags to the specified view in the Tableau Server using the provided authentication credentials.
#'
#' @param tableau A list containing the Tableau authentication variables: `base_url`, `token`, `user_id`, and `site_id`.
#' @param api_version The API version to use (default: 3.8).
#' @param view_id The ID of the view to add tags to.
#' @param tags A vector of tags to add to the view.
#'
#' @return The response from the API.
#' @export
#'
#' @family Tableau REST API
add_tags_to_view <- function(tableau, api_version = 3.8, view_id, tags) {
base_url <- tableau$base_url
token <- tableau$token
site_id <- tableau$site_id

url <- paste0(
base_url,
"api/",
api_version,
"/sites/",
site_id,
"/views/",
view_id,
"/tags"
)

# Construct the request body
request_body <- paste0(
"<tsRequest>",
"<tags>",
paste0(
"<tag label=\"", tags, "\" />",
collapse = ""
),
"</tags>",
"</tsRequest>"
)

api_response <- httr::PUT(
url,
httr::add_headers("X-Tableau-Auth" = token),
body = request_body,
encode = "xml"
)

return(api_response)
}
50 changes: 50 additions & 0 deletions R/add_tags_to_workbook.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#' Add tags to a workbook in Tableau Server.
#'
#' Adds one or more tags to the specified workbook in the Tableau Server using the provided authentication credentials.
#'
#' @param tableau A list containing the Tableau authentication variables: `base_url`, `token`, `user_id`, and `site_id`.
#' @param api_version The API version to use (default: 3.8).
#' @param workbook_id The ID of the workbook to add tags to.
#' @param tags A vector of tags to add to the workbook.
#'
#' @return The response from the API.
#' @export
#'
#' @family Tableau REST API
add_tags_to_workbook <- function(tableau, api_version = 3.8, workbook_id, tags) {
base_url <- tableau$base_url
token <- tableau$token
site_id <- tableau$site_id

url <- paste0(
base_url,
"api/",
api_version,
"/sites/",
site_id,
"/workbooks/",
workbook_id,
"/tags"
)

# Construct the request body
request_body <- paste0(
"<tsRequest>",
"<tags>",
paste0(
"<tag label=\"", tags, "\" />",
collapse = ""
),
"</tags>",
"</tsRequest>"
)

api_response <- httr::PUT(
url,
httr::add_headers("X-Tableau-Auth" = token),
body = request_body,
encode = "xml"
)

return(api_response)
}
36 changes: 36 additions & 0 deletions R/get_table_assets.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#' Get table assets from Tableau Server.
#'
#' Retrieves information about all table assets for a site from the Tableau Server using the provided authentication credentials.
#'
#' @param tableau A list containing the Tableau authentication variables: `base_url`, `token`, `user_id`, and `site_id`.
#' @param api_version The API version to use (default: 3.8).
#'
#' @return A data frame containing the table assets information.
#' @export
#'
#' @family Tableau REST API
get_table_assets <- function(tableau, api_version = 3.8) {
base_url <- tableau$base_url
token <- tableau$token
site_id <- tableau$site_id

url <- paste0(
base_url,
"api/",
api_version,
"/sites/",
site_id,
"/tables"
)

api_response <- httr::GET(
url,
httr::add_headers("X-Tableau-Auth" = token)
)

jsonResponseText <- httr::content(api_response, as = "text")

df <- as.data.frame(jsonlite::fromJSON(jsonResponseText), check.names = FALSE)

return(df)
}
8 changes: 4 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- [ ] Import ask data lens
- [ ] List ask data lenses in site
- [ ] Revoke Administrator Personal Access Tokens - Not available for Tableau Cloud.
- [ ] Sign In
- [x] Sign In
- [ ] Sign Out
- [ ] Switch Site - Not available for Tableau Cloud.
- [ ] Create Connected App
Expand Down Expand Up @@ -193,7 +193,7 @@
- [ ] Query Quality Warning Trigger
- [ ] Query Table
- [ ] Query Table Permissions
- [ ] Query Tables
- [x] Query Tables
- [ ] Remove Column - Available only with a Data Management license.
- [ ] Remove Database - Available only with a Data Management license.
- [ ] Remove Table - Available only with a Data Management license.
Expand Down Expand Up @@ -300,8 +300,8 @@
- [ ] List Virtual Connection Database Connections - Available only with a Data Management license.
- [ ] List Virtual Connections - Available only with a Data Management license.
- [ ] Update Virtual Connection Database Connections - Available only with a Data Management license.
- [ ] Add Tags to View
- [ ] Add Tags to Workbook
- [x] Add Tags to View
- [x] Add Tags to Workbook
- [ ] Delete Custom View
- [ ] Delete Tag from View
- [ ] Delete Tag from Workbook
Expand Down
48 changes: 48 additions & 0 deletions man/add_tags_to_view.Rd

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

48 changes: 48 additions & 0 deletions man/add_tags_to_workbook.Rd

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

5 changes: 4 additions & 1 deletion man/authenticate_server.Rd

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

5 changes: 4 additions & 1 deletion man/download_filtered_tableau_image.Rd

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

5 changes: 4 additions & 1 deletion man/download_tableau_crosstab_excel.Rd

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

5 changes: 4 additions & 1 deletion man/download_tableau_data.Rd

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

5 changes: 4 additions & 1 deletion man/download_workbooks_server.Rd

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

5 changes: 4 additions & 1 deletion man/download_workbooks_server_pdf.Rd

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

Loading

0 comments on commit 776f524

Please sign in to comment.