sinatra-geoloqi 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Gemfile.lock +90 -0
- data/README.markdown +43 -0
- data/Rakefile +13 -0
- data/lib/sinatra/geoloqi.rb +29 -0
- data/spec/sinatra_geoloqi_spec.rb +86 -0
- metadata +136 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sinatra-geoloqi (0.9.0)
|
5
|
+
geoloqi (>= 0.9.33)
|
6
|
+
sinatra (>= 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ParseTree (3.0.8)
|
12
|
+
RubyInline (>= 3.7.0)
|
13
|
+
sexp_processor (>= 3.0.0)
|
14
|
+
RubyInline (3.11.0)
|
15
|
+
ZenTest (~> 4.3)
|
16
|
+
ZenTest (4.6.2)
|
17
|
+
addressable (2.2.6)
|
18
|
+
bouncy-castle-java (1.5.0146.1)
|
19
|
+
crack (0.3.1)
|
20
|
+
diff-lcs (1.1.3)
|
21
|
+
faraday (0.7.5)
|
22
|
+
addressable (~> 2.2.6)
|
23
|
+
multipart-post (~> 1.1.3)
|
24
|
+
rack (>= 1.1.0, < 2)
|
25
|
+
file-tail (1.0.7)
|
26
|
+
tins (~> 0.3)
|
27
|
+
geoloqi (0.9.33)
|
28
|
+
faraday (>= 0.6.1)
|
29
|
+
json
|
30
|
+
jruby-openssl (0.7.4)
|
31
|
+
bouncy-castle-java
|
32
|
+
json (1.6.1)
|
33
|
+
json (1.6.1-java)
|
34
|
+
minitest (2.8.1)
|
35
|
+
multipart-post (1.1.3)
|
36
|
+
predicated (0.2.6)
|
37
|
+
rack (1.3.5)
|
38
|
+
rack-protection (1.1.4)
|
39
|
+
rack
|
40
|
+
rack-test (0.5.7)
|
41
|
+
rack (>= 1.0)
|
42
|
+
rake (0.9.2.2)
|
43
|
+
ruby2ruby (1.3.1)
|
44
|
+
ruby_parser (~> 2.0)
|
45
|
+
sexp_processor (~> 3.0)
|
46
|
+
ruby_parser (2.0.6)
|
47
|
+
sexp_processor (~> 3.0)
|
48
|
+
sexp_processor (3.0.8)
|
49
|
+
sinatra (1.3.1)
|
50
|
+
rack (~> 1.3, >= 1.3.4)
|
51
|
+
rack-protection (~> 1.1, >= 1.1.2)
|
52
|
+
tilt (~> 1.3, >= 1.3.3)
|
53
|
+
sourcify (0.5.0)
|
54
|
+
file-tail (>= 1.0.5)
|
55
|
+
ruby2ruby (>= 1.2.5)
|
56
|
+
ruby_parser (>= 2.0.5)
|
57
|
+
sexp_processor (>= 3.0.5)
|
58
|
+
tilt (1.3.3)
|
59
|
+
tins (0.3.2)
|
60
|
+
webmock (1.7.7)
|
61
|
+
addressable (~> 2.2, > 2.2.5)
|
62
|
+
crack (>= 0.1.7)
|
63
|
+
wrong (0.5.0)
|
64
|
+
ParseTree (~> 3.0)
|
65
|
+
diff-lcs (~> 1.1.2)
|
66
|
+
file-tail (~> 1.0)
|
67
|
+
predicated (>= 0.2.2)
|
68
|
+
ruby2ruby (~> 1.2)
|
69
|
+
ruby_parser (~> 2.0.4)
|
70
|
+
sexp_processor (~> 3.0)
|
71
|
+
sourcify (>= 0.3.0)
|
72
|
+
wrong (0.5.0-java)
|
73
|
+
diff-lcs (~> 1.1.2)
|
74
|
+
predicated (>= 0.2.2)
|
75
|
+
ruby2ruby (~> 1.2)
|
76
|
+
ruby_parser (~> 2.0.4)
|
77
|
+
sexp_processor (~> 3.0)
|
78
|
+
|
79
|
+
PLATFORMS
|
80
|
+
java
|
81
|
+
ruby
|
82
|
+
|
83
|
+
DEPENDENCIES
|
84
|
+
jruby-openssl
|
85
|
+
minitest
|
86
|
+
rack-test (= 0.5.7)
|
87
|
+
rake
|
88
|
+
sinatra-geoloqi!
|
89
|
+
webmock (= 1.7.7)
|
90
|
+
wrong (= 0.5.0)
|
data/README.markdown
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Geoloqi plugin for Sinatra [![](https://secure.travis-ci.org/geoloqi/sinatra-geoloqi.png)](http://travis-ci.org/geoloqi/sinatra-geoloqi)
|
2
|
+
===
|
3
|
+
Easy drop-in [Sinatra](http://sinatrarb.com) plugin for Geoloqi. All you need to do is require it, configure the settings and you're ready to go with Geoloqi application development!
|
4
|
+
|
5
|
+
Installation
|
6
|
+
---
|
7
|
+
|
8
|
+
gem install sinatra-geoloqi
|
9
|
+
|
10
|
+
Usage
|
11
|
+
---
|
12
|
+
First, go to the [Geoloqi Developers Site](https://developers.geoloqi.com) and create an application on the "Your Apps" page.
|
13
|
+
|
14
|
+
Then, you can use it like this. This is the standard way with classic mode:
|
15
|
+
|
16
|
+
require 'sinatra'
|
17
|
+
require 'sinatra/geoloqi'
|
18
|
+
|
19
|
+
set :geoloqi_client_id, 'YOUR_APP_ID_GOES_HERE'
|
20
|
+
set :geoloqi_client_secret, 'YOUR_APP_SECRET_GOES_HERE'
|
21
|
+
set :geoloqi_redirect_uri, 'http://127.0.0.1:4567'
|
22
|
+
set :session_secret, 'ENTER_RANDOM_TEXT_HERE'
|
23
|
+
|
24
|
+
before do
|
25
|
+
require_geoloqi_login
|
26
|
+
end
|
27
|
+
|
28
|
+
get '/?' do
|
29
|
+
username = geoloqi.get('account/username')['username']
|
30
|
+
"You have successfully logged in as #{username}!"
|
31
|
+
end
|
32
|
+
|
33
|
+
For "classy mode", don't forget to register the plugin explicitly:
|
34
|
+
|
35
|
+
register Sinatra::Geoloqi
|
36
|
+
|
37
|
+
Found a bug?
|
38
|
+
---
|
39
|
+
Let us know! Send a pull request or a patch. Questions? Ask! We're here to help. File issues, we'll respond to them!
|
40
|
+
|
41
|
+
Authors
|
42
|
+
---
|
43
|
+
* [Kyle Drake](https://github.com/kyledrake)
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs = ['lib','test']
|
8
|
+
t.test_files = Dir.glob("spec/**/*_spec.rb").sort
|
9
|
+
t.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => [:test]
|
13
|
+
task :spec => [:test]
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'geoloqi'
|
3
|
+
|
4
|
+
module Sinatra
|
5
|
+
module Geoloqi
|
6
|
+
def self.registered(app)
|
7
|
+
app.enable :sessions unless app.test?
|
8
|
+
|
9
|
+
app.after do
|
10
|
+
session[:_geoloqi_auth] = @_geoloqi.auth unless session[:_geoloqi_auth].nil? && @_geoloqi.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
app.helpers do
|
14
|
+
def geoloqi
|
15
|
+
@_geoloqi ||= ::Geoloqi::Session.new :auth => session[:_geoloqi_auth],
|
16
|
+
:config => {:client_id => settings.geoloqi_client_id,
|
17
|
+
:client_secret => settings.geoloqi_client_secret}
|
18
|
+
end
|
19
|
+
|
20
|
+
def require_geoloqi_login
|
21
|
+
geoloqi.get_auth(params[:code], settings.geoloqi_redirect_uri) if params[:code] && !geoloqi.access_token?
|
22
|
+
redirect geoloqi.authorize_url(settings.geoloqi_redirect_uri) unless geoloqi.access_token?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
register Geoloqi
|
29
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
require File.join(File.join(File.expand_path(File.dirname(__FILE__))), '..', 'lib', 'sinatra', 'geoloqi')
|
3
|
+
require 'rack/test'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'wrong/adapters/minitest'
|
6
|
+
require 'webmock'
|
7
|
+
Wrong.config.alias_assert :expect_that
|
8
|
+
|
9
|
+
include WebMock::API
|
10
|
+
|
11
|
+
def auth
|
12
|
+
{'display_name' => 'Captain Ron',
|
13
|
+
'username' => 'isthegreatestmoviever',
|
14
|
+
'user_id' => '31337',
|
15
|
+
'is_anonymous' => 0,
|
16
|
+
'access_token' => 'access_token1234',
|
17
|
+
'scope' => nil,
|
18
|
+
'expires_in' => 3600,
|
19
|
+
'refresh_token' => 'refresh_token1234'}
|
20
|
+
end
|
21
|
+
|
22
|
+
def app
|
23
|
+
@app ||= Sinatra.new do
|
24
|
+
set :geoloqi_client_id, 'ABCD'
|
25
|
+
set :geoloqi_client_secret, 'EFGH'
|
26
|
+
set :geoloqi_redirect_uri, 'http://example.org/test'
|
27
|
+
|
28
|
+
register Sinatra::Geoloqi
|
29
|
+
|
30
|
+
get '/' do
|
31
|
+
geoloqi.class.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
get '/redirect' do
|
35
|
+
require_geoloqi_login
|
36
|
+
end
|
37
|
+
|
38
|
+
get '/test' do
|
39
|
+
require_geoloqi_login
|
40
|
+
geoloqi.access_token
|
41
|
+
end
|
42
|
+
|
43
|
+
get '/calltest' do
|
44
|
+
require_geoloqi_login
|
45
|
+
geoloqi.get('account/profile')['result']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'A mock app' do
|
51
|
+
include Rack::Test::Methods
|
52
|
+
|
53
|
+
it 'returns geoloqi object' do
|
54
|
+
get '/'
|
55
|
+
expect_that { last_response.ok? }
|
56
|
+
expect_that { last_response.body == 'Geoloqi::Session' }
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns a geoloqi object on request' do
|
60
|
+
get '/redirect'
|
61
|
+
expect_that { last_response.redirect? }
|
62
|
+
expect_that { last_response.headers['Location'] == 'https://geoloqi.com/oauth/authorize?response_type=code&client_id=ABCD&redirect_uri=http%3A%2F%2Fexample.org%2Ftest' }
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'processes the geoloqi return' do
|
66
|
+
stub_request(:post, "https://api.geoloqi.com/1/oauth/token").
|
67
|
+
with(:body => "{\"client_id\":\"ABCD\",\"client_secret\":\"EFGH\",\"grant_type\":\"authorization_code\",\"code\":\"code1234\",\"redirect_uri\":\"http://example.org/test\"}").
|
68
|
+
to_return(:status => 200,
|
69
|
+
:body => auth.to_json)
|
70
|
+
|
71
|
+
get '/test?state=&code=code1234'
|
72
|
+
expect_that { last_response.ok? }
|
73
|
+
expect_that { last_response.body == 'access_token1234' }
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'calls successfully' do
|
77
|
+
stub_request(:get, "https://api.geoloqi.com/1/account/profile").
|
78
|
+
with(:headers => {'Authorization' => 'OAuth access_token1234'}).
|
79
|
+
to_return(:status => 200, :body => {'result' => 'ok'}.to_json, :headers => {})
|
80
|
+
|
81
|
+
get '/calltest', {}, 'rack.session' => {:'_geoloqi_auth' => auth}
|
82
|
+
|
83
|
+
expect_that { last_response.status == 200 }
|
84
|
+
expect_that { last_response.body == 'ok' }
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-geoloqi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.9.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kyle Drake
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-11-19 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sinatra
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: geoloqi
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.9.33
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rack-test
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - "="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.5.7
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: wrong
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - "="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.5.0
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: webmock
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - "="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.7.7
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: minitest
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id007
|
92
|
+
description: Geoloqi adapter for Sinatra, quickly allows you to make applications
|
93
|
+
email:
|
94
|
+
- kyledrake@gmail.com
|
95
|
+
executables: []
|
96
|
+
|
97
|
+
extensions: []
|
98
|
+
|
99
|
+
extra_rdoc_files: []
|
100
|
+
|
101
|
+
files:
|
102
|
+
- lib/sinatra/geoloqi.rb
|
103
|
+
- spec/sinatra_geoloqi_spec.rb
|
104
|
+
- Gemfile
|
105
|
+
- Gemfile.lock
|
106
|
+
- Rakefile
|
107
|
+
- README.markdown
|
108
|
+
homepage: https://github.com/geoloqi/sinatra-geoloqi
|
109
|
+
licenses: []
|
110
|
+
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: "0"
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 1.3.4
|
128
|
+
requirements: []
|
129
|
+
|
130
|
+
rubyforge_project: sinatra-geoloqi
|
131
|
+
rubygems_version: 1.8.9
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: Geoloqi adapter for Sinatra
|
135
|
+
test_files: []
|
136
|
+
|