#' @title get_news_page_range
#' @description Pulls Janes news articles page range for a given search. Helper function.
#'
#' @param country Country filter for news
#' @param query Keyword search for news
#'
#' @return Helper function to return Janes news article page range related to search.
#' @importFrom httr GET
#' @importFrom httr content
#' @importFrom jsonlite fromJSON
#' @importFrom stringr str_replace_all
#' @importFrom magrittr "%>%"
get_news_page_range <- function(country = NULL, query = NULL){
request <- httr::GET(url = paste0("https://developer.janes.com/api/v1/news?q=",
stringr::str_replace_all(query, " ", "%20"),
"&f=countryiso(",
country,
")&num=100"),
httr::add_headers(Authorization = Sys.getenv("JANES_KEY")))
response <- httr::content(request, as = "text", encoding = "UTF-8")
range_temp <- ceiling(jsonlite::fromJSON(response)[["metadata"]][["recordCount"]] / 100)
seq(1:range_temp)
}
#' @export
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.