Created
November 29, 2012 23:06
-
-
Save hinke/4172534 to your computer and use it in GitHub Desktop.
Ruby Readmill oAuth methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great gist, hinke!
If you are looking for a php example. see my gist here: https://gist.github.com/4204947