tests/testthat/test-batch.R

# library(testthat)
# library(googleAuthR)
# options(googleAuthR.httr_oauth_cache = "httr-oauth.rds")
# ## from search console API
# list_websites <- function() {
#   
#   l <- googleAuthR::gar_api_generator("https://www.googleapis.com/webmasters/v3/sites",
#                                       "GET",
#                                       data_parse_function = function(x) x$siteEntry)
#   l()
# }
# 
# ## from google Analytics API
# google_analytics_account_list <- function(){
#   
#   url <- "https://www.googleapis.com/analytics/v3/management/accountSummaries"
#   acc_sum <- gar_api_generator(url,
#                                "GET",
#                                data_parse_function = function(x) x)
#   
#   acc_sum()
# }
# 
# test_walk <- function(){
#   
#   siteURL <-  "http://sites.google.com/a/markedmondson.me/home/"
#   startDate <- Sys.Date() - 93
#   endDate <- Sys.Date() - 3
#   dimensions <- NULL
#   searchType <- c("web")
#   aggregationType <- "auto"
#   rowLimit <-  1000
#   
#   startDate <- as.character(startDate)
#   endDate   <- as.character(endDate)  
#   
#   siteURL <- utils::URLencode(siteURL, reserved=T)
#   
#   body <- list(
#     startDate = startDate,
#     endDate = endDate,
#     dimensions = as.list(dimensions),  
#     searchType = searchType,
#     dimensionFilterGroups = list(
#       list( ## you don't want more than one of these until different groupType available
#         groupType = "and", ##only one available for now
#         filters = NULL
#       )
#     ),
#     aggregationType = aggregationType,
#     rowLimit = rowLimit
#   )
#   
#   search_analytics_g <- 
#     googleAuthR::gar_api_generator("https://www.googleapis.com/webmasters/v3/",
#                                    "POST",
#                                    path_args = list(sites = "siteURL",
#                                                     searchAnalytics = "query"),
#                                    data_parse_function = function(x) x
#     )
#       
#   ## byBatch uses API batching, but this pulls out less data
#   ## 0 impression keywords not included. 
#   walk_vector <- seq(0, rowLimit, 5000)
#   
#   googleAuthR::gar_batch_walk(search_analytics_g,
#                               walk_vector = walk_vector,
#                               gar_paths = list(sites = siteURL),
#                               body_walk = "startRow",
#                               the_body = body,
#                               batch_size = 3, 
#                               data_frame_output = FALSE)
#   
# }
# 
# context("Batching")
# 
# test_that("Can authenticate JSON settings (Batch)", {
#   skip_on_cran()
#   filep <- Sys.getenv("GAR_AUTH_FILE")
#   if(filep == "") filep <- Sys.getenv("TRAVIS_GAR_AUTH_FILE")
#   
#   if(filep != ""){
#     
#     expect_s3_class(gar_auth_service(filep), "Token2.0")
#     
#   } else {
#     skip("No auth file found")
#   }
#   
# })
# 
# 
# test_that("A walk batch call works but with no returned data", {
#   skip_on_cran()
#   gg <- test_walk()
#   expect_type(gg, "list")
# })

# tests batching with googleAnalyticsR
# library(googleAnalyticsR)
# accountId <- 54019251
# test_email_adds <- c("mark@iihnordic.com", "iihmarkedmondson@gmail.com")
# done <- ga_users_add(test_email_adds,permissions = "EDIT", accountId = accountId)
MarkEdmondson1234/googleAuthR documentation built on Aug. 7, 2023, 6 a.m.