Skip to content

Instantly share code, notes, and snippets.

@abicky
Created November 19, 2011 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abicky/1378878 to your computer and use it in GitHub Desktop.
Save abicky/1378878 to your computer and use it in GitHub Desktop.
patch for ROAuth package
diff -cr ROAuth.orig/R/ROauth.R ROAuth/R/ROauth.R
*** ROAuth.orig/R/ROauth.R 2011-06-03 13:10:28.000000000 +0900
--- ROAuth/R/ROauth.R 2011-11-19 19:13:36.000000000 +0900
***************
*** 128,146 ****
auth <- signRequest(url, params, consumerKey, consumerSecret,
oauthKey=oauthKey, oauthSecret=oauthSecret,
httpMethod="POST", signMethod=signMethod)
opts <- list(...)
## post ,specify the method
- ## We should be able to use postForm() but we have to work out the issues
- ## with escaping, etc. to match the signature mechanism.
- if(TRUE) {
- reader <- dynCurlReader(curl, baseURL = url, verbose = FALSE)
- fields <- paste(names(auth), sapply(auth, curlPercentEncode),
- sep = "=", collapse = "&")
- curlPerform(curl = curl, URL = url, postfields = fields,
- writefunction = reader$update, ...)
- reader$value()
- } else
postForm(url, .params = c(params, lapply(auth, I)), curl = curl,
.opts = opts, style = "POST")
}
--- 128,137 ----
auth <- signRequest(url, params, consumerKey, consumerSecret,
oauthKey=oauthKey, oauthSecret=oauthSecret,
httpMethod="POST", signMethod=signMethod)
+ auth$oauth_signature <- encodeURI(auth$oauth_signature)
opts <- list(...)
## post ,specify the method
postForm(url, .params = c(params, lapply(auth, I)), curl = curl,
.opts = opts, style = "POST")
}
diff -cr ROAuth.orig/R/sign.R ROAuth/R/sign.R
*** ROAuth.orig/R/sign.R 2011-06-03 13:10:28.000000000 +0900
--- ROAuth/R/sign.R 2011-11-19 19:11:10.000000000 +0900
***************
*** 2,13 ****
oauthKey = "", oauthSecret = "", httpMethod = "GET",
signMethod = "HMAC", nonce = genNonce(),
timestamp = Sys.time(),
! escapeFun = curlPercentEncode) {
## Sign an request made up of the URL, the parameters as a named character
## vector the consumer key and secret and the token and token secret.
httpMethod <- toupper(httpMethod)
signMethod <- toupper(signMethod)
!
params["oauth_nonce"] <- nonce
params["oauth_timestamp"] <- as.integer(timestamp)
--- 2,14 ----
oauthKey = "", oauthSecret = "", httpMethod = "GET",
signMethod = "HMAC", nonce = genNonce(),
timestamp = Sys.time(),
! escapeFun = encodeURI) {
## Sign an request made up of the URL, the parameters as a named character
## vector the consumer key and secret and the token and token secret.
httpMethod <- toupper(httpMethod)
signMethod <- toupper(signMethod)
!
! params <- sapply(params, escapeFun, simplify = FALSE)
params["oauth_nonce"] <- nonce
params["oauth_timestamp"] <- as.integer(timestamp)
***************
*** 28,34 ****
## the resulting % prefix in the escaped characters, e.g. %20 becomes
## %2520 as %25 is the escape for %
params <- params[order(names(params))]
! args <- paste(names(params), sapply(params, escapeFun, post.amp = TRUE),
sep = "%3D", collapse = "%26")
if(is.null(oauthSecret))
--- 29,35 ----
## the resulting % prefix in the escaped characters, e.g. %20 becomes
## %2520 as %25 is the escape for %
params <- params[order(names(params))]
! args <- paste(names(params), sapply(params, escapeFun),
sep = "%3D", collapse = "%26")
if(is.null(oauthSecret))
***************
*** 42,48 ****
sig <- signString(odat, okey, signMethod)
! params["oauth_signature"] <- sig # curlPercentEncode(sig)
params[grepl("^oauth_", names(params))]
}
--- 43,49 ----
sig <- signString(odat, okey, signMethod)
! params["oauth_signature"] <- sig
params[grepl("^oauth_", names(params))]
}
***************
*** 98,100 ****
--- 99,117 ----
signWithPlaintext <- function(key, data) {
key
}
+
+ encodeURI <- function(URI) {
+ if (!is.character(URI)) {
+ URI
+ } else {
+ OK <- "[^-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.~]"
+ x <- strsplit(URI, "")[[1L]]
+ z <- grep(OK, x)
+ if (length(z)) {
+ y <- sapply(x[z], function(x) paste("%", toupper(as.character(charToRaw(x))),
+ sep = "", collapse = ""))
+ x[z] <- y
+ }
+ paste(x, collapse = "")
+ }
+ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment