omniauth-osm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sw[a-p]
4
+ *.tmproj
5
+ *.tmproject
6
+ *.un~
7
+ *~
8
+ .DS_Store
9
+ .Spotlight-V100
10
+ .Trashes
11
+ ._*
12
+ .bundle
13
+ .config
14
+ .directory
15
+ .elc
16
+ .emacs.desktop
17
+ .emacs.desktop.lock
18
+ .redcar
19
+ .yardoc
20
+ Desktop.ini
21
+ Gemfile.lock
22
+ Icon?
23
+ InstalledFiles
24
+ Session.vim
25
+ Thumbs.db
26
+ \#*\#
27
+ _yardoc
28
+ auto-save-list
29
+ coverage
30
+ doc
31
+ lib/bundler/man
32
+ pkg
33
+ pkg/*
34
+ rdoc
35
+ spec/reports
36
+ test/tmp
37
+ test/version_tmp
38
+ tmp
39
+ tmtags
40
+ tramp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.8.7@omniauth-osm
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Christoph Bünte
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # OmniAuth OpenStreetMap
2
+
3
+ This gem contains the OpenStreetMap strategy for OmniAuth.
4
+
5
+ OpenStreetMap uses the OAuth 1.0a flow, you can read about it here: http://wiki.openstreetmap.org/wiki/OAuth
6
+
7
+ ## How To Use It
8
+
9
+ Usage is as per any other OmniAuth 1.0 strategy. So let's say you're using Rails, you need to add the strategy to your `Gemfile` along side omniauth:
10
+
11
+ gem 'omniauth'
12
+ gem 'omniauth-osm'
13
+
14
+ Of course if one or both of these are unreleased, you may have to pull them in directly from github e.g.:
15
+
16
+ gem 'omniauth', :git => 'https://github.com/intridea/omniauth.git'
17
+ gem 'omniauth-osm', :git => 'https://github.com/sozialhelden/omniauth-osm.git'
18
+
19
+ Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
20
+
21
+ Rails.application.config.middleware.use OmniAuth::Builder do
22
+ provider :osm, "consumer_key", "consumer_secret"
23
+ end
24
+
25
+ You will obviously have to put in your key and secret, which you get when you register your app with OpenStreetMap.
26
+
27
+ Now just follow the README at: https://github.com/intridea/omniauth
28
+
29
+ ## Note on Patches/Pull Requests
30
+
31
+ - Fork the project.
32
+ - Make your feature addition or bug fix.
33
+ - Add tests for it. This is important so I don’t break it in a future version unintentionally.
34
+ - Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
35
+ - Send me a pull request. Bonus points for topic branches.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
10
+ task :test => :spec
11
+
12
+ require 'yard'
13
+ namespace :doc do
14
+ YARD::Rake::YardocTask.new do |task|
15
+ task.files = ['LICENSE.md', 'lib/**/*.rb']
16
+ task.options = ['--markup', 'markdown']
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Osm
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/osm'
@@ -0,0 +1,54 @@
1
+ require 'omniauth-oauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Osm < OmniAuth::Strategies::OAuth
6
+ option :name, "osm"
7
+
8
+ option :client_options, {
9
+ :site => 'http://www.openstreetmap.org',
10
+ :request_token_url => 'http://www.openstreetmap.org/oauth/request_token',
11
+ :access_token_url => 'http://www.openstreetmap.org/oauth/access_token',
12
+ :authorize_url => 'http://www.openstreetmap.org/oauth/authorize'
13
+ }
14
+
15
+ uid{ raw_info['user']['id'] }
16
+
17
+ info do
18
+ {
19
+ 'name' => raw_info['user']['display_name'],
20
+ 'languages' => languages,
21
+ 'lat' => lat,
22
+ 'lon' => lon,
23
+ 'image_url' => image_url
24
+ }
25
+ end
26
+
27
+ def lat
28
+ raw_info['user']['home']['lat'].to_f rescue nil
29
+ end
30
+
31
+ def lon
32
+ raw_info['user']['home']['lon'].to_f rescue nil
33
+ end
34
+
35
+ def languages
36
+ raw_info['user']['languages']['lang'] rescue []
37
+ end
38
+
39
+ def image_url
40
+ raw_info['user']['img']['href'] rescue nil
41
+ end
42
+
43
+ extra do
44
+ { 'raw_info' => raw_info }
45
+ end
46
+
47
+ def raw_info
48
+ @raw_info ||= Hash.from_xml(access_token.get('/api/0.6/user/details.json').body)['osm']
49
+ rescue ::Errno::ETIMEDOUT
50
+ raise ::Timeout::Error
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth/osm'
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/omniauth/osm/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'omniauth-osm'
6
+ gem.version = OmniAuth::Osm::VERSION
7
+ gem.homepage = 'https://github.com/sozialhelden/omniauth-osm'
8
+
9
+ gem.author = "Christoph Bünte"
10
+ gem.email = 'christoph@sozialhelden.de'
11
+ gem.description = 'OpenStreetMap strategy for OmniAuth 1.0'
12
+ gem.summary = gem.description
13
+
14
+ gem.add_dependency "omniauth-oauth", "~> 1.0"
15
+
16
+ gem.add_development_dependency 'rake', '~> 0.9'
17
+ gem.add_development_dependency 'rdiscount', '~> 1.6'
18
+ gem.add_development_dependency 'rspec', '~> 2.7'
19
+ gem.add_development_dependency 'simplecov', '~> 0.5'
20
+ gem.add_development_dependency 'yard', '~> 0.7'
21
+ gem.add_development_dependency 'webmock', '~> 1.7'
22
+
23
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
24
+ gem.files = `git ls-files`.split("\n")
25
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+
27
+ gem.require_paths = ['lib']
28
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'OmniAuth::Strategies::OSM Integration' do
4
+ pending 'write some tests yo'
5
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Osm do
4
+ before :each do
5
+ @request = double('Request')
6
+ @request.stub(:params) { {} }
7
+ end
8
+
9
+ subject do
10
+ OmniAuth::Strategies::Osm.new(nil, @options || {}).tap do |strategy|
11
+ strategy.stub(:request) { @request }
12
+ end
13
+ end
14
+
15
+ describe '#client_options' do
16
+ it 'has correct Osm site' do
17
+ subject.options.client_options.site.should eq('http://www.openstreetmap.org')
18
+ end
19
+
20
+ it 'has correct authorize url' do
21
+ subject.options.client_options.authorize_url.should eq('http://www.openstreetmap.org/oauth/authorize')
22
+ end
23
+
24
+ it 'has correct request token url' do
25
+ subject.options.client_options.request_token_url.should eq('http://www.openstreetmap.org/oauth/request_token')
26
+ end
27
+
28
+ it 'has correct access token url' do
29
+ subject.options.client_options.access_token_url.should eq('http://www.openstreetmap.org/oauth/access_token')
30
+ end
31
+ end
32
+
33
+ describe '#id' do
34
+ it 'returns the id from raw_info' do
35
+ subject.stub(:raw_info) {{ 'user' => { 'id' => '123' } } }
36
+ subject.uid.should eq('123')
37
+ end
38
+ end
39
+
40
+ describe '#info' do
41
+ before :each do
42
+ @raw_info ||= { 'user' => { 'display_name' => 'Fred', 'languages' => {'lang' => ["de-DE", "de"]}, 'home' => {'lat' => '52.0', 'lon' => '13.4', 'zoom' => '3' }, 'img' => {'href' => 'http://somewhere.com/image.jpg'} } }
43
+ subject.stub(:raw_info) { @raw_info }
44
+ end
45
+
46
+ context 'when data is present in raw info' do
47
+ it 'returns the name' do
48
+ subject.info['name'].should eq('Fred')
49
+ end
50
+
51
+ it 'returns the languages' do
52
+ subject.info['languages'].should eq(['de-DE', 'de'])
53
+ end
54
+
55
+ it 'returns no languages if missing' do
56
+ @raw_info['user'].delete('languages')
57
+ subject.info['languages'].should eq([])
58
+ end
59
+
60
+ it 'returns the lat' do
61
+ subject.info['lat'].should eq(52.0)
62
+ end
63
+
64
+ it 'returns no lat if missing' do
65
+ @raw_info['user'].delete('home')
66
+ subject.info['lat'].should eq(nil)
67
+ end
68
+
69
+ it 'returns the lon' do
70
+ subject.info['lon'].should eq(13.4)
71
+ end
72
+
73
+ it 'returns no lon if missing' do
74
+ @raw_info['user'].delete('home')
75
+ subject.info['lon'].should eq(nil)
76
+ end
77
+
78
+ it 'returns the image' do
79
+ subject.info['image_url'].should eq('http://somewhere.com/image.jpg')
80
+ end
81
+
82
+ it 'returns no image of missing' do
83
+ @raw_info['user'].delete('img')
84
+ subject.info['image_url'].should eq(nil)
85
+
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ require 'omniauth-osm'
5
+ require 'rspec'
6
+ require 'webmock/rspec'
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-osm
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - "Christoph B\xC3\xBCnte"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-28 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: omniauth-oauth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 1
31
+ - 0
32
+ version: "1.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 25
44
+ segments:
45
+ - 0
46
+ - 9
47
+ version: "0.9"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rdiscount
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 1
61
+ - 6
62
+ version: "1.6"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: rspec
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 13
74
+ segments:
75
+ - 2
76
+ - 7
77
+ version: "2.7"
78
+ type: :development
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: simplecov
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ hash: 1
89
+ segments:
90
+ - 0
91
+ - 5
92
+ version: "0.5"
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: yard
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ hash: 5
104
+ segments:
105
+ - 0
106
+ - 7
107
+ version: "0.7"
108
+ type: :development
109
+ version_requirements: *id006
110
+ - !ruby/object:Gem::Dependency
111
+ name: webmock
112
+ prerelease: false
113
+ requirement: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ hash: 1
119
+ segments:
120
+ - 1
121
+ - 7
122
+ version: "1.7"
123
+ type: :development
124
+ version_requirements: *id007
125
+ description: OpenStreetMap strategy for OmniAuth 1.0
126
+ email: christoph@sozialhelden.de
127
+ executables: []
128
+
129
+ extensions: []
130
+
131
+ extra_rdoc_files: []
132
+
133
+ files:
134
+ - .gitignore
135
+ - .rvmrc
136
+ - Gemfile
137
+ - LICENSE.md
138
+ - README.md
139
+ - Rakefile
140
+ - lib/omniauth-osm.rb
141
+ - lib/omniauth/osm.rb
142
+ - lib/omniauth/osm/version.rb
143
+ - lib/omniauth/strategies/osm.rb
144
+ - omniauth-osm.gemspec
145
+ - spec/integration.spec
146
+ - spec/omniauth/strategies/osm_spec.rb
147
+ - spec/spec_helper.rb
148
+ homepage: https://github.com/sozialhelden/omniauth-osm
149
+ licenses: []
150
+
151
+ post_install_message:
152
+ rdoc_options: []
153
+
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ requirements: []
175
+
176
+ rubyforge_project:
177
+ rubygems_version: 1.8.11
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: OpenStreetMap strategy for OmniAuth 1.0
181
+ test_files:
182
+ - spec/integration.spec
183
+ - spec/omniauth/strategies/osm_spec.rb
184
+ - spec/spec_helper.rb
185
+ has_rdoc: