nominatim 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/lib/nominatim.rb +8 -0
- data/lib/nominatim/address.rb +9 -1
- data/lib/nominatim/client.rb +2 -1
- data/lib/nominatim/configuration.rb +9 -5
- data/lib/nominatim/reverse.rb +42 -0
- data/lib/nominatim/version.rb +1 -1
- data/spec/fixtures/reverse.json +1 -0
- data/spec/nominatim/reverse_spec.rb +68 -0
- data/spec/nominatim_spec.rb +13 -1
- metadata +13 -2
data/.gitignore
CHANGED
data/lib/nominatim.rb
CHANGED
@@ -7,6 +7,7 @@ require "nominatim/place"
|
|
7
7
|
require "nominatim/response/parse_json"
|
8
8
|
require "nominatim/client"
|
9
9
|
require "nominatim/search"
|
10
|
+
require "nominatim/reverse"
|
10
11
|
|
11
12
|
module Nominatim
|
12
13
|
|
@@ -17,6 +18,13 @@ module Nominatim
|
|
17
18
|
search
|
18
19
|
end
|
19
20
|
|
21
|
+
# @return [Nominatim::Reverse]
|
22
|
+
def self.reverse(lat = nil, lon = nil)
|
23
|
+
search = Nominatim::Reverse.new
|
24
|
+
search.lat(lat).lon(lon) if lat && lon
|
25
|
+
search
|
26
|
+
end
|
27
|
+
|
20
28
|
# @return [Nominatim::Configuration]
|
21
29
|
def self.config
|
22
30
|
@config ||= Configuration.new
|
data/lib/nominatim/address.rb
CHANGED
data/lib/nominatim/client.rb
CHANGED
@@ -25,8 +25,9 @@ module Nominatim
|
|
25
25
|
@connection.params[:email] = Nominatim.config.email if Nominatim.config.email
|
26
26
|
|
27
27
|
@connection.headers[:user_agent] = Nominatim.config.user_agent
|
28
|
+
@connection.headers[:"accept-language"] = Nominatim.config.accept_language
|
28
29
|
|
29
30
|
@connection
|
30
31
|
end
|
31
32
|
end
|
32
|
-
end
|
33
|
+
end
|
@@ -7,10 +7,13 @@ module Nominatim
|
|
7
7
|
|
8
8
|
DEFAULT_EMAIL = nil
|
9
9
|
|
10
|
+
DEFAULT_LANGUAGE = 'en'
|
11
|
+
|
10
12
|
VALID_OPTIONS_KEYS = [
|
11
13
|
:endpoint,
|
12
14
|
:user_agent,
|
13
|
-
:email
|
15
|
+
:email,
|
16
|
+
:accept_language
|
14
17
|
]
|
15
18
|
|
16
19
|
attr_accessor *VALID_OPTIONS_KEYS
|
@@ -25,9 +28,10 @@ module Nominatim
|
|
25
28
|
end
|
26
29
|
|
27
30
|
def reset!
|
28
|
-
self.endpoint
|
29
|
-
self.user_agent
|
30
|
-
self.email
|
31
|
+
self.endpoint = DEFAULT_ENDPOINT
|
32
|
+
self.user_agent = DEFAULT_USER_AGENT
|
33
|
+
self.email = DEFAULT_EMAIL
|
34
|
+
self.accept_language = DEFAULT_LANGUAGE
|
31
35
|
end
|
32
36
|
end
|
33
|
-
end
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Nominatim
|
2
|
+
class Reverse < Client
|
3
|
+
attr_reader :criteria
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@criteria = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns search result.
|
10
|
+
def fetch
|
11
|
+
Nominatim::Place.new(get('/reverse', @criteria).body)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Latitude string to search for.
|
15
|
+
#
|
16
|
+
# @param lat [String] Latitude
|
17
|
+
# @return [Nominatim::Reverse]
|
18
|
+
def lat(lat)
|
19
|
+
@criteria[:lat] = lat
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
# Longitude string to search for.
|
24
|
+
#
|
25
|
+
# @param lon [String] Longitude
|
26
|
+
# @return [Nominatim::Reverse]
|
27
|
+
def lon(lon)
|
28
|
+
@criteria[:lon] = lon
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
# Include a breakdown of the address into elements.
|
33
|
+
#
|
34
|
+
# @param bool [true, false]
|
35
|
+
# @return [Nominatim::Reverse]
|
36
|
+
def address_details(bool)
|
37
|
+
@criteria[:addressdetails] = bool ? 1 : 0
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
data/lib/nominatim/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"place_id":"13686660","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"1241690521","lat":"37.733976","lon":"-122.3912081","display_name":"4900, 3rd Street, San Francisco, California, 94124, United States of America","address":{"house_number":"4900","road":"3rd Street","city":"San Francisco","county":"San Francisco","state":"California","postcode":"94124","country":"United States of America","country_code":"us"}}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nominatim::Reverse do
|
4
|
+
|
5
|
+
let(:reverse) { Nominatim::Reverse.new }
|
6
|
+
|
7
|
+
it 'has no criteria set' do
|
8
|
+
reverse.criteria.should be_empty
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'allows chaining of criterions' do
|
12
|
+
reverse.lat('37.733976').lon('-122.3912081').address_details(1)
|
13
|
+
reverse.criteria[:lat].should eq '37.733976'
|
14
|
+
reverse.criteria[:lon].should eq '-122.3912081'
|
15
|
+
reverse.criteria[:addressdetails].should eq 1
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#each' do
|
19
|
+
let(:reverse) { Nominatim::Reverse.new.lat('37.733976').lon('-122.3912081').address_details(1) }
|
20
|
+
|
21
|
+
before do
|
22
|
+
stub_get('/reverse').
|
23
|
+
with(query: { lat: '37.733976', lon: '-122.3912081', addressdetails: 1 }).
|
24
|
+
to_return(body: fixture('reverse.json'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'iterates over the matching places' do
|
28
|
+
reverse.fetch.should be_a Nominatim::Place
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns correct places' do
|
32
|
+
reverse.fetch.display_name.should eq '4900, 3rd Street, San Francisco, California, 94124, United States of America'
|
33
|
+
reverse.fetch.address.city.should eq 'San Francisco'
|
34
|
+
reverse.fetch.address.state.should eq 'California'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#lat' do
|
39
|
+
it 'adds a latitude criterion' do
|
40
|
+
reverse.lat('37.733976')
|
41
|
+
reverse.criteria[:lat].should eq '37.733976'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#lon' do
|
46
|
+
it 'adds a longitude criterion' do
|
47
|
+
reverse.lon('-122.3912081')
|
48
|
+
reverse.criteria[:lon].should eq '-122.3912081'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#address_details' do
|
53
|
+
it 'adds an address details criterion' do
|
54
|
+
reverse.address_details(true)
|
55
|
+
reverse.criteria[:addressdetails].should eq 1
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets 1 when set with true' do
|
59
|
+
reverse.address_details(true)
|
60
|
+
reverse.criteria[:addressdetails].should eq 1
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'sets 0 when set with false' do
|
64
|
+
reverse.address_details(false)
|
65
|
+
reverse.criteria[:addressdetails].should eq 0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/nominatim_spec.rb
CHANGED
@@ -12,6 +12,18 @@ describe Nominatim do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
describe '.reverse' do
|
16
|
+
it 'returns a Nominatim::Reverse' do
|
17
|
+
Nominatim.reverse.should be_a Nominatim::Reverse
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'adds a reverse query criteria if given as a parameters' do
|
21
|
+
reverse = Nominatim.reverse('37.733976', '-122.3912081')
|
22
|
+
reverse.criteria[:lat].should eq '37.733976'
|
23
|
+
reverse.criteria[:lon].should eq '-122.3912081'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
15
27
|
describe '.configure' do
|
16
28
|
|
17
29
|
before do
|
@@ -51,4 +63,4 @@ describe Nominatim do
|
|
51
63
|
Nominatim.config.email.should eq "foo@bar.com"
|
52
64
|
end
|
53
65
|
end
|
54
|
-
end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nominatim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -147,15 +147,18 @@ files:
|
|
147
147
|
- lib/nominatim/point.rb
|
148
148
|
- lib/nominatim/polygon.rb
|
149
149
|
- lib/nominatim/response/parse_json.rb
|
150
|
+
- lib/nominatim/reverse.rb
|
150
151
|
- lib/nominatim/search.rb
|
151
152
|
- lib/nominatim/version.rb
|
152
153
|
- nominatim.gemspec
|
154
|
+
- spec/fixtures/reverse.json
|
153
155
|
- spec/fixtures/search.json
|
154
156
|
- spec/nominatim/address_spec.rb
|
155
157
|
- spec/nominatim/client_spec.rb
|
156
158
|
- spec/nominatim/place_spec.rb
|
157
159
|
- spec/nominatim/point_spec.rb
|
158
160
|
- spec/nominatim/polygon_spec.rb
|
161
|
+
- spec/nominatim/reverse_spec.rb
|
159
162
|
- spec/nominatim/search_spec.rb
|
160
163
|
- spec/nominatim_spec.rb
|
161
164
|
- spec/spec_helper.rb
|
@@ -171,12 +174,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
174
|
- - ! '>='
|
172
175
|
- !ruby/object:Gem::Version
|
173
176
|
version: '0'
|
177
|
+
segments:
|
178
|
+
- 0
|
179
|
+
hash: 1511415446284472130
|
174
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
181
|
none: false
|
176
182
|
requirements:
|
177
183
|
- - ! '>='
|
178
184
|
- !ruby/object:Gem::Version
|
179
185
|
version: '0'
|
186
|
+
segments:
|
187
|
+
- 0
|
188
|
+
hash: 1511415446284472130
|
180
189
|
requirements: []
|
181
190
|
rubyforge_project:
|
182
191
|
rubygems_version: 1.8.23
|
@@ -184,12 +193,14 @@ signing_key:
|
|
184
193
|
specification_version: 3
|
185
194
|
summary: A Ruby wrapper for the Nominatim API.
|
186
195
|
test_files:
|
196
|
+
- spec/fixtures/reverse.json
|
187
197
|
- spec/fixtures/search.json
|
188
198
|
- spec/nominatim/address_spec.rb
|
189
199
|
- spec/nominatim/client_spec.rb
|
190
200
|
- spec/nominatim/place_spec.rb
|
191
201
|
- spec/nominatim/point_spec.rb
|
192
202
|
- spec/nominatim/polygon_spec.rb
|
203
|
+
- spec/nominatim/reverse_spec.rb
|
193
204
|
- spec/nominatim/search_spec.rb
|
194
205
|
- spec/nominatim_spec.rb
|
195
206
|
- spec/spec_helper.rb
|