From 00d93e55c943515ea289918c85c2d11a1ddcb63a Mon Sep 17 00:00:00 2001 From: Viktor Horvath Date: Sat, 24 Oct 2020 11:54:37 -0400 Subject: [PATCH 1/5] Making offset available for air_get() --- R/airtabler.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/airtabler.R b/R/airtabler.R index c325c01..ad18ca6 100644 --- a/R/airtabler.R +++ b/R/airtabler.R @@ -89,6 +89,7 @@ air_get <- function(base, table_name, record_id = NULL, ) air_validate(res) # throws exception (stop) if error ret <- air_parse(res) # returns R object + offset <- attr(ret, "offset") if(combined_result && is.null(record_id)) { # combine ID, Fields and CreatedTime in the same data frame: ret <- @@ -97,6 +98,7 @@ air_get <- function(base, table_name, record_id = NULL, stringsAsFactors =FALSE ) } + attr(ret, "offset") <- offset ret } From 2dcba402962a01e1b7b2c256aab282eec74255b5 Mon Sep 17 00:00:00 2001 From: Viktor Horvath Date: Sat, 24 Oct 2020 11:56:42 -0400 Subject: [PATCH 2/5] Exposing offset when returned in air_select() --- R/airtabler.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/airtabler.R b/R/airtabler.R index ad18ca6..f1dfb64 100644 --- a/R/airtabler.R +++ b/R/airtabler.R @@ -216,8 +216,8 @@ air_select <- function( id = ret$id, ret$fields, createdTime = ret$createdTime, stringsAsFactors =FALSE ) - attr(ret, "offset") <- offset } + attr(ret, "offset") <- offset ret } From 36dacfd4db8c7db0062fe00d9efee0888e4f1acc Mon Sep 17 00:00:00 2001 From: Viktor Horvath Date: Sat, 24 Oct 2020 12:04:31 -0400 Subject: [PATCH 3/5] Guar pattern for air_parse() --- R/airtabler.R | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/R/airtabler.R b/R/airtabler.R index f1dfb64..308cdc2 100644 --- a/R/airtabler.R +++ b/R/airtabler.R @@ -258,14 +258,18 @@ air_validate <- function(res) { air_parse <- function(res) { res_obj <- jsonlite::fromJSON(httr::content(res, as = "text")) - if(!is.null(res_obj$records)) { - res <- res_obj$records - if(!is.null(res_obj$offset)) { - attr(res, "offset") <- res_obj$offset - } - } else { - res <- res_obj + + # Single entry returned, terminate early: expose all key-value pairs + if(is.null(res_obj$records)) { return(res_obj) } + + # Multiple entries returned: expose values under 'records' key + res <- res_obj$records + + # Add offset, if available + if(!is.null(res_obj$offset)) { + attr(res, "offset") <- res_obj$offset } + res } From ce74f8d86f0f5da2885a71c754064f2dc2af89fa Mon Sep 17 00:00:00 2001 From: Viktor Horvath Date: Sat, 24 Oct 2020 12:05:38 -0400 Subject: [PATCH 4/5] Guard pattern for air_parse() --- R/airtabler.R | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/R/airtabler.R b/R/airtabler.R index f1dfb64..308cdc2 100644 --- a/R/airtabler.R +++ b/R/airtabler.R @@ -258,14 +258,18 @@ air_validate <- function(res) { air_parse <- function(res) { res_obj <- jsonlite::fromJSON(httr::content(res, as = "text")) - if(!is.null(res_obj$records)) { - res <- res_obj$records - if(!is.null(res_obj$offset)) { - attr(res, "offset") <- res_obj$offset - } - } else { - res <- res_obj + + # Single entry returned, terminate early: expose all key-value pairs + if(is.null(res_obj$records)) { return(res_obj) } + + # Multiple entries returned: expose values under 'records' key + res <- res_obj$records + + # Add offset, if available + if(!is.null(res_obj$offset)) { + attr(res, "offset") <- res_obj$offset } + res } From 801b5b126f31403ea479a3b70e253dc15a0aade7 Mon Sep 17 00:00:00 2001 From: Viktor Horvath Date: Sat, 24 Oct 2020 12:09:47 -0400 Subject: [PATCH 5/5] Guard pattern for air_parse() --- R/airtabler.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/airtabler.R b/R/airtabler.R index 308cdc2..14815d7 100644 --- a/R/airtabler.R +++ b/R/airtabler.R @@ -269,7 +269,6 @@ air_parse <- function(res) { if(!is.null(res_obj$offset)) { attr(res, "offset") <- res_obj$offset } - res }