Skip to content

Instantly share code, notes, and snippets.

@hinke
Created November 29, 2012 23:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hinke/4172534 to your computer and use it in GitHub Desktop.
Save hinke/4172534 to your computer and use it in GitHub Desktop.
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
@johnstonian
Copy link

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