Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the easiest way to use OAuth with ActiveResource?

I'm working with some old code and using ActiveResource for a very basic Twitter integration. I'd like to touch the app code as little as possible and just bring OAuth in while still using ActiveResource.

Unfortunately I'm finding no easy way to do this. I did run into the oauth-active-resource gem, but it's not exactly documented and it appears to be designed for creating full-on API wrapper libraries. As you can imagine, I'd like to avoid creating a whole Twitter ActiveResource API wrapper for this one legacy change.

Any success stories out there? In my instance, it might be quicker to just leave ActiveResource rather than get this working. I'm happy to be proven wrong!

like image 730
Barry Hess Avatar asked May 28 '10 20:05

Barry Hess


2 Answers

I had the same problem and built this simple gem to handle it:

https://github.com/albertopq/oauth-activeresource

You just need to use the oauth gem to retrieve the access token, and assign the final http object to your model. It will use that object instead the ActiveResource::Connection one.

Hope it helps.

like image 148
albertopq Avatar answered Nov 15 '22 03:11

albertopq


I just did this with omniauth and it was surprisingly easy. This screencast and a subsequent one walks you through it. All I needed was an initializer, a controller with login/logout actions and some attributes on my user model to store the Twitter id and screen name.

like image 44
Brian Deterling Avatar answered Nov 15 '22 05:11

Brian Deterling