Build fetch API URL using httr2
This also prevents errors with numbers getting converted to scientific
notation via paste0.
Resolves #25
Change-Id: I92d94fa27119471d5659ac4db9a34e4571794489
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index 04d859a..340bd4c 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -474,8 +474,19 @@
# Calculate the actual offset in tokens
currentOffset <- current_offset_page * maxResultsPerPage
- # Build the query with the appropriate count and offset
- query <- paste0(kqo@requestUrl, "&count=", min(if (!is.na(maxFetch)) maxFetch - results else maxResultsPerPage, maxResultsPerPage), "&offset=", currentOffset, "&cutoff=true")
+ # Build the query with the appropriate count and offset using httr2
+ count_param <- min(if (!is.na(maxFetch)) maxFetch - results else maxResultsPerPage, maxResultsPerPage)
+
+ # Parse existing URL to preserve all query parameters
+ parsed_url <- httr2::url_parse(kqo@requestUrl)
+ existing_query <- parsed_url$query
+
+ # Add/update count and offset parameters
+ existing_query$count <- count_param
+ existing_query$offset <- currentOffset
+
+ # Rebuild the URL with all parameters
+ query <- httr2::url_modify(kqo@requestUrl, query = existing_query)
res <- apiCall(kqo@korapConnection, query)
if (length(res$matches) == 0) {
break