geoloqi 0.9.15 → 0.9.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/examples/sinatra.rb CHANGED
@@ -4,18 +4,27 @@ require 'rubygems'
4
4
  require 'sinatra'
5
5
  require 'geoloqi'
6
6
 
7
- GEOLOQI_REDIRECT_URI = 'http://example.com'
7
+ GEOLOQI_REDIRECT_URI = 'http://yourwebsite.net'
8
8
 
9
9
  enable :sessions
10
+ set :session_secret, 'PUT A SECRET WORD HERE' # Encrypts the cookie session.. recommended.
10
11
 
11
12
  def geoloqi
12
- Geoloqi.config :client_id => 'YOUR OAUTH CLIENT ID', :client_secret => 'YOUR CLIENT SECRET'
13
- @geoloqi ||= Geoloqi::Session.new :auth => session[:geoloqi_auth]
13
+ @geoloqi ||= Geoloqi::Session.new :auth => session[:geoloqi_auth],
14
+ :config => {:client_id => 'YOUR OAUTH CLIENT ID',
15
+ :client_secret => 'YOUR CLIENT SECRET'}
16
+ end
17
+
18
+ # If the access token expires, Geoloqi::Session will refresh inline!
19
+ # This after block makes sure the session gets the updated config.
20
+ after do
21
+ session[:geoloqi_auth] = @geoloqi.auth
14
22
  end
15
23
 
16
24
  get '/?' do
17
- session[:geoloqi_auth] = geoloqi.get_auth(params[:code], GEOLOQI_REDIRECT_URI) if params[:code] && !geoloqi.access_token?
25
+ geoloqi.get_auth(params[:code], GEOLOQI_REDIRECT_URI) if params[:code] && !geoloqi.access_token?
18
26
  redirect geoloqi.authorize_url(GEOLOQI_REDIRECT_URI) unless geoloqi.access_token?
27
+
19
28
  username = geoloqi.get('account/username')['username']
20
29
  "You have successfully logged in as #{username}!"
21
- end
30
+ end
@@ -9,21 +9,31 @@ require 'sinatra'
9
9
  require 'sinatra/synchrony'
10
10
  require 'geoloqi'
11
11
 
12
- GEOLOQI_REDIRECT_URI = 'http://example.com'
12
+ GEOLOQI_REDIRECT_URI = 'http://yourwebsite.net'
13
13
 
14
14
  enable :sessions
15
+ set :session_secret, 'PUT A SECRET WORD HERE' # Encrypts the cookie session.. recommended.
15
16
 
16
- configure do
17
- Geoloqi.config :client_id => 'YOUR OAUTH CLIENT ID', :client_secret => 'YOUR CLIENT SECRET', :adapter => :em_synchrony
17
+ def geoloqi
18
+ @geoloqi ||= Geoloqi::Session.new :auth => session[:geoloqi_auth],
19
+ :config => {:client_id => 'YOUR OAUTH CLIENT ID',
20
+ :client_secret => 'YOUR CLIENT SECRET',
21
+ :adapter => :em_synchrony}
18
22
  end
19
23
 
20
- def geoloqi
21
- @geoloqi ||= Geoloqi::Session.new :auth => session[:geoloqi_auth]
24
+ # If the access token expires, Geoloqi::Session will refresh inline!
25
+ # This after block makes sure the session gets the updated config.
26
+ after do
27
+ session[:geoloqi_auth] = @geoloqi.auth
22
28
  end
23
29
 
24
30
  get '/?' do
25
- session[:geoloqi_auth] = geoloqi.get_auth(params[:code], GEOLOQI_REDIRECT_URI) if params[:code] && !geoloqi.access_token?
31
+ geoloqi.get_auth(params[:code], GEOLOQI_REDIRECT_URI) if params[:code] && !geoloqi.access_token?
26
32
  redirect geoloqi.authorize_url(GEOLOQI_REDIRECT_URI) unless geoloqi.access_token?
33
+
27
34
  username = geoloqi.get('account/username')['username']
28
35
  "You have successfully logged in as #{username}!"
29
- end
36
+ end
37
+
38
+ # To install deps: gem install sinatra sinatra-synchrony geoloqi
39
+ # To run from command line: ruby sinatra_synchrony.rb -s thin
data/lib/geoloqi.rb CHANGED
@@ -22,8 +22,10 @@ module Geoloqi
22
22
  @@config = Config.new opts
23
23
  end
24
24
 
25
- def self.authorize_url(client_id=nil, redirect_uri=@@config.redirect_uri)
25
+ def self.authorize_url(client_id=nil, redirect_uri=@@config.redirect_uri, opts={})
26
26
  raise "client_id required to authorize url. Pass with Geoloqi.config" unless client_id
27
- "#{OAUTH_URL}?response_type=code&client_id=#{Rack::Utils.escape client_id}&redirect_uri=#{Rack::Utils.escape redirect_uri}"
27
+ url = "#{OAUTH_URL}?response_type=code&client_id=#{Rack::Utils.escape client_id}&redirect_uri=#{Rack::Utils.escape redirect_uri}"
28
+ url += "&#{Rack::Utils.build_query opts}" unless opts.empty?
29
+ url
28
30
  end
29
31
  end
@@ -1,5 +1,5 @@
1
1
  module Geoloqi
2
2
  def self.version
3
- '0.9.15'
3
+ '0.9.16'
4
4
  end
5
5
  end
data/spec/geoloqi_spec.rb CHANGED
@@ -24,6 +24,15 @@ describe Geoloqi do
24
24
  "client_id=#{Rack::Utils.escape 'test'}&"+
25
25
  "redirect_uri=#{Rack::Utils.escape 'http://blah.blah/test'}" }
26
26
  end
27
+
28
+ it 'returns authorize url with scope' do
29
+ authorize_url = Geoloqi.authorize_url 'test', 'http://blah.blah/test', :scope => 'can_party_hard'
30
+ expect { authorize_url == "#{Geoloqi::OAUTH_URL}?"+
31
+ 'response_type=code&'+
32
+ "client_id=#{Rack::Utils.escape 'test'}&"+
33
+ "redirect_uri=#{Rack::Utils.escape 'http://blah.blah/test'}&"+
34
+ "scope=can_party_hard" }
35
+ end
27
36
  end
28
37
 
29
38
  describe Geoloqi::ApiError do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: geoloqi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.15
5
+ version: 0.9.16
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kyle Drake