Wrap API https request in new apiCall method
Also added: timeout and userAgent slots in KorAPConnection and output of error and warning messages.
Change-Id: I76159941a9fc56d31a560b84cc295419f52c3503
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index 24a03cb..b3fb9d5 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -151,7 +151,7 @@
if (verbose) {
cat("Searching \"", query, "\" in \"", vc, "\"", sep="")
}
- res = fromJSON(paste0(requestUrl, '&count=1'))
+ res = apiCall(kco, paste0(requestUrl, '&count=1'))
if (verbose) {
cat(" took ", res$meta$benchmark, "\n", sep="")
}
@@ -194,7 +194,7 @@
collectedMatches <- kqo@collectedMatches
repeat {
- res <- fromJSON(paste0(kqo@requestUrl, '&count=', min(ifelse(!is.na(maxFetch), maxFetch - results, maxResultsPerPage), maxResultsPerPage) ,'&offset=', offset + results))
+ res <- apiCall(kqo@korapConnection, paste0(kqo@requestUrl, '&count=', min(ifelse(!is.na(maxFetch), maxFetch - results, maxResultsPerPage), maxResultsPerPage) ,'&offset=', offset + results))
if (res$meta$totalResults == 0) { return(kqo) }
for (field in kqo@fields) {
if (!field %in% colnames(res$matches)) {
@@ -221,7 +221,7 @@
}
nextStartIndex <- min(res$meta$startIndex + res$meta$itemsPerPage, res$meta$totalResults)
KorAPQuery(nextStartIndex = nextStartIndex,
- korapConnection = kco,
+ korapConnection = kqo@korapConnection,
fields = kqo@fields,
requestUrl = kqo@requestUrl,
request = kqo@request,