Skip to content
This repository has been archived by the owner on May 24, 2019. It is now read-only.

Commit

Permalink
deprecate credentials and keypair option (closes #102)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeper committed Dec 18, 2015
1 parent 3fd9c79 commit 1a545bb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: MTurkR
Version: 0.6.19
Date: 2015-11-28
Version: 0.6.20
Date: 2015-12-18
Title: R Client for the MTurk Requester API
Authors@R: c(person("Thomas J.", "Leeper", role = c("aut", "cre"),
email = "thosjleeper@gmail.com"),
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## SIGNIFICANT USER-VISIBLE CHANGES ##

* The use of `credentials()`, and `options("MTurkR.keypair")` are completely deprecated. A warning will now be issued if trying to supply credentials in this way. AWS credentials should be specified in environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. (#102)
* `HITStatus()` will now display any non-empty RequesterAnnotation field for a HIT. (#101)
* The deprecated argument `print`, which was removed in v0.5, has been fully removed. Use `verbose` instead. (#97)
* The deprecated functions `mturkrhelp` and `APIReference` have been removed. (#96)
Expand Down
9 changes: 5 additions & 4 deletions R/onLoad.r
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
options(MTurkR.log = TRUE) # log logical
if(is.null(getOption("MTurkR.test")))
options(MTurkR.test = FALSE) # validation.test logical
a <- Sys.getenv("AWS_ACCESS_KEY_ID")
s <- Sys.getenv("AWS_SECRET_ACCESS_KEY")
if(a != "" & s != "") {
options(MTurkR.keypair = c(a,s))
if (Sys.getenv("AWS_ACCESS_KEY_ID") == "") {
message("Environment variable AWS_ACCESS_KEY_ID not set!")
}
if (Sys.getenv("AWS_SECRET_ACCESS_KEY") == "") {
message("Environment variable AWS_SECRET_ACCESS_KEY not set!")
}
}
20 changes: 11 additions & 9 deletions R/request.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
request <-
function(operation, GETparameters = NULL,
keypair = getOption('MTurkR.keypair'),
keypair = c(Sys.getenv("AWS_ACCESS_KEY_ID"),
Sys.getenv("AWS_SECRET_ACCESS_KEY")),
browser = getOption('MTurkR.browser', FALSE),
log.requests = getOption('MTurkR.log', TRUE),
sandbox = getOption('MTurkR.sandbox', FALSE),
Expand All @@ -9,17 +10,18 @@ function(operation, GETparameters = NULL,
service = "AWSMechanicalTurkRequester",
version = NULL)
{
if(sandbox)
if(sandbox) {
host <- "https://mechanicalturk.sandbox.amazonaws.com/"
else
} else {
host <- "https://mechanicalturk.amazonaws.com/"
if(is.null(keypair)) {
key <- Sys.getenv("AWS_ACCESS_KEY_ID")
secret <- Sys.getenv("AWS_SECRET_ACCESS_KEY")
if(key != "" & secret != "") {
options(MTurkR.keypair = c(key,secret))
}
if(is.null(keypair) | keypair == "" | keypair = c("", "")) {
g <- getOption("MTurkR.keypair")
if (!is.null(g)) {
keypair <- g
warning("Credentials must be set in environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY")
} else {
stop("No keypair provided or 'credentials' object not stored")
stop("No keypair provided.\nPlease set environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY")
}
}
keyid <- keypair[1]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ To install the latest version from CRAN, simply use:
install.packages("MTurkR")
```

Using MTurkR requires setting two environment variables: `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. These can be specified on the command-line when initializing one's R session, using `Sys.setenv()` within R, or by placing these values in an `.Renviron` or `Rprofile.site` file. (Note: this functionality is a more secure replacmeent of the use of the `credentials()` function or `options("MTurkR.keypair")` from earlier versions of MTurkR.)

## Using **MTurkR** ##

The MTurkR documentation files contain minimal examples for all functions. Further examples of how to use MTurkR are provided in [the MTurkR GitHub wiki](https://github.com/leeper/MTurkR/wiki). Users can contribute their own examples or further documentation there, or via pull requests to the GitHub repository.
Expand Down
5 changes: 3 additions & 2 deletions man/request.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
\description{This is the workhorse function that makes authenticated HTTP requests to the MTurk API. It is not exported as of v0.5.}
\usage{
request(operation, GETparameters = NULL,
keypair = getOption('MTurkR.keypair'),
keypair = c(Sys.getenv("AWS_ACCESS_KEY_ID"),
Sys.getenv("AWS_SECRET_ACCESS_KEY")),
browser = getOption('MTurkR.browser', FALSE),
log.requests = getOption('MTurkR.log', TRUE),
sandbox = getOption('MTurkR.sandbox', FALSE),
Expand All @@ -17,7 +18,7 @@ request(operation, GETparameters = NULL,
\arguments{
\item{operation}{The MTurk API operation to be performed.}
\item{GETparameters}{An optional character string containing URL query parameters that specify options for the request.}
\item{keypair}{A two-element character vector containing an AWS Access Key ID and an AWS Secret Access Key. Default is from \code{options('MTurkR.keypair')}.}
\item{keypair}{A two-element character vector containing an AWS Access Key ID and an AWS Secret Access Key. The easiest way to do this is to specify \samp{AWS_ACCESS_KEY_ID} and \samp{AWS_SECRET_ACCESS_KEY} environment variables using \code{Sys.setenv()} or by placing these values in an .Renviron file.}
\item{browser}{Optionally open the request in the default web browser, rather than opening in R. Default is \code{FALSE}.}
\item{log.requests}{A logical specifying whether API requests should be logged. Default is \code{TRUE}. See \code{\link{readlogfile}} for details.}
\item{sandbox}{Optionally execute the request in the MTurk sandbox rather than the live server. Default is \code{FALSE}.}
Expand Down

0 comments on commit 1a545bb

Please sign in to comment.