Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix so arguments are passed to get_multiple_ga_metrics #80

Merged
merged 7 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ resources/*
inst/extdata/docker/*
^CRAN-SUBMISSION$
^cran-comments.md$
^privacypolicy.md$
^privacypolicy.md$
CODE_OF_CONDUCT.md
LICENSE
^.config/*
^.local/*
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ Suggests:
withr
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
LazyData: true
VignetteBuilder: knitr
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
export("%>%")
export(auth_from_secret)
export(authorize)
export(cache_secrets_folder)
export(calendly_get)
export(clean_ga_metrics)
export(clean_repo_metrics)
Expand Down
2 changes: 1 addition & 1 deletion R/auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ authorize <- function(app_name = NULL,

if (app_name == "github") {
# Open up browser to have them create a key
browseURL("https://github.com/settings/tokens/new?description=metricminer&scopes=repo,read:packages,read:org")
browseURL("https://github.com/settings/tokens/new?description=METRICMINER_GITHUB_PAT&scopes=repo,read:packages,read:org")
message("On the opened page, scroll down and click 'Generate Token'.")

# Store api key here
Expand Down
33 changes: 15 additions & 18 deletions R/github.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ get_github_user <- function(token = NULL) {
#' @description This is a function to get the information about a repository
#' @param token You can provide the Personal Access Token key directly or this function will attempt to grab a PAT that was stored using the `authorize("github")` function
#' @param owner The owner of the repository. So for `https://github.com/fhdsl/metricminer`, it would be `fhdsl`
#' @param count The number of responses that should be returned. Default is 20 or you can say "all" to retrieve all.
#' @param count The number of responses that should be returned. default is 100000
#' @param data_format Default is to return a curated data frame. However if you'd like to see the raw information returned from GitHub set format to "raw".
#' @return a list of repositories that an organization has
#' @importFrom gh gh
Expand All @@ -69,8 +69,7 @@ get_github_user <- function(token = NULL) {
#' get_org_repo_list(owner = "fhdsl")
#' }
#'
get_org_repo_list <- function(owner, count = "all", data_format = "dataframe", token = NULL) {
if (count == "all") count <- "Inf"
get_org_repo_list <- function(owner, count = 100000, data_format = "dataframe", token = NULL) {

if (is.null(token)) {
# Get auth token
Expand Down Expand Up @@ -101,7 +100,7 @@ get_org_repo_list <- function(owner, count = "all", data_format = "dataframe", t
#' @description This is a function to get the information about a repository
#' @param token You can provide the Personal Access Token key directly or this function will attempt to grab a PAT that was stored using the `authorize("github")` function
#' @param owner The owner of the repository. So for `https://github.com/fhdsl/metricminer`, it would be `fhdsl`
#' @param count The number of responses that should be returned. Default is 20 or you can say "all" to retrieve all.
#' @param count The number of responses that should be returned. default is 100000
#' @param data_format Default is to return a curated data frame. However if you'd like to see the raw information returned from GitHub set format to "raw".
#' @return a list of repositories that an organization has
#' @importFrom gh gh
Expand All @@ -112,12 +111,11 @@ get_org_repo_list <- function(owner, count = "all", data_format = "dataframe", t
#' get_user_repo_list(owner = "metricminer")
#' }
#'
get_user_repo_list <- function(owner, count = "all", data_format = "dataframe", token = NULL) {
if (count == "all") count <- "Inf"
get_user_repo_list <- function(owner, count = 100000, data_format = "dataframe", token = NULL) {

if (is.null(token)) {
# Get auth token
token <- get_token(app_name = "github", try = TRUE)
token <- get_token(app_name = "github")
if (is.null(token)) warning("No token found. Only public repositories will be retrieved.")
}

Expand All @@ -144,7 +142,7 @@ get_user_repo_list <- function(owner, count = "all", data_format = "dataframe",
#' @description This is a function to get the information about a repository
#' @param token You can provide the Personal Access Token key directly or this function will attempt to grab a PAT that was stored using the `authorize("github")` function
#' @param repo The repository name. So for `https://github.com/fhdsl/metricminer`, it would be `fhdsl/metricminer`
#' @param count How many items would you like to receive? Put "all" to retrieve all records.
#' @param count How many items would you like to receive? default is 100000
#' @param data_format Default is to return a curated data frame. However if you'd like to see the raw information returned from GitHub set format to "raw".
#' @param time_course Should the time course data be collected or only the summary metrics?
#' @return Repository summary or time course metrics for a particular GitHub repository as a dataframe
Expand All @@ -160,12 +158,11 @@ get_user_repo_list <- function(owner, count = "all", data_format = "dataframe",
#' summary_metrics <- get_github_repo_summary(repo = "fhdsl/metricminer")
#' timecourse_metrics <- get_github_repo_timecourse(repo = "fhdsl/metricminer")
#' }
get_github_metrics <- function(repo, token = NULL, count = "all", data_format = "dataframe", time_course = FALSE) {
if (count == "all") count <- Inf
get_github_metrics <- function(repo, token = NULL, count = 100000, data_format = "dataframe", time_course = FALSE) {

if (is.null(token)) {
# Get auth token
token <- get_token(app_name = "github", try = TRUE)
token <- get_token(app_name = "github")
if (is.null(token)) warning("No token found. Only public repositories will be retrieved.")
}

Expand Down Expand Up @@ -243,7 +240,7 @@ get_github_metrics <- function(repo, token = NULL, count = "all", data_format =
#' @description This is a function to get the information about a repository
#' @param token You can provide the Personal Access Token key directly or this function will attempt to grab a PAT that was stored using the `authorize("github")` function
#' @param repo The repository name. So for `https://github.com/fhdsl/metricminer`, it would be `fhdsl/metricminer`
#' @param count How many items would you like to receive? Put "all" to retrieve all records.
#' @param count How many items would you like to receive? default is 100000
#' @param data_format Default is to return a curated data frame. However if you'd like to see the raw information returned from GitHub set format to "raw".
#' @return GitHub repository timecourse metrics for views and clones
#' @export
Expand All @@ -253,7 +250,7 @@ get_github_metrics <- function(repo, token = NULL, count = "all", data_format =
#'
#' timecourse_metrics <- get_github_repo_timecourse(repo = "fhdsl/metricminer")
#' }
get_github_repo_timecourse <- function(repo, token = NULL, count = "all", data_format = "dataframe") {
get_github_repo_timecourse <- function(repo, token = NULL, count = 100000, data_format = "dataframe") {
result <- get_github_metrics(
repo = repo,
token = token,
Expand All @@ -269,7 +266,7 @@ get_github_repo_timecourse <- function(repo, token = NULL, count = "all", data_f
#' @description This is a function to get the information about a repository
#' @param token You can provide the Personal Access Token key directly or this function will attempt to grab a PAT that was stored using the `authorize("github")` function
#' @param repo The repository name. So for `https://github.com/fhdsl/metricminer`, it would be `fhdsl/metricminer`
#' @param count How many items would you like to receive? Put "all" to retrieve all records.
#' @param count How many items would you like to receive? default is 100000
#' @param data_format Default is to return a curated data frame. However if you'd like to see the raw information returned from GitHub set format to "raw".
#' @return GitHub repository summary metrics
#' @export
Expand All @@ -279,7 +276,7 @@ get_github_repo_timecourse <- function(repo, token = NULL, count = "all", data_f
#'
#' summary_metrics <- get_github_repo_summary(repo = "fhdsl/metricminer")
#' }
get_github_repo_summary <- function(repo, token = NULL, count = "all", data_format = "dataframe") {
get_github_repo_summary <- function(repo, token = NULL, count = 100000, data_format = "dataframe") {
result <- get_github_metrics(
repo = repo,
token = token,
Expand Down Expand Up @@ -349,12 +346,13 @@ get_multiple_repos_metrics <- function(repo_names = NULL, token = NULL, data_for
#' @param token You can provide the Personal Access Token key directly or this function will attempt to grab a PAT that was stored using the `authorize("github")` function
#' @param owner The repository name. So for `https://github.com/fhdsl/metricminer`, it would be `fhdsl`
#' @param repo The repository name. So for `https://github.com/fhdsl/metricminer`, it would be `metricminer`
#' @param count How many items would you like to receive? Put "all" to retrieve all records.
#' @param count How many items would you like to receive? default is 100000
#' @return Metrics for a repository on GitHub
#' @importFrom gh gh
#' @export
#'
gh_repo_wrapper <- function(api_call, owner, repo, token = NULL, count = Inf) {
gh_repo_wrapper <- function(api_call, owner, repo, token = NULL, count = 100000) {

message(paste0("Trying ", api_call, " for ", owner, "/", repo))

if (is.null(token)) {
Expand All @@ -374,7 +372,6 @@ gh_repo_wrapper <- function(api_call, owner, repo, token = NULL, count = Inf) {
# Some handlers because not all repositories have all stats
if (length(result) == 0) result <- "No results"
if (grepl("404", result[1])) result <- "No results"
if (class(result)[1] == "try-error") stop(paste0("Failed to retrieve: ", owner, "/", repo))

return(result)
}
Expand Down
16 changes: 14 additions & 2 deletions R/google-analytics.R
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ link_clicks <- function() {
#' @param account_id the account id that you'd like to retrieve stats for all properties associated with it.
#' @param property_ids A vector of property ids you'd like to retrieve metrics for.
#' @param token credentials for access to Google using OAuth. `authorize("google")`
#' @param start_date YYYY-MM-DD format of what metric you'd like to collect metrics from to start. Default is the earliest date Google Analytics were collected.
#' @param end_date YYYY-MM-DD format of what metric you'd like to collect metrics from to end. Default is today.
#' @param dataformat How would you like the data returned to you? Default is a "dataframe" but if you'd like to see the original API list result, put "raw".
#' @param stats_type Do you want to retrieve metrics or dimensions? List all you want to collect as a vector
#' @returns Either a list of dataframes where `metrics`, `dimensions` and `link clicks` are reported. But if `format` is set to "raw" then the original raw API results will be returned
Expand All @@ -334,7 +336,12 @@ link_clicks <- function() {
#' some_properties <- get_multiple_ga_metrics(property_ids = property_ids)
#'
#' }
get_multiple_ga_metrics <- function(account_id = NULL, property_ids = NULL, token = NULL, dataformat = "dataframe",
get_multiple_ga_metrics <- function(account_id = NULL,
property_ids = NULL,
token = NULL,
start_date = "2015-08-14",
end_date = NULL,
dataformat = "dataframe",
stats_type = c("metrics", "dimensions", "link_clicks")) {
if (is.null(token)) {
# Get auth token
Expand Down Expand Up @@ -370,7 +377,12 @@ get_multiple_ga_metrics <- function(account_id = NULL, property_ids = NULL, toke
message(paste("Retrieving", property_id, a_stats_type))

# Get the stats
metrics <- get_ga_stats(token = token, property_id, stats_type = a_stats_type, dataformat = "raw")
metrics <- get_ga_stats(token = token,
start_date = start_date,
end_date = end_date,
property_id = property_id,
stats_type = a_stats_type,
dataformat = "raw")

return(metrics)
})
Expand Down
21 changes: 12 additions & 9 deletions R/google-forms.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ get_google_form <- function(form_id, token = NULL, dataformat = "dataframe") {
metadata = metadata,
answers = answers_df
)
return(result)
}
return(result)
}


Expand All @@ -135,6 +135,7 @@ get_google_form <- function(form_id, token = NULL, dataformat = "dataframe") {
#' If you don't check this box on the OAuth screen this function won't work.
#' @param form_ids a vector of form ids you'd like to retrieve information for
#' @param token credentials for access to Google using OAuth. `authorize("google")`
#' @param dataformat What format would you like the data? Options are "raw" or "dataframe". "dataframe" is the default.
#' @returns This returns a list of API information for google forms
#' @importFrom purrr map
#' @importFrom janitor make_clean_names
Expand All @@ -149,22 +150,24 @@ get_google_form <- function(form_id, token = NULL, dataformat = "dataframe") {
#'
#' multiple_forms <- get_multiple_forms(form_ids = form_list$id)
#' }
get_multiple_forms <- function(form_ids = NULL, token = NULL) {
get_multiple_forms <- function(form_ids = NULL, token = NULL, dataformat = "dataframe") {
# Get all the forms info
all_form_info <- sapply(form_ids, function(form_id) {
get_google_form(
form_id = form_id,
token = token
token = token,
dataformat = dataformat
)
}, simplify = FALSE, USE.NAMES = TRUE)

if (dataformat == "dataframe") {
# Set up the names
titles <- purrr::map(all_form_info, ~ .x$title)
titles <- janitor::make_clean_names(titles)

# Set up the names
titles <- purrr::map(all_form_info, ~ .x$title)
titles <- janitor::make_clean_names(titles)

# Set as names
names(all_form_info) <- titles
# Set as names
names(all_form_info) <- titles
}

all_form_info
}
Expand Down
4 changes: 1 addition & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
utils::globalVariables(c(
"result", "num", "test_name", "scopes", "set_token", "browseURL", "remove_token", "get_token", "get_github", "get_calendly", "%>%",
"token", "query_params", "file_name", "accounts", "get_repo_list", "timestamp", "uniques", "req", "cache_secrets_folder", "google_folder_locations"
"token", "query_params", "file_name", "accounts", "get_repo_list", "timestamp", "uniques", "req", "cache_secrets_folder", "google_folder_locations", "google_entry"
))

#' Get list of example datasets
Expand Down Expand Up @@ -109,11 +109,9 @@ key_encrypt_creds_path <- function() {
full.names = TRUE
)
}

#' See where your cached secrets are being stored
#' @description This is a function to retrieve the file path of where your cached secrets are stored
#' @return an file path that shows where your cached secrets are stored
#' @export
#' @examples \dontrun{
#'
#' # You can see where your cached secrets are being stored by running:
Expand Down
4 changes: 2 additions & 2 deletions man/get_github_metrics.Rd

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

4 changes: 2 additions & 2 deletions man/get_github_repo_summary.Rd

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

4 changes: 2 additions & 2 deletions man/get_github_repo_timecourse.Rd

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

4 changes: 3 additions & 1 deletion man/get_multiple_forms.Rd

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

6 changes: 6 additions & 0 deletions man/get_multiple_ga_metrics.Rd

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

4 changes: 2 additions & 2 deletions man/get_org_repo_list.Rd

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

4 changes: 2 additions & 2 deletions man/get_user_repo_list.Rd

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

Loading
Loading