Sha256: 8b71996098aa891fc9de8d93bf7d8c19b4007008b48fa138c18115d5d8fa3c05
Contents?: true
Size: 1.13 KB
Versions: 16
Compression:
Stored size: 1.13 KB
Contents
# A simple Sinatra example demonstrating OAuth2 implementation with Geoloqi # This version of the example is powerful! It uses sinatra-synchrony to implement real concurrency with EventMachine. # Your calls to the Geoloqi api will not block the app from serving other requests! # Run this example with Thin (which uses EventMachine under the hood): ruby sinatra_synchrony.rb -s thin # Works on anything that supports Thin (Rack, EY, Heroku, etc..) require 'rubygems' require 'sinatra' require 'sinatra/synchrony' require 'geoloqi' GEOLOQI_REDIRECT_URI = 'http://example.com' enable :sessions configure do Geoloqi.config :client_id => 'YOUR OAUTH CLIENT ID', :client_secret => 'YOUR CLIENT SECRET', :adapter => :em_synchrony end def geoloqi @geoloqi ||= Geoloqi::Session.new :auth => session[:geoloqi_auth] end get '/?' do session[:geoloqi_auth] = geoloqi.get_auth(params[:code], GEOLOQI_REDIRECT_URI) if params[:code] && !geoloqi.access_token? redirect geoloqi.authorize_url(GEOLOQI_REDIRECT_URI) unless geoloqi.access_token? username = geoloqi.get('account/username')['username'] "You have successfully logged in as #{username}!" end
Version data entries
16 entries across 16 versions & 1 rubygems