Skip to content

Commit

Permalink
Fix forms thing
Browse files Browse the repository at this point in the history
  • Loading branch information
cansavvy committed May 13, 2024
1 parent 0a10d78 commit caba602
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
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
14 changes: 12 additions & 2 deletions R/google-analytics.R
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,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 +375,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

0 comments on commit caba602

Please sign in to comment.