omniauth-osm 0.1.3 → 0.2.0
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/.travis.yml +3 -0
- data/lib/omniauth/strategies/osm.rb +41 -36
- data/lib/omniauth-osm/version.rb +1 -1
- data/omniauth-osm.gemspec +1 -2
- data/spec/omniauth/strategies/osm_spec.rb +39 -29
- metadata +25 -41
data/.travis.yml
CHANGED
@@ -1,55 +1,60 @@
|
|
1
1
|
require 'omniauth-oauth'
|
2
|
-
require '
|
2
|
+
require 'rexml/document'
|
3
3
|
|
4
4
|
module OmniAuth
|
5
5
|
module Strategies
|
6
6
|
class Osm < OmniAuth::Strategies::OAuth
|
7
7
|
option :name, "osm"
|
8
8
|
|
9
|
-
option :client_options,
|
10
|
-
:site => 'http://www.openstreetmap.org',
|
11
|
-
:request_token_url => 'http://www.openstreetmap.org/oauth/request_token',
|
12
|
-
:access_token_url => 'http://www.openstreetmap.org/oauth/access_token',
|
13
|
-
:authorize_url => 'http://www.openstreetmap.org/oauth/authorize'
|
14
|
-
}
|
9
|
+
option :client_options, :site => 'http://www.openstreetmap.org'
|
15
10
|
|
16
|
-
uid{ raw_info['
|
11
|
+
uid { raw_info['id'] }
|
17
12
|
|
18
13
|
info do
|
19
|
-
|
20
|
-
'name' => raw_info['user']['display_name'],
|
21
|
-
'languages' => languages,
|
22
|
-
'lat' => lat,
|
23
|
-
'lon' => lon,
|
24
|
-
'image_url' => image_url
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
def lat
|
29
|
-
raw_info['user']['home']['lat'].to_f rescue nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def lon
|
33
|
-
raw_info['user']['home']['lon'].to_f rescue nil
|
34
|
-
end
|
35
|
-
|
36
|
-
def languages
|
37
|
-
raw_info['user']['languages']['lang'] rescue []
|
38
|
-
end
|
39
|
-
|
40
|
-
def image_url
|
41
|
-
raw_info['user']['img']['href'] rescue nil
|
42
|
-
end
|
43
|
-
|
44
|
-
extra do
|
45
|
-
{ 'raw_info' => raw_info }
|
14
|
+
raw_info
|
46
15
|
end
|
47
16
|
|
48
17
|
def raw_info
|
49
|
-
@raw_info ||=
|
18
|
+
@raw_info ||= parse_info(access_token.get('/api/0.6/user/details').body)
|
50
19
|
rescue ::Errno::ETIMEDOUT
|
51
20
|
raise ::Timeout::Error
|
52
21
|
end
|
22
|
+
|
23
|
+
# EXAMPLE XML
|
24
|
+
#
|
25
|
+
# <?xml version="1.0" encoding="UTF-8"?>
|
26
|
+
# <osm generator="OpenStreetMap server" version="0.6">
|
27
|
+
# <user display_name="freundchen" account_created="2011-01-07T14:35:24Z" id="392638">
|
28
|
+
# <img href='http://foo.bar.net/logo.gif' />
|
29
|
+
# <description>Test description</description>
|
30
|
+
# <contributor-terms pd="false" agreed="true"/>
|
31
|
+
# <home lon="13.411681556178" zoom="3" lat="52.524360979625"/>
|
32
|
+
# <languages>
|
33
|
+
# <lang>de-DE</lang>
|
34
|
+
# <lang>de</lang>
|
35
|
+
# </languages>
|
36
|
+
# </user>
|
37
|
+
# </osm>
|
38
|
+
|
39
|
+
private
|
40
|
+
def parse_info(xml_data)
|
41
|
+
# extract event information
|
42
|
+
doc = REXML::Document.new(xml_data)
|
43
|
+
user = doc.elements['//user']
|
44
|
+
home = doc.elements['//home']
|
45
|
+
languages = doc.get_elements('//lang')
|
46
|
+
image = doc.elements['//img']
|
47
|
+
description = doc.elements['//description']
|
48
|
+
basic_attributes = { }
|
49
|
+
basic_attributes['id'] = user.attribute('id').value
|
50
|
+
basic_attributes['display_name'] = user.attribute('display_name').value
|
51
|
+
basic_attributes['languages'] = languages.map(&:text) if languages
|
52
|
+
basic_attributes['image_url'] = image.attribute('href').value if image
|
53
|
+
basic_attributes['lat'] = home.attribute('lat').value.to_f if home
|
54
|
+
basic_attributes['lon'] = home.attribute('lon').value.to_f if home
|
55
|
+
basic_attributes['description'] = description.text if description
|
56
|
+
basic_attributes
|
57
|
+
end
|
53
58
|
end
|
54
59
|
end
|
55
60
|
end
|
data/lib/omniauth-osm/version.rb
CHANGED
data/omniauth-osm.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "omniauth-osm/version"
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = 'omniauth-osm'
|
7
7
|
gem.version = OmniAuth::Osm::VERSION
|
8
|
-
gem.authors = ["Christoph
|
8
|
+
gem.authors = ["Christoph Bünte"]
|
9
9
|
gem.email = 'christoph@sozialhelden.de'
|
10
10
|
gem.homepage = 'https://github.com/sozialhelden/omniauth-osm'
|
11
11
|
gem.description = %q{OpenStreetMap strategy for OmniAuth 1.0a}
|
@@ -19,7 +19,6 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.require_paths = ['lib']
|
20
20
|
|
21
21
|
gem.add_runtime_dependency "omniauth-oauth", "~> 1.0"
|
22
|
-
gem.add_runtime_dependency "multi_json", "~> 1.0"
|
23
22
|
|
24
23
|
gem.add_development_dependency 'rake', '~> 0.9'
|
25
24
|
gem.add_development_dependency 'rspec', '~> 2.7'
|
@@ -16,73 +16,83 @@ describe OmniAuth::Strategies::Osm do
|
|
16
16
|
it 'has correct Osm site' do
|
17
17
|
subject.options.client_options.site.should eq('http://www.openstreetmap.org')
|
18
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
19
|
end
|
32
20
|
|
33
21
|
describe '#id' do
|
34
22
|
it 'returns the id from raw_info' do
|
35
|
-
subject.stub(:raw_info) {
|
23
|
+
subject.stub(:raw_info) { { 'id' => '123' } }
|
36
24
|
subject.uid.should eq('123')
|
37
25
|
end
|
38
26
|
end
|
39
27
|
|
28
|
+
FULL_XML = <<-EOX
|
29
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
30
|
+
<osm generator="OpenStreetMap server" version="0.6">
|
31
|
+
<user display_name="freundchen" account_created="2011-01-07T14:35:24Z" id="392638">
|
32
|
+
<img href="http://somewhere.com/image.jpg" />
|
33
|
+
<description>Test description</description>
|
34
|
+
<contributor-terms pd="false" agreed="true"/>
|
35
|
+
<home lon="13.411681556178" zoom="3" lat="52.524360979625"/>
|
36
|
+
<languages>
|
37
|
+
<lang>de-DE</lang>
|
38
|
+
<lang>de</lang>
|
39
|
+
</languages>
|
40
|
+
</user>
|
41
|
+
</osm>
|
42
|
+
EOX
|
43
|
+
|
44
|
+
MINI_XML = <<-EOX
|
45
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
46
|
+
<osm generator="OpenStreetMap server" version="0.6">
|
47
|
+
<user display_name="freundchen" account_created="2011-01-07T14:35:24Z" id="392638">
|
48
|
+
<description/>
|
49
|
+
<contributor-terms pd="false" agreed="true"/>
|
50
|
+
</user>
|
51
|
+
</osm>
|
52
|
+
EOX
|
53
|
+
|
40
54
|
describe '#info' do
|
41
55
|
before :each do
|
42
|
-
@
|
43
|
-
subject.
|
56
|
+
@parsed = subject.send(:parse_info, FULL_XML)
|
57
|
+
@mini_parsed = subject.send(:parse_info, MINI_XML)
|
44
58
|
end
|
45
59
|
|
46
60
|
context 'when data is present in raw info' do
|
47
61
|
it 'returns the name' do
|
48
|
-
|
62
|
+
@parsed['display_name'].should eq('freundchen')
|
49
63
|
end
|
50
64
|
|
51
65
|
it 'returns the languages' do
|
52
|
-
|
66
|
+
@parsed['languages'].should eq(['de-DE', 'de'])
|
53
67
|
end
|
54
68
|
|
55
69
|
it 'returns no languages if missing' do
|
56
|
-
|
57
|
-
|
70
|
+
|
71
|
+
@mini_parsed['languages'].should eq([])
|
58
72
|
end
|
59
73
|
|
60
74
|
it 'returns the lat' do
|
61
|
-
|
75
|
+
@parsed['lat'].should eq(52.524360979625)
|
62
76
|
end
|
63
77
|
|
64
78
|
it 'returns no lat if missing' do
|
65
|
-
@
|
66
|
-
subject.info['lat'].should eq(nil)
|
79
|
+
@mini_parsed['lat'].should eq(nil)
|
67
80
|
end
|
68
81
|
|
69
82
|
it 'returns the lon' do
|
70
|
-
|
83
|
+
@parsed['lon'].should eq(13.411681556178)
|
71
84
|
end
|
72
85
|
|
73
86
|
it 'returns no lon if missing' do
|
74
|
-
@
|
75
|
-
subject.info['lon'].should eq(nil)
|
87
|
+
@mini_parsed['lon'].should eq(nil)
|
76
88
|
end
|
77
89
|
|
78
90
|
it 'returns the image' do
|
79
|
-
|
91
|
+
@parsed['image_url'].should eq('http://somewhere.com/image.jpg')
|
80
92
|
end
|
81
93
|
|
82
94
|
it 'returns no image of missing' do
|
83
|
-
@
|
84
|
-
subject.info['image_url'].should eq(nil)
|
85
|
-
|
95
|
+
@mini_parsed['image_url'].should eq(nil)
|
86
96
|
end
|
87
97
|
end
|
88
98
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-osm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Christoph B\xC3\xBCnte"
|
@@ -15,12 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-04-04 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
22
|
none: false
|
25
23
|
requirements:
|
26
24
|
- - ~>
|
@@ -30,27 +28,12 @@ dependencies:
|
|
30
28
|
- 1
|
31
29
|
- 0
|
32
30
|
version: "1.0"
|
33
|
-
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: multi_json
|
37
31
|
prerelease: false
|
38
|
-
requirement:
|
39
|
-
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 15
|
44
|
-
segments:
|
45
|
-
- 1
|
46
|
-
- 0
|
47
|
-
version: "1.0"
|
32
|
+
requirement: *id001
|
33
|
+
name: omniauth-oauth
|
48
34
|
type: :runtime
|
49
|
-
version_requirements: *id002
|
50
35
|
- !ruby/object:Gem::Dependency
|
51
|
-
|
52
|
-
prerelease: false
|
53
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
54
37
|
none: false
|
55
38
|
requirements:
|
56
39
|
- - ~>
|
@@ -60,12 +43,12 @@ dependencies:
|
|
60
43
|
- 0
|
61
44
|
- 9
|
62
45
|
version: "0.9"
|
46
|
+
prerelease: false
|
47
|
+
requirement: *id002
|
48
|
+
name: rake
|
63
49
|
type: :development
|
64
|
-
version_requirements: *id003
|
65
50
|
- !ruby/object:Gem::Dependency
|
66
|
-
|
67
|
-
prerelease: false
|
68
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
69
52
|
none: false
|
70
53
|
requirements:
|
71
54
|
- - ~>
|
@@ -75,12 +58,12 @@ dependencies:
|
|
75
58
|
- 2
|
76
59
|
- 7
|
77
60
|
version: "2.7"
|
61
|
+
prerelease: false
|
62
|
+
requirement: *id003
|
63
|
+
name: rspec
|
78
64
|
type: :development
|
79
|
-
version_requirements: *id004
|
80
65
|
- !ruby/object:Gem::Dependency
|
81
|
-
|
82
|
-
prerelease: false
|
83
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
66
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
84
67
|
none: false
|
85
68
|
requirements:
|
86
69
|
- - ~>
|
@@ -90,12 +73,12 @@ dependencies:
|
|
90
73
|
- 0
|
91
74
|
- 5
|
92
75
|
version: "0.5"
|
76
|
+
prerelease: false
|
77
|
+
requirement: *id004
|
78
|
+
name: simplecov
|
93
79
|
type: :development
|
94
|
-
version_requirements: *id005
|
95
80
|
- !ruby/object:Gem::Dependency
|
96
|
-
|
97
|
-
prerelease: false
|
98
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
81
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
99
82
|
none: false
|
100
83
|
requirements:
|
101
84
|
- - ~>
|
@@ -105,8 +88,10 @@ dependencies:
|
|
105
88
|
- 1
|
106
89
|
- 7
|
107
90
|
version: "1.7"
|
91
|
+
prerelease: false
|
92
|
+
requirement: *id005
|
93
|
+
name: webmock
|
108
94
|
type: :development
|
109
|
-
version_requirements: *id006
|
110
95
|
description: OpenStreetMap strategy for OmniAuth 1.0a
|
111
96
|
email: christoph@sozialhelden.de
|
112
97
|
executables: []
|
@@ -160,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
145
|
requirements: []
|
161
146
|
|
162
147
|
rubyforge_project: omniauth-osm
|
163
|
-
rubygems_version: 1.8.
|
148
|
+
rubygems_version: 1.8.15
|
164
149
|
signing_key:
|
165
150
|
specification_version: 3
|
166
151
|
summary: OpenStreetMap strategy for OmniAuth 1.0a
|
@@ -168,4 +153,3 @@ test_files:
|
|
168
153
|
- spec/integration.spec
|
169
154
|
- spec/omniauth/strategies/osm_spec.rb
|
170
155
|
- spec/spec_helper.rb
|
171
|
-
has_rdoc:
|