Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth authorisation with rlist #81

Open
pssguy opened this issue Oct 22, 2014 · 12 comments
Open

OAuth authorisation with rlist #81

pssguy opened this issue Oct 22, 2014 · 12 comments

Comments

@pssguy
Copy link

pssguy commented Oct 22, 2014

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

@renkun-ken
Copy link
Owner

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?

@timelyportfolio
Copy link
Contributor

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.

@renkun-ken
Copy link
Owner

Thanks @timelyportfolio!

@pssguy
Copy link
Author

pssguy commented Oct 22, 2014

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

@timelyportfolio
Copy link
Contributor

I forgot there is a httr OAuth demo specific to github.

@renkun-ken
Copy link
Owner

Thanks, @timelyportfolio! I tried the demo and it works for me :)

Let's see how we can make it easier in rlist.

@renkun-ken renkun-ken added this to the 0.4 milestone Oct 30, 2014
@renkun-ken renkun-ken removed this from the 0.4 milestone Jan 23, 2015
@jennybc
Copy link

jennybc commented Apr 10, 2015

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.

@renkun-ken
Copy link
Owner

Thanks, @jennybc! It seems not straightforward to make it an one-click-and-go feature.

@jennybc
Copy link

jennybc commented Apr 11, 2015

@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)

@renkun-ken
Copy link
Owner

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.

@jennybc
Copy link

jennybc commented Apr 11, 2015

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.

@renkun-ken
Copy link
Owner

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants