Slim down buildWebUIRequestUrl function
Change-Id: I3da8e74388fc5a703bd83895cae6dea3741d4f59
diff --git a/NAMESPACE b/NAMESPACE
index 9255cb8..47165ab 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -7,6 +7,7 @@
export(as_tibble)
export(bind_cols)
export(buildWebUIRequestUrl)
+export(buildWebUIRequestUrlFromString)
export(ci)
export(complete)
export(defaultAssociationScoreFunctions)
@@ -91,6 +92,7 @@
importFrom(ggplot2,layer)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,theme)
+importFrom(httr,parse_url)
importFrom(jsonlite,fromJSON)
importFrom(lubridate,year)
importFrom(magrittr,"%>%")
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index c1c29d9..fb6af8b 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -427,11 +427,37 @@
ci(conf.level = conf.level)
})
+#' buildWebUIRequestUrlFromString
+#'
+#' @rdname KorAPQuery-class
+#' @importFrom urltools url_encode
+#' @export
+buildWebUIRequestUrlFromString <- function(KorAPUrl,
+ query,
+ vc = "",
+ ql = "poliqarp"
+) {
+ if ("KorAPConnection" %in% class(KorAPUrl)) {
+ KorAPUrl <- KorAPUrl@KorAPUrl
+ }
+
+ request <-
+ paste0(
+ '?q=',
+ urltools::url_encode(enc2utf8(as.character(query))),
+ ifelse(vc != '',
+ paste0('&cq=', urltools::url_encode(enc2utf8(vc))),
+ ''),
+ '&ql=',
+ ql
+ )
+ paste0(KorAPUrl, request)
+}
#' buildWebUIRequestUrl
#'
#' @rdname KorAPQuery-class
-#' @importFrom urltools url_encode
+#' @importFrom httr parse_url
#' @export
buildWebUIRequestUrl <- function(kco,
query = if (missing(KorAPUrl))
@@ -440,42 +466,9 @@
httr::parse_url(KorAPUrl)$query$q,
vc = if (missing(KorAPUrl)) "" else httr::parse_url(KorAPUrl)$query$cq,
KorAPUrl,
- metadataOnly = TRUE,
- ql = if (missing(KorAPUrl)) "poliqarp" else httr::parse_url(KorAPUrl)$query$ql,
- fields = c(
- "corpusSigle",
- "textSigle",
- "pubDate",
- "pubPlace",
- "availability",
- "textClass",
- "snippet",
- "tokens"
- ),
- accessRewriteFatal = TRUE) {
- request <-
- paste0(
- '?q=',
- urltools::url_encode(enc2utf8(as.character(query))),
- ifelse(vc != '',
- paste0('&cq=', urltools::url_encode(enc2utf8(vc))),
- ''),
- '&ql=',
- ql
- )
- webUIRequestUrl <- paste0(kco@KorAPUrl, request)
- requestUrl <- paste0(
- kco@apiUrl,
- 'search',
- request,
- '&fields=',
- paste(fields, collapse = ","),
- if (metadataOnly)
- '&access-rewrite-disabled=true'
- else
- ''
- )
- webUIRequestUrl
+ ql = if (missing(KorAPUrl)) "poliqarp" else httr::parse_url(KorAPUrl)$query$ql) {
+
+ buildWebUIRequestUrlFromString(kco@KorAPUrl, query, vc, ql)
}
#´ format()
diff --git a/man/KorAPQuery-class.Rd b/man/KorAPQuery-class.Rd
index 1f131a5..1c862cc 100644
--- a/man/KorAPQuery-class.Rd
+++ b/man/KorAPQuery-class.Rd
@@ -15,6 +15,7 @@
\alias{fetchRest}
\alias{frequencyQuery,KorAPConnection-method}
\alias{frequencyQuery}
+\alias{buildWebUIRequestUrlFromString}
\alias{buildWebUIRequestUrl}
\alias{format.KorAPQuery}
\alias{show,KorAPQuery-method}
@@ -75,6 +76,8 @@
...
)
+buildWebUIRequestUrlFromString(KorAPUrl, query, vc = "", ql = "poliqarp")
+
buildWebUIRequestUrl(
kco,
query = if (missing(KorAPUrl))
@@ -82,11 +85,7 @@
FALSE) else httr::parse_url(KorAPUrl)$query$q,
vc = if (missing(KorAPUrl)) "" else httr::parse_url(KorAPUrl)$query$cq,
KorAPUrl,
- metadataOnly = TRUE,
- ql = if (missing(KorAPUrl)) "poliqarp" else httr::parse_url(KorAPUrl)$query$ql,
- fields = c("corpusSigle", "textSigle", "pubDate", "pubPlace", "availability",
- "textClass", "snippet", "tokens"),
- accessRewriteFatal = TRUE
+ ql = if (missing(KorAPUrl)) "poliqarp" else httr::parse_url(KorAPUrl)$query$ql
)
\method{format}{KorAPQuery}(x, ...)