Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchKSSL: Fix for "status was 'SSL connect error'" #267

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions R/fetchKSSL.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@
.getExtended_SoilWeb <- function(f) {

# KSSL geochem, XRD, glass
extended.url <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=extended', f))

x <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=extended', f))

tf <- tempfile()
curl::curl_download(x, tf, quiet = TRUE, mode = "wb", handle = .soilDB_curl_handle())

## get data
# note: missing data are returned as FALSE by the API
# when data are available, list of data.frame objects
ext <- jsonlite::fromJSON(gzcon(url(extended.url)))
# unlink(tf)
# list of dataframe objects; note: missing data are returned as FALSE
ext <- jsonlite::fromJSON(gzfile(tf))
unlink(tf)

# done
return(ext)
Expand All @@ -62,13 +64,16 @@
.getMorphologic_SoilWeb <- function(f) {

# NASIS morphology
morph.url <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=nasis_morphologic', f))
x <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=nasis_morphologic', f))

tf <- tempfile()
curl::curl_download(x, tf, quiet = TRUE, mode = "wb", handle = .soilDB_curl_handle())

## get data
# note: missing data are returned as FALSE
# list of dataframe objects
m <- jsonlite::fromJSON(gzcon(url(morph.url)))

# list of dataframe objects; note: missing data are returned as FALSE
m <- jsonlite::fromJSON(gzfile(tf))
unlink(tf)
# done
return(m)
}
Expand All @@ -78,13 +83,16 @@
.getKSSL_SoilWeb <- function(f) {

# KSSL site + horizon
site_hz.url <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=site_hz', f))

# ## get data
# # note: missing data are returned as FALSE
# # list of dataframe objects
site_hz <- jsonlite::fromJSON(gzcon(url(site_hz.url)))
x <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=site_hz', f))

tf <- tempfile()
curl::curl_download(x, tf, quiet = TRUE, mode = "wb", handle = .soilDB_curl_handle())

## get data
# list of dataframe objects; note: missing data are returned as FALSE
site_hz <- jsonlite::fromJSON(gzfile(tf))
unlink(tf)

# report missing data
if(
all(
Expand Down