Open pssguy opened 9 years ago
Thanks, @pssguy! I think it is necessary for rlist to support OAuth to work with data APIs smoothly, but I don't have much experience on it. Would you please give some suggestions or send PR if you know how to do it. I also wonder if different data sources have different OAuth methods?
Would strongly suggest just plugging into the OAuth from httr
https://github.com/hadley/httr rather than rebuilding. I can try to work up some examples.
Thanks @timelyportfolio!
Thanks tp. @renkun There was this stackoverflow question but may be out of date now http://stackoverflow.com/questions/13169305/httr-github-api-callback-url-issues
I forgot there is a httr
OAuth demo specific to github.
Thanks, @timelyportfolio! I tried the demo and it works for me :)
Let's see how we can make it easier in rlist.
In this specific case, there is probably a way to combine usage of rlist
and functions from the github
package, which confusingly resides a repo named rgithub
(note the r
). github
will handle the authentication this way, which doesn't seem like a natural fit for rlist
.
Thanks, @jennybc! It seems not straightforward to make it an one-click-and-go feature.
@renkun-ken Do you mean it's hard to integrate Ouath into rlist or that you're skeptical about the suggestion to combine github
and rlist? I keep the relevant GitHub access token in an envvar, create an explicit GitHub "context" (jargon from the github
package), then simply use all the wrapped API calls w/o thinking about auth again. The authorization workflow will be so different for different APIs that I can't imagine you would want to get into that w/ rlist.
Here's a sketch where I am, shamefully, not using rlist, but I think you can see where rlist functions could be dropped in. Maybe you could add a suggestion to use github
and authenticate if someone gets inspired by your tutorial and hits the rate-limit. I think API work is a very interesting application of rlist -- you know my struggles with traversing pages!
library(plyr)
library(github)
# GITHUB_TOKEN envvar is defined in my ~/.Renviron
ctx <- create.github.context(access_token = Sys.getenv("GITHUB_TOKEN"))
# now do whatever I want w/ the API
# iss_dat <- …. a data.frame w/ one row per issue I need to open …..
foo <- alply(iss_dat, 1, function(x) {
# define line1, line2, etc.
list(title = sprintf("Peer review of %s's %s by %s",
x[["reviewee"]], this_hw, x[["reviewer"]]),
body = paste(line1, line2, line3, sep = "\n"),
assignee = x[["reviewer_gitName"]],
labels = c("peer-review", "hw02"),
repo = paste0("zz_", x[["reviewee"]], "_STAT540_2015"))
})
# here's where I could have used rlist::list.map()
ret_val <- llply(foo, function(x) {
repo <- x$repo
x$repo <- NULL
create.issue(owner = "STAT540-UBC", repo = repo, content = x)
})
# and here I could use list.mapv()?
ok <- laply(ret_val, function(x) x$ok)
table(ok)
Thanks for your detailed and helpful information, @jennybc! It's great if rlist can make it easy to work with oauth, but shamefully I don't have much experience on it. I'll take a closer look at your examples and try to figure out a good way to do it.
My advice is "don't get sucked into doing OAuth" within rlist
. Instead, show it playing nicely with API wrapping packages. Which I think it does.
Agree. In your example, there may be no need to load json data to data.frame. list.select
, list.map
, list.mapv
may reduce some code for you.
foo <- list.select(iss_day,
title = sprintf("Peer review of %s's %s by %s", reviewee, this_hw, reviewer),
body = paste(line1, line2, line3, sep = "\n"),
assignee = reviewer_gitName,
labels = c("peer-review", "hw02"),
repo = paste0("zz_", reviewee, "_STAT540_2015"))
ret_val <- list.map(foo,
create.issue(owner = "STAT540-UBC",
repo = repo,
content = list.remove(., "repo")))
ok <- list.mapv(ret_val, ok)
I have been working through your github tutorial example http://renkun.me/rlist-tutorial/Examples/GitHub-API.html and reached the rate limit. Would it be possible to incorporate the required codes as parameters in the list.load function or come up with some other solution. The same issue will apply to other APIs Tx