What's the easiest way to use OAuth with ActiveResource? - ruby-on-rails

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!

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.

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.

Related

I want to add a Facebook style messenger to my Ruby on Rails application so Users from the User model can have a conversation with each other

So right now I have a basic CRUD app using Devise. I have a User model I generated with it. I want to know what the best way would be to add a messenger component to it similar to Facebooks so users can talk with each other. What would if possible be the best way to accomplish this within Rails?
You can probably easily take advantage of Action Cable, to use existing Rails WebSocket functionality and get it good enough.
If you really want to make it like Facebook, you will need to use MQTT. I have no experience with it, but https://github.com/njh/ruby-mqtt purports to be a pure Ruby gem that implements the MQTT protocol.

Ember.JS w/ Rails JSON API - two separate APIs? One for UI one for connecting 'apps'?

Related to this question but looking for a more current set of recommendations w/ Rails 4 and Ember.js.
Is it better to use one, versioned API for users to connect via the Ember UI as well as for 'applications' to use w/ an API key or something? Or would it be better to create two, distinct APIs for this? (i.e. two sets of controllers that have the appropriate restrictions.)
The first is more desirable = less work.
The second just seems to solve problems handling authentication via Devise or the API key, etc.
I know there isn't an objective answer to this so I beg everyone's pardon in advance. I appreciate all reasoned input.
There are probably some situations where it might make sense to have two separate APIs but if your only reason is for authentication, I don't think it would make sense.
You should look into something like Doorkeeper that allows you to act as an Oauth2 provider, similar to Twitter, Facebook, and Google. Doorkeeper can be used with Devise and allows you to create both user specific access tokens as well as create applications which have their own access tokens.
There's also a Railscast about using Doorkeeper.

How to use a Google API as my model?

I would like to use the Google Books API as the model for one of the controllers in my Rails app. Basically -I would still like this to act as a scaffold (though I won't be posting to / modifying it)
But I would still like to have a Book object, and be able to do a Book.find([google_book_id]).
What is the best way to go about setting something like this up? Should I generate a scaffold?
Since the Google Books API seems to be a typical REST service, I would start by looking at ActiveResource. It's a way of implementing ActiveRecord-ish models where the data is stored in an external service instead of your database. If you set up a Book model using ActiveResource, you would indeed be able to call Book.find(google_book_id) and have it return a Book object with the properties returned from the API.
Since I've never used ActiveResource myself I can't offer you much advice on the details, but it looks like you would need a way to either use OAuth or add an API key parameter to each request.

Structure my application for web interface and API

I have a web application that also provides an API. The API is fairly simple, so I am just handling it in the respond_to block and returning json if requested. Now I want to version my API. I was looking at versionist gem. This mentions using the api_version method in your config/routes.rb to change routes based on API version. I don't understand this though, since I would think the routes would be the same, but the behavior of the response would change.
My question is, do I need separate controllers for my web and API portions? Also, do I need a separate namespace for the API? Or is there a way to keep things as they are now?
There are some things you'd want to do differently when providing an API. One of them is the ability to set an API version so that you can enhance your API by adding a new version without breaking existing clients. If your API is extremely simple you can achieve this by providing a second set of routes that will include the version. You may use versionist for that. However, when you'll need to add versions, the simplest solution (and the one that keeps concerns well separated) will be to hold a separate set of controllers, and keep them thin so there is no code duplication. This may allow you to use additional gems for the API (e.g. RABL, JBuilder or rocketpants). There are railscasts on each of them, I recommend watching them to get some background on API building.

Simplest way to allow posting to a Rails site using MarsEdit/Ecto/etc?

I have a simple site, using restful_authentication and a simple model for the posts. I would like to use MarsEdit (or something like Ecto) to post/edit content. How would I go about this?
The XML-RPC system is rather bewildering - there's a lot of different variations (Atom, MovableType, metaWeblog, Blogger, TypePad, probably others), never mind actually implementing any of them.. The Action Web Service API in Rails, which is intended to implement such APIs, has deprecated a while ago..
Try a plugin...
http://github.com/calavera/atompub-server/tree/master
Or this library...
http://github.com/inkspot/alumina/tree/master
As a starter/prototype for what you need

Resources