Skip to content

Commit

Permalink
Use parsing in HTTR instead of doing it ourself in jsonlite
Browse files Browse the repository at this point in the history
  • Loading branch information
lmullen committed Mar 19, 2016
1 parent 3bbde5c commit 9a092dd
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 22 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ BugReports: https://github.com/ropensci/internetarchive/issues
Depends:
R (>= 3.1.0)
Imports:
httr (>= 0.6.1),
jsonlite (>= 0.9.14),
dplyr (>= 0.4.1)
httr (>= 1.1.0),
dplyr (>= 0.4.3)
Suggests:
knitr,
testthat,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export(ia_list_fields)
export(ia_metadata)
export(ia_search)
import(httr)
import(jsonlite)
importFrom(dplyr,"%>%")
importFrom(dplyr,as_data_frame)
importFrom(dplyr,data_frame)
Expand Down
6 changes: 2 additions & 4 deletions R/ia_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
#' @return A data frame including the file names of the downloaded files.
#' @examples
#' \dontrun{
#' if(require(dplyr)) {
#' if (require(dplyr)) {
#' dir <- tempdir()
#' ia_get_items("thedamnationofth00133gut") %>%
#' ia_files() %>%
#' filter(type == "txt") %>% # download only the files we want
#' group_by(id) %>%
#' slice(1) %>%
#' ia_download(dir = dir, extended_name = FALSE)
#' }
#' }
Expand All @@ -47,7 +45,7 @@ download_row <- function(row, dir, extended_name, overwrite, silence) {
}

if (overwrite | !file.exists(row$local_file)) {
if(!silence) message(paste("Downloading", row$local_file))
if (!silence) message(paste("Downloading", row$local_file))
GET(row$url, write_disk(row$local_file, overwrite = overwrite))
row$downloaded <- TRUE
}
Expand Down
5 changes: 2 additions & 3 deletions R/ia_get_item.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ ia_get_items <- function(item_id, silence = FALSE) {
if (!silence) message(paste("Getting", item_id))
req <- GET("https://archive.org/", path = path, query = list(output = "json"))
warn_for_status(req)
result <- content(req, as = "text")
if (identical(result, "")) stop("")
fromJSON(result, simplifyVector = FALSE)
result <- content(req, as = "parsed", encoding = "UTF-8")
result
}
ia_get_items <- Vectorize(ia_get_items, SIMPLIFY = FALSE)
4 changes: 1 addition & 3 deletions R/ia_keyword_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ ia_keyword_search <- function(keywords, num_results = 5, page = 1,
url <- modify_url(base, path = path, query = query)
req <- GET(url)
warn_for_status(req)
result <- content(req, as = "text")
if (identical(result, "")) stop("")
response <- fromJSON(result, simplifyVector = FALSE)
response <- content(req, as = "parsed", encoding = "UTF-8")

if (print_total)
message(paste(response$response$numFound, "total items found.",
Expand Down
4 changes: 1 addition & 3 deletions R/ia_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ ia_search <- function(terms, num_results = 5, page = 1, print_url = FALSE,
if (print_url) message(url)
req <- GET(url)
warn_for_status(req)
result <- content(req, as = "text")
if (identical(result, "")) stop("")
response <- fromJSON(result, simplifyVector = FALSE)
response <- content(req, as = "parsed", encoding = "UTF-8")

if (print_total)
message(paste(response$response$numFound, "total items found.",
Expand Down
3 changes: 1 addition & 2 deletions R/internetarchive-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
#' files (\link{ia_files}) in a pipeable interface.
#'
#' @import httr
#' @import jsonlite
#' @importFrom dplyr rbind_all data_frame %>% mutate rowwise do as_data_frame
#' @importFrom tools file_ext
#' @name internetarchive
NULL

# Hide variables from R CMD check
if(getRversion() >= "2.15.1") {
if (getRversion() >= "2.15.1") {
utils::globalVariables(c(".", "id"))
}
4 changes: 1 addition & 3 deletions man/ia_download.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9a092dd

Please sign in to comment.