Skip to content

Commit

Permalink
feat: download datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomeriko96 committed Jan 12, 2024
1 parent e57c89e commit 42a47ce
Show file tree
Hide file tree
Showing 41 changed files with 275 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(authenticate_server)
export(check_dashboard_names)
export(create_group)
export(delete_group)
export(download_datasource)
export(download_filtered_tableau_image)
export(download_tableau_crosstab_excel)
export(download_tableau_data)
Expand All @@ -22,6 +23,7 @@ export(get_actions)
export(get_folders)
export(get_groups_for_user)
export(get_hierarchy)
export(get_mobile_security_settings)
export(get_nodenames)
export(get_parameter)
export(get_revision)
Expand Down
39 changes: 39 additions & 0 deletions R/download_datasource.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' Download a data source in .tdsx format using Tableau REST API and save it as a file.
#'
#' Downloads a data source in .tdsx format and saves it as a file on your computer.
#'
#' @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.16).
#' @param datasource_id The ID of the data source to download.
#' @param file_path The path to save the downloaded data source.
#' @param include_extract Logical indicating whether to include the extract when downloading the data source (default: TRUE).
#' @return A binary vector containing the data source in .tdsx format.
#' @export
#' @family Tableau REST API
download_datasource <- function(tableau, api_version = 3.16, datasource_id, file_path, include_extract = TRUE) {
base_url <- tableau$base_url
token <- tableau$token
site_id <- tableau$site_id

url <- paste0(
base_url,
"api/",
api_version,
"/sites/",
site_id,
"/datasources/",
datasource_id,
"/content"
)

if (!include_extract) {
url <- paste0(url, "?includeExtract=False")
}

api_response <- httr::GET(
url,
httr::add_headers("X-Tableau-Auth" = token),
httr::write_disk(paste0(file_path, "data.tdsx"), overwrite = TRUE)
)

}
31 changes: 31 additions & 0 deletions R/get_mobile_security_settings.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' Get mobile security settings for the server using Tableau REST API.
#'
#' Retrieves the mobile security settings for the Tableau Server.
#'
#' @param tableau A list containing the Tableau authentication variables: `base_url`, `token`, `user_id`.
#' @param api_version The API version to use (default: 3.19).
#' @return A list containing the mobile security settings for the server.
#' @export
#' @family Tableau REST API
get_mobile_security_settings <- function(tableau, api_version = 3.19) {
base_url <- tableau$base_url
token <- tableau$token

url <- paste0(
base_url,
"api/",
api_version,
"/settings/mobilesecuritysettings"
)

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

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

settings <- jsonlite::fromJSON(jsonResponseText)

return(settings)
}
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
- [ ] Add Tags to Data Source
- [ ] Delete Data Source
- [ ] Delete Tag from Data Source
- [ ] Download Data Source
- [x] Download Data Source
- [ ] Download Data Source Revision
- [ ] Get Data Source Revisions
- [ ] Publish Data Source
Expand Down Expand Up @@ -210,7 +210,7 @@
- [ ] Get Metric Data
- [ ] List Metrics for Site
- [ ] Update Metric
- [ ] Get Mobile Security Settings for Server
- [x] Get Mobile Security Settings for Server
- [ ] Get Mobile Security Settings for Site
- [ ] Update Mobile Security Settings for Site
- [ ] Add User to Data-Driven Alert
Expand Down
9 changes: 5 additions & 4 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ reference:
- title: Data Sources Methods
desc: Data sources methods for Tableau REST API.
contents:
- download_datasource
- download_tableau_data
- get_server_datasources

Expand Down Expand Up @@ -77,10 +78,10 @@ reference:
# contents:
# - None

# - title: Mobile Settings Methods
# desc: Mobile settings methods for Tableau REST API.
# contents:
# - None
- title: Mobile Settings Methods
desc: Mobile settings methods for Tableau REST API.
contents:
- get_mobile_security_settings

# - title: Notifications Methods
# desc: Notifications methods for Tableau REST API.
Expand Down
2 changes: 2 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.

2 changes: 2 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.

2 changes: 2 additions & 0 deletions man/add_user_to_group.Rd

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

2 changes: 2 additions & 0 deletions man/add_user_to_site.Rd

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

2 changes: 2 additions & 0 deletions man/authenticate_PAT.Rd

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

2 changes: 2 additions & 0 deletions man/authenticate_server.Rd

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

2 changes: 2 additions & 0 deletions man/create_group.Rd

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

2 changes: 2 additions & 0 deletions man/delete_group.Rd

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

70 changes: 70 additions & 0 deletions man/download_datasource.Rd

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

2 changes: 2 additions & 0 deletions man/download_filtered_tableau_image.Rd

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

2 changes: 2 additions & 0 deletions man/download_tableau_crosstab_excel.Rd

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

2 changes: 2 additions & 0 deletions man/download_tableau_data.Rd

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

2 changes: 2 additions & 0 deletions man/download_workbooks_server.Rd

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

Loading

0 comments on commit 42a47ce

Please sign in to comment.