Commit 9377d0c4 authored by Laura A DeCicco's avatar Laura A DeCicco Committed by GitHub
Browse files

Merge pull request #292 from ldecicco-USGS/master

http -> https
parents 2bc250c4 cd285ee2
Package: dataRetrieval
Type: Package
Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data
Version: 2.6.1
Date: 2016-08-26
Version: 2.6.3
Date: 2016-12-06
Authors@R: c( person("Robert", "Hirsch", role = c("aut"),
email = "rhirsch@usgs.gov"),
person("Laura", "DeCicco", role = c("aut","cre"),
......@@ -25,11 +25,10 @@ Copyright: This software is in the public domain because it contains materials
that originally came from the United States Geological Survey, an agency of
the United States Department of Interior. For more information, see the
official USGS copyright policy at
http://www.usgs.gov/visual-id/credit_usgs.html#copyright
https://www2.usgs.gov/visual-id/credit_usgs.html#copyright
Depends:
R (>= 3.0)
Imports:
XML,
httr (>= 1.0.0),
curl,
reshape2,
......
......@@ -6,7 +6,7 @@ pkg.env <- new.env()
}
.onAttach = function(libname, pkgname){
packageStartupMessage("Recent changes to NWIS data may affect dataRetrieval output.
Please see http://help.waterdata.usgs.gov/news/061016
packageStartupMessage("USGS is switching from http to https:
Please see https://help.waterdata.usgs.gov/news/December%205%2C%202016
for more information.")
}
......@@ -27,33 +27,47 @@
#' }
getWebServiceData <- function(obs_url, ...){
returnedList <- RETRY("GET",obs_url, ..., user_agent(default_ua()))
returnedList <- tryCatch({
RETRY("GET",obs_url, ..., user_agent(default_ua()))
}, error = function(e){
NULL
})
if(is.null(returnedList)){
message("Switching from https to http")
obs_url <- gsub("https", "http", obs_url)
returnedList <- tryCatch({
RETRY("GET",obs_url, ..., user_agent(default_ua()))
}, error = function(e){
NULL
})
}
if(status_code(returnedList) != 200){
message("For: ", obs_url,"\n")
stop_for_status(returnedList)
} else {
headerInfo <- headers(returnedList)
if(status_code(returnedList) != 200){
message("For: ", obs_url,"\n")
stop_for_status(returnedList)
} else {
headerInfo <- headers(returnedList)
if(headerInfo$`content-type` == "text/tab-separated-values;charset=UTF-8"){
returnedDoc <- content(returnedList, type="text",encoding = "UTF-8")
} else if (headerInfo$`content-type` == "text/html"){
txt <- readBin(returnedList$content, character())
message(txt)
return(txt)
} else {
returnedDoc <- content(returnedList,encoding = "UTF-8")
if(grepl("No sites/data found using the selection criteria specified", returnedDoc)){
message(returnedDoc)
}
if(headerInfo$`content-type` == "text/tab-separated-values;charset=UTF-8"){
returnedDoc <- content(returnedList, type="text",encoding = "UTF-8")
} else if (headerInfo$`content-type` == "text/html"){
txt <- readBin(returnedList$content, character())
message(txt)
return(txt)
} else {
returnedDoc <- content(returnedList,encoding = "UTF-8")
if(grepl("No sites/data found using the selection criteria specified", returnedDoc)){
message(returnedDoc)
}
}
attr(returnedDoc, "headerInfo") <- headerInfo
attr(returnedDoc, "headerInfo") <- headerInfo
return(returnedDoc)
}
return(returnedDoc)
}
}
default_ua <- function() {
......
......@@ -11,7 +11,7 @@
#' Possible values to provide are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
#' "America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla"
#' @return retval dataframe raw data returned from the Water Quality Portal. Additionally, a POSIXct dateTime column is supplied for
#' start and end times, and converted to UTC. See \url{https://www.waterqualitydata.us/portal_userguide.jsp} for more information.
#' start and end times, and converted to UTC. See \url{http://www.waterqualitydata.us/portal_userguide/} for more information.
#' @export
#' @seealso \code{\link{readWQPdata}}, \code{\link{readWQPqw}}, \code{\link{whatWQPsites}}
#' @import utils
......
......@@ -40,15 +40,15 @@ access = match.arg(access, c('public','internal','cooperator','USGS'))
message('setting access to public')
}
pkg.env$site = "http://waterservices.usgs.gov/nwis/site/"
pkg.env$iv = "http://waterservices.usgs.gov/nwis/iv/"
pkg.env$dv = "http://waterservices.usgs.gov/nwis/dv/"
pkg.env$gwlevels = "http://waterservices.usgs.gov/nwis/gwlevels/"
pkg.env$measurements = "http://waterdata.usgs.gov/nwis/measurements/"
pkg.env$peak = "http://nwis.waterdata.usgs.gov/usa/nwis/peak/"
pkg.env$rating = "http://waterdata.usgs.gov/nwisweb/get_ratings/"
pkg.env$qwdata = "http://nwis.waterdata.usgs.gov/nwis/qwdata"
pkg.env$stat = "http://waterservices.usgs.gov/nwis/stat/"
pkg.env$site = "https://waterservices.usgs.gov/nwis/site/"
pkg.env$iv = "https://waterservices.usgs.gov/nwis/iv/"
pkg.env$dv = "https://waterservices.usgs.gov/nwis/dv/"
pkg.env$gwlevels = "https://waterservices.usgs.gov/nwis/gwlevels/"
pkg.env$measurements = "https://waterdata.usgs.gov/nwis/measurements/"
pkg.env$peak = "https://nwis.waterdata.usgs.gov/usa/nwis/peak/"
pkg.env$rating = "https://waterdata.usgs.gov/nwisweb/get_ratings/"
pkg.env$qwdata = "https://nwis.waterdata.usgs.gov/nwis/qwdata"
pkg.env$stat = "https://waterservices.usgs.gov/nwis/stat/"
options(Access.dataRetrieval = access)
}
......
......@@ -2,7 +2,7 @@
=============
Retrieval functions for USGS and EPA hydrologic and water quality data. For tutorial information, see:
[http://owi.usgs.gov/R/dataRetrieval.html](http://owi.usgs.gov/R/dataRetrieval.html)
[https://owi.usgs.gov/R/dataRetrieval.html](https://owi.usgs.gov/R/dataRetrieval.html)
##Package Installation
To install the dataRetrieval package, you must be using R 3.0 or greater and run the following command:
......@@ -13,7 +13,7 @@ install.packages("dataRetrieval")
To get inter-CRAN release updates, use the command:
```r
install.packages("dataRetrieval",repos="http://owi.usgs.gov/R")
install.packages("dataRetrieval",repos="https://owi.usgs.gov/R")
```
To get cutting-edge changes, install from GitHub using the `devtools` packages:
......@@ -49,7 +49,7 @@ Follow `@USGS-R` on Twitter for updates on all USGS R packages:
##Disclaimer
This software is in the public domain because it contains materials that originally came from the U.S. Geological Survey, an agency of the United States Department of Interior. For more information, see the [official USGS copyright policy](http://www.usgs.gov/visual-id/credit_usgs.html#copyright/ "official USGS copyright policy")
This software is in the public domain because it contains materials that originally came from the U.S. Geological Survey, an agency of the United States Department of Interior. For more information, see the [official USGS copyright policy](https://www.usgs.gov/visual-id/credit_usgs.html#copyright/ "official USGS copyright policy")
Although this software program has been used by the U.S. Geological Survey (USGS), no warranty, expressed or implied, is made by the USGS or the U.S. Government as to the accuracy and functioning of the program and related program material nor shall the fact of distribution constitute any such warranty, and no responsibility is assumed by the USGS in connection therewith.
......
......@@ -18,7 +18,7 @@ Possible values to provide are "America/New_York","America/Chicago", "America/De
}
\value{
retval dataframe raw data returned from the Water Quality Portal. Additionally, a POSIXct dateTime column is supplied for
start and end times, and converted to UTC. See \url{https://www.waterqualitydata.us/portal_userguide.jsp} for more information.
start and end times, and converted to UTC. See \url{http://www.waterqualitydata.us/portal_userguide/} for more information.
}
\description{
Imports data from the Water Quality Portal based on a specified url.
......
......@@ -123,11 +123,12 @@ test_that("External importWaterML1 test", {
#raw XML
url <- constructNWISURL(service = 'dv', siteNumber = '02319300', parameterCd = "00060",
startDate = "2014-01-01", endDate = "2014-01-01")
raw <- content(GET(url), as = 'raw')
rawParsed <- importWaterML1(raw)
expect_true(nrow(rawParsed) > 0)
expect_true(data.class(rawParsed$X_00060_00003) == "numeric")
# Will put back when https is converted:
# raw <- content(GET(url), as = 'raw')
# rawParsed <- importWaterML1(raw)
# expect_true(nrow(rawParsed) > 0)
# expect_true(data.class(rawParsed$X_00060_00003) == "numeric")
#
#no data
url <- constructNWISURL("05212700", "00060", "2014-01-01", "2014-01-10",'dv', statCd = "00001")
noData <- importWaterML1(url)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment