Skip to content

Commit

Permalink
Updated the code to support empty reports
Browse files Browse the repository at this point in the history
Improved the speed by checking to see if we had already gotten a working report prior to sleeping for 15 seconds
Fixed a bug in the read.KissReports code
  • Loading branch information
yosemsweet committed Feb 10, 2016
1 parent ff6d926 commit e902e31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
5 changes: 2 additions & 3 deletions R/kiss-report.R
Expand Up @@ -88,13 +88,12 @@ read.KissReport <- function(report) {

resultsLink <- NULL
repeat {
# Wait 15 seconds for report to complete
Sys.sleep(15)

print("Checking status of report")
requestKey <- c(statusLink, headers)
response <- readCache(report, requestKey)
if (is.null(response)) {
# Wait 15 seconds for report to complete
Sys.sleep(15)
response <- httr::GET(statusLink, httr::add_headers(headers))
}
httr::stop_for_status(response)
Expand Down
28 changes: 18 additions & 10 deletions R/utilities.R
Expand Up @@ -82,14 +82,22 @@ loadPages <- function (object, url) {
totalItems <- pages$pagination$total
itemsPerPage <- pages$pagination$limit

urlTemplate <- stringr::str_c(url,
"?limit=", itemsPerPage, "\u0026offset={{OFFSET}}")


urls <- buildPaginationUrls(urlTemplate = urlTemplate,
offsets = seq(from=0,
to=totalItems,
by=itemsPerPage))

do.call(rbind, lapply(urls, loadPage, object=object))
if(totalItems > 0) {
urlTemplate <- stringr::str_c(url,
"?limit=", itemsPerPage, "\u0026offset={{OFFSET}}")


urls <- buildPaginationUrls(urlTemplate = urlTemplate,
offsets = seq(from=0,
to=totalItems,
by=itemsPerPage))

result <- do.call(rbind, lapply(urls, loadPage, object=object))
} else if (is.null(object$columnNames)) {
result <- data.frame(product_id=c(), account_id=c(), report_type=c(), name=c(), created_at=c(), links=c())
} else {
result <- setNames(data.frame(matrix(ncol=length(object$columnNames), nrow=0)),
object$columnNames)
}
return(result)
}

0 comments on commit e902e31

Please sign in to comment.