Hi,
I recently finished a VERY simple implementation of DA on Rails with the OAuth gem. I figured some people might be interested in some working code. To test, go to http://URL_TO_RAILS_APP/myspace and it will redirect you to authorize. Then, it will print the raw JSON to the screen. Note that the OAuth library does not currently support oauth_callback, and we must manually append it. The code below will run fine with the default routes.
myspace_controller.rb
require 'oauth/consumer'
class MyspaceController < ApplicationController
def index
@consumer = OAuth::Consumer.new("CONSUMER_KEY","CONSUMER_SECRET", {
:http_method=>"get",
:site=>"http://api.myspace.com",
:request_token_path=>"/request_token",
:access_token_path=>"/access_token",
:authorize_path=>"/authorize"
})
@request_token=@consumer.get_request_token
session[:request_token]=@request_token
redirect_to @request_token.authorize_url+"&oauth_callback="+CGI.escape("http://URL_TO_RAILS_APP/myspace/callback")
end
def callback
@request_token=session[:request_token]
@access_token=@request_token.get_access_token
@myspace_person=@access_token.get "/v2/people/@me/@self?format=json"
@myspace_friends=@access_token.get "/v2/people/@me/@friends?format=json"
end
end
callback.html.erb
<h1>Myspace#callback</h1>
<p><%= @myspace_person.body %></p>
<p><%= @myspace_friends.body %></p>
<p><%= @myspace_activities.body %></p>