Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Ruby Readmill oAuth methods
get '/auth/readmill' do
redirect "http://readmill.com/oauth/authorize?response_type=code&client_id=#{settings.readmill_client_id}&redirect_uri=#{settings.readmill_redirect}&scope=non-expiring"
end
get '/callback/readmill' do
token_params = {
:grant_type => 'authorization_code',
:client_id => settings.readmill_client_id,
:client_secret => settings.readmill_client_secret,
:redirect_uri => settings.readmill_redirect,
:code => params[:code],
:scope => 'non-expiring'
}
resp = JSON.parse(RestClient.post("http://readmill.com/oauth/token.json", token_params).to_str) rescue nil
data = {
:user => fetch_and_parse("http://api.readmill.com/me.json", resp['access_token'])
}
user = User.first_or_create({ :readmill_id => data[:user]['id'] })
user.name = data[:user]['username']
user.access_token = resp['access_token']
@access_token = resp['access_token']
user.save!
erb :twitter
end

great gist, hinke!

If you are looking for a php example. see my gist here: https://gist.github.com/4204947

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