Skip to content

Commit

Permalink
cran
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpe committed Aug 30, 2015
1 parent 9d8781d commit b89638d
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 193 deletions.
173 changes: 87 additions & 86 deletions R/API.R
Original file line number Diff line number Diff line change
@@ -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)
}

}
50 changes: 20 additions & 30 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -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.

31 changes: 31 additions & 0 deletions vignettes/Tutorial.R
Original file line number Diff line number Diff line change
@@ -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())

Loading

0 comments on commit b89638d

Please sign in to comment.