Add runtime OAuth2 browser flow demos with httr and httr2
Change-Id: If244a6c6c68115f52125189445c30c167c61b13b
diff --git a/demo/00Index b/demo/00Index
index 6000d36..2b86b41 100644
--- a/demo/00Index
+++ b/demo/00Index
@@ -14,3 +14,5 @@
frequency_by_country_highcharts Plot frequencies depending on country of publication using highcharter.
collocation_score_by_country Plot collocation scores depending on country of publication using ggplot2.
pluralGenderVariants Plot frequencies of the plular gender variants of a word over time.
+OAuthBrowserflowHttr2 Runtime OAuth2 browser flow demonstration using the httr2 package (adjective collocates of »Gendern«)
+OAuthBrowserflowHttr Runtime OAuth2 browser flow demonstration using the httr package (query results for »Vöner« including KWICs)
diff --git a/demo/OAuthBrowserflowHttr.R b/demo/OAuthBrowserflowHttr.R
new file mode 100644
index 0000000..47fccd1
--- /dev/null
+++ b/demo/OAuthBrowserflowHttr.R
@@ -0,0 +1,22 @@
+library(RKorAPClient)
+library(httr)
+library(kableExtra)
+library(dplyr)
+
+query = 'V\u00F6ner' # "Portable packages must use only ASCII characters in their demos. Use \uxxxx escapes for other characters."
+
+korap_app <-oauth_app("test-korap-client", key = "773NHGM76N7P9b6rLfmpM4", secret = NULL)
+korap_endpoint <- oauth_endpoint(NULL,
+ "settings/oauth/authorize",
+ "api/v1.0/oauth2/token",
+ base_url = "https://korap.ids-mannheim.de")
+token_bundle = oauth2.0_token(korap_endpoint, korap_app, scope = "search match_info", cache = FALSE)
+
+new("KorAPConnection", verbose = TRUE, accessToken = token_bundle[["credentials"]][["access_token"]]) %>%
+ corpusQuery(query, fields = c("textSigle", "pubDate", "corpusTitle", "snippet"),
+ metadataOnly = FALSE) %>%
+ fetchAll() %>%
+ slot("collectedMatches") %>%
+ dplyr::arrange(pubDate) %>%
+ kable(escape = FALSE, caption = paste0("Query hits for '", query, "' ordered by date of publication")) %>%
+ kable_styling()
diff --git a/demo/OAuthBrowserflowHttr2.R b/demo/OAuthBrowserflowHttr2.R
new file mode 100644
index 0000000..b67564e
--- /dev/null
+++ b/demo/OAuthBrowserflowHttr2.R
@@ -0,0 +1,14 @@
+library(RKorAPClient)
+library(httr2)
+library(kableExtra)
+
+token <- oauth_client( id = "773NHGM76N7P9b6rLfmpM4",
+ token_url = "https://korap.ids-mannheim.de/api/v1.0/oauth2/token") %>%
+ oauth_flow_auth_code( scope = "search match_info",
+ auth_url = "https://korap.ids-mannheim.de/settings/oauth/authorize")
+
+new("KorAPConnection", verbose = TRUE, accessToken = token$access_token) %>%
+ collocationAnalysis("focus([marmot/p=ADJA] {Gendern})", leftContextSize=1, rightContextSize=0) %>%
+ mutate(collocate = paste0('<a href="', webUIRequestUrl, '">', collocate, '</a>')) %>%
+ select(collocate, O, pmi, mi2, mi3, logDice, ll) %>%
+ kable(escape = FALSE, caption = "Adjective collocates of 'Gendern'") %>% kable_styling()