From 26dc4c8e443c3cbbbbcfa419fbc74f5f70a5380b Mon Sep 17 00:00:00 2001 From: Greg Sutcliffe Date: Fri, 19 Mar 2021 11:08:36 +0000 Subject: [PATCH] Fixes #111 - only use next_url for subsequent pagination calls --- R/internals.R | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/R/internals.R b/R/internals.R index 29ae92cd..a2e6be19 100644 --- a/R/internals.R +++ b/R/internals.R @@ -96,20 +96,17 @@ meetup_api_prefix <- function() { if((length(records) < total_records) & !is.null(res$headers$link)){ # calculate number of offsets for records above 200 - offsetn <- ceiling(total_records/length(records)) + max_pages <- ceiling(total_records/length(records)) all_records <- list(records) - for(i in 1:(offsetn - 1)) { - res <- meetup_call(api_path = api_path, - event_status = event_status, - offset = i, - ...) - + # Paginate over res. First page already exists in res and all_records, so we can + # start from page 2 using the next_page api data returned from Meetup. + for(i in 2:max_pages) { next_url <- strsplit(strsplit(res$headers$link, split = "<")[[1]][2], split = ">")[[1]][1] next_url <- gsub(meetup_api_prefix(), "", next_url) - res <- meetup_call(next_url, event_status) + res <- meetup_call(next_url, event_status, offset = NULL) # offset is already in the next_url - all_records[[i + 1]] <- res$result + all_records[[i]] <- res$result } records <- unlist(all_records, recursive = FALSE)