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

Version Path
geoloqi-0.9.15 examples/sinatra_synchrony.rb
geoloqi-0.9.14 examples/sinatra_synchrony.rb
geoloqi-0.9.13 examples/sinatra_synchrony.rb
geoloqi-0.9.12 examples/sinatra_synchrony.rb
geoloqi-0.9.11 examples/sinatra_synchrony.rb
geoloqi-0.9.10 examples/sinatra_synchrony.rb
geoloqi-0.9.9 examples/sinatra_synchrony.rb
geoloqi-0.9.8 examples/sinatra_synchrony.rb
geoloqi-0.9.7 examples/sinatra_synchrony.rb
geoloqi-0.9.6 examples/sinatra_synchrony.rb
geoloqi-0.9.5 examples/sinatra_synchrony.rb
geoloqi-0.9.4 examples/sinatra_synchrony.rb
geoloqi-0.9.3 examples/sinatra_synchrony.rb
geoloqi-0.9.2 examples/sinatra_synchrony.rb
geoloqi-0.9.1 examples/sinatra_synchrony.rb
geoloqi-0.9.0 examples/sinatra_synchrony.rb