From b89638d3a7a1c5e49ec0874d80e51dcf9b4be8fb Mon Sep 17 00:00:00 2001 From: dmpe Date: Sun, 30 Aug 2015 10:43:19 +0200 Subject: [PATCH] cran --- R/API.R | 173 +++++++++++++++++++++-------------------- cran-comments.md | 50 +++++------- vignettes/Tutorial.R | 31 ++++++++ vignettes/Tutorial.Rmd | 154 ++++++++++++++++++------------------ 4 files changed, 215 insertions(+), 193 deletions(-) create mode 100644 vignettes/Tutorial.R diff --git a/R/API.R b/R/API.R index c462d26..fc40b96 100644 --- a/R/API.R +++ b/R/API.R @@ -1,86 +1,87 @@ -#' @title Authentication -#' -#' @description Methods for setting your Wufoo Name & API Key, permanently. For both of them visit your -#' profile. For API Key go to \code{https://yourName.wufoo.com/api/code/1/} -#' -#' @author The code for these methods has been developed by Scott Chamberlain \url{https://github.com/sckott} for his -#' \url{https://github.com/ropensci/rnoaa} package. His copyright! -#' -#' @param x - an empty parameter, e.g. NULL -#' -#' @note Wufoo currently restricts your API usage to 5000 requests per day. -#' -#' @examples -#' options(Wufoo_Name = "johnmalc", Wufoo_API = "F1QH-Q64B-BSBI-JASJ") -#' -#' @export -auth_name <- function(x) { - tmp <- if(is.null(x)) { - Sys.getenv("Wufoo_Name", "") - } else x - - if(tmp == "") { - getOption("Wufoo_Name", stop("you need to set up your wofoo name")) - } else tmp -} - -#' @rdname auth_name -#' @export -auth_key <- function(x) { - tmp <- if(is.null(x)) { - Sys.getenv("Wufoo_API", "") - } else x - - if(tmp == "") { - getOption("Wufoo_API", stop("you need to set up your wofoo api key")) - } else tmp -} - -#' @title Generalized function for executing GET requests by always appending user's API Key. -#' -#' @param url - which is used for the request -#' @param apiKey - uses the passed api key of the user -#' @param queryParameters - parameters that are used for building a URL -#' @param showURL - for debugging purposes only: it shows what URL has been called -#' -#' @import httr -#' @import jsonlite -#' -#' @noRd -doRequest <- function(url, queryParameters = NULL, apiKey = auth_key(NULL), showURL = NULL, debugConnection = 0L) { - - if (is.null(apiKey)) { - stop("Please assign your API Key", call. = FALSE) - } else { - - # https://github.com/wufoo/Wufoo-PHP-API-Wrapper/blob/master/WufooApiWrapperBase.php#L102 - # http://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html - # https://stackoverflow.com/questions/28622558/how-to-solve-error-ssl23-get-server-hellosslv3-alert-handshake-failure - if(.Platform$OS.type == "windows") { - getResponse <- GET(url = url, query = queryParameters, - config(userpwd = paste0(apiKey,":fakepassword"), ssl_cipher_list = "TLSv1", - ssl_verifypeer=0L, ssl_verifyhost=0L, followlocation=1L, verbose=debugConnection)) - } else { - getResponse <- GET(url = url, query = queryParameters, - config(userpwd = paste0(apiKey,":fakepassword"), - ssl_verifypeer=0L, ssl_verifyhost=0L, followlocation=1L, verbose=debugConnection)) - - } - stop_for_status(getResponse) - - rawTextResponse <- content(getResponse, as = "text") - - if (grepl("application/json", getResponse$headers$`content-type`)) { - response <- fromJSON(rawTextResponse) - } else { - response <- rawTextResponse - } - - if (identical(showURL, TRUE)) { - cat("The requested URL has been this: ", getResponse$url, "\n") - } - - return(response) - } - -} +#' @title Authentication +#' +#' @description Methods for setting your Wufoo Name & API Key, permanently. For both of them visit your +#' profile. For API Key go to \code{https://yourName.wufoo.com/api/code/1/} +#' +#' @author The code for these methods has been developed by Scott Chamberlain \url{https://github.com/sckott} for his +#' \url{https://github.com/ropensci/rnoaa} package. His copyright! +#' +#' @param x - an empty parameter, e.g. NULL +#' +#' @note Wufoo currently restricts your API usage to 5000 requests per day. +#' +#' @examples +#' options(Wufoo_Name = "johnmalc", Wufoo_API = "F1QH-Q64B-BSBI-JASJ") +#' +#' @export +auth_name <- function(x) { + tmp <- if(is.null(x)) { + Sys.getenv("Wufoo_Name", "") + } else x + + if(tmp == "") { + getOption("Wufoo_Name", stop("you need to set up your wofoo name")) + } else tmp +} + +#' @rdname auth_name +#' @export +auth_key <- function(x) { + tmp <- if(is.null(x)) { + Sys.getenv("Wufoo_API", "") + } else x + + if(tmp == "") { + getOption("Wufoo_API", stop("you need to set up your wofoo api key")) + } else tmp +} + +#' @title Generalized function for executing GET requests by always appending user's API Key. +#' +#' @param url - which is used for the request +#' @param apiKey - uses the passed api key of the user +#' @param queryParameters - parameters that are used for building a URL +#' @param showURL - for debugging purposes only: it shows what URL has been called +#' +#' @import httr +#' @import jsonlite +#' +#' @noRd +doRequest <- function(url, queryParameters = NULL, apiKey = auth_key(NULL), showURL = NULL, debugConnection = 0L) { + + if (is.null(apiKey)) { + stop("Please assign your API Key", call. = FALSE) + } else { + + # https://github.com/wufoo/Wufoo-PHP-API-Wrapper/blob/master/WufooApiWrapperBase.php#L102 + # http://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html + # https://stackoverflow.com/questions/28622558/how-to-solve-error-ssl23-get-server-hellosslv3-alert-handshake-failure + + if (.Platform$OS.type == "windows") { + getResponse <- GET(url = url, query = queryParameters, + config(userpwd = paste0(apiKey,":fakepassword"), ssl_cipher_list = "TLSv1", + ssl_verifypeer=0L, ssl_verifyhost=0L, followlocation=1L, verbose=debugConnection)) + } else { + getResponse <- GET(url = url, query = queryParameters, + config(userpwd = paste0(apiKey,":fakepassword"), + ssl_verifypeer=0L, ssl_verifyhost=0L, followlocation=1L, verbose=debugConnection)) + + } + stop_for_status(getResponse) + + rawTextResponse <- content(getResponse, as = "text") + + if (grepl("application/json", getResponse$headers$`content-type`)) { + response <- fromJSON(rawTextResponse) + } else { + response <- rawTextResponse + } + + if (identical(showURL, TRUE)) { + cat("The requested URL has been this: ", getResponse$url, "\n") + } + + return(response) + } + +} diff --git a/cran-comments.md b/cran-comments.md index 805a47a..c408792 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,30 +1,20 @@ -## Test environments -* Ubuntu 15.04 (+ travis-ci), R 3.1.2 -* Windows 10 (3.2.1-patched) - -## This is a resubmission -Dear Mr.Ligges, - -* `@import utils` has been addeded -* Description has been improved - - -## R CMD check results -There were no ERRORs or WARNINGs. - -There were 2 NOTEs: - -* New submission -Found the following (possibly) invalid URLs: - URL: http://cran.r-project.org/package=WufooR - From: README.md - Status: 404 - Message: Not Found - -* No repository set, so cyclic dependency check skipped - -(This is my first release of [WufooR](https://github.com/dmpe/WufooR)) - -## Downstream dependencies -There are no downstream dependencies because this is the first release. - +## Test environments +* Ubuntu 15.04 (+ travis-ci) +* Windows 8 (3.2.2-release) + +## This is a submission +Dear CRAN Maintainers, + +I have updated my package inline with Mr. Ripley (email 28th of Aug. 2015) comments about fedora checks. +This package has been tested on fedora, ubuntu and windows 8; always with the latest release of R. + +## R CMD check results +There were no ERRORs or WARNINGs. + +There were 1 NOTE: + +* No repository set, so cyclic dependency check skipped + +## Downstream dependencies +There are no downstream dependencies. + diff --git a/vignettes/Tutorial.R b/vignettes/Tutorial.R new file mode 100644 index 0000000..f7952b2 --- /dev/null +++ b/vignettes/Tutorial.R @@ -0,0 +1,31 @@ +## ------------------------------------------------------------------------ +library(WufooR) + +options(Wufoo_Name = "johnmalc", Wufoo_API = "F1QH-Q64B-BSBI-JASJ") + +## ------------------------------------------------------------------------ +auth_name(NULL) +auth_key(NULL) + +## ------------------------------------------------------------------------ +t(user_info()) + +## ------------------------------------------------------------------------ +t(form_info()) + +# Show responses to the form +fe_1 <- form_entries(formIdentifier = "z5kqx7h1gtvg4g") +t(fe_1) + +sapply(fe_1, class) + +## ------------------------------------------------------------------------ +# How many responses did you get ? +form_entriesCount(formIdentifier = "z5kqx7h1gtvg4g") + +## ------------------------------------------------------------------------ +fields_info(formIdentifier = "z5kqx7h1gtvg4g", showRequestURL = TRUE) + +## ------------------------------------------------------------------------ +t(reports_info()) + diff --git a/vignettes/Tutorial.Rmd b/vignettes/Tutorial.Rmd index 1e80dac..de0e0c4 100644 --- a/vignettes/Tutorial.Rmd +++ b/vignettes/Tutorial.Rmd @@ -1,77 +1,77 @@ ---- -title: "Tutorial for WufooR" -author: "dmpe @ github" -date: "`r Sys.Date()`" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{Vignette Title} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -## Authentication - -To access data from your surways, you firstly need to store your login name (subdomain) and API Key. This can be done in two ways as described below. - -Initially, this has been written by [Scott Chamberlain](https://github.com/sckott), who wrote it in the NEWS file of his `rnoaa` [package](https://github.com/ropensci/rnoaa/blob/master/NEWS.md). I have addapted the names of my functions accordingly. - -PS: Don't use my key, of course. - -> A new helper function `auth_name()/auth_api()` looks for one of two stored keys, as an -environment variable under the name `Wufoo_Name`/`Wufoo_API`, or an option variable under the name -`Wufoo_Name`/`Wufoo_API`. - -> Environment variables can be set during session like `Sys.setenv(VAR = "...")`, -or stored long term in your `.Renviron` file. Option variables can be set during session -like `options(var = "...")`, or stored long term in your `.Rprofile` file. - -```{r} -library(WufooR) - -options(Wufoo_Name = "johnmalc", Wufoo_API = "F1QH-Q64B-BSBI-JASJ") -``` - -Print information about my name & api key. - -```{r} -auth_name(NULL) -auth_key(NULL) -``` - -## Use Cases - -Let's print some information about the user. - -```{r} -t(user_info()) -``` - -And now about the forms you have access to. - -```{r} -t(form_info()) - -# Show responses to the form -fe_1 <- form_entries(formIdentifier = "z5kqx7h1gtvg4g") -t(fe_1) - -sapply(fe_1, class) -``` - -```{r} -# How many responses did you get ? -form_entriesCount(formIdentifier = "z5kqx7h1gtvg4g") -``` - -Show its fields, with the requested URL (for debug purposes). - -```{r} -fields_info(formIdentifier = "z5kqx7h1gtvg4g", showRequestURL = TRUE) -``` - -Do you have some reports ? If yes, then show me information about them. - -```{r} -t(reports_info()) -``` - +--- +title: "Tutorial for WufooR" +author: "dmpe @ github" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Vignette Title} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +## Authentication + +To access data from your surways, you firstly need to store your login name (subdomain) and API Key. This can be done in two ways as described below. + +Initially, this has been written by [Scott Chamberlain](https://github.com/sckott), who wrote it in the NEWS file of his `rnoaa` [package](https://github.com/ropensci/rnoaa/blob/master/NEWS.md). I have addapted the names of my functions accordingly. + +PS: Don't use my key, of course. + +> A new helper function `auth_name()/auth_api()` looks for one of two stored keys, as an +environment variable under the name `Wufoo_Name`/`Wufoo_API`, or an option variable under the name +`Wufoo_Name`/`Wufoo_API`. + +> Environment variables can be set during session like `Sys.setenv(VAR = "...")`, +or stored long term in your `.Renviron` file. Option variables can be set during session +like `options(var = "...")`, or stored long term in your `.Rprofile` file. + +```{r} +library(WufooR) + +options(Wufoo_Name = "johnmalc", Wufoo_API = "F1QH-Q64B-BSBI-JASJ") +``` + +Print information about my name & api key. + +```{r} +auth_name(NULL) +auth_key(NULL) +``` + +## Use Cases + +Let's print some information about the user. + +```{r} +t(user_info()) +``` + +And now about the forms you have access to. + +```{r} +t(form_info()) + +# Show responses to the form +fe_1 <- form_entries(formIdentifier = "z5kqx7h1gtvg4g") +t(fe_1) + +sapply(fe_1, class) +``` + +```{r} +# How many responses did you get ? +form_entriesCount(formIdentifier = "z5kqx7h1gtvg4g") +``` + +Show its fields, with the requested URL (for debug purposes). + +```{r} +fields_info(formIdentifier = "z5kqx7h1gtvg4g", showRequestURL = TRUE) +``` + +Do you have some reports ? If yes, then show me information about them. + +```{r} +t(reports_info()) +``` +