nominatim 0.0.1
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/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +8 -0
- data/Guardfile +13 -0
- data/LICENSE +22 -0
- data/README.md +45 -0
- data/Rakefile +11 -0
- data/lib/nominatim.rb +26 -0
- data/lib/nominatim/address.rb +75 -0
- data/lib/nominatim/client.rb +32 -0
- data/lib/nominatim/configuration.rb +33 -0
- data/lib/nominatim/place.rb +57 -0
- data/lib/nominatim/response/parse_json.rb +16 -0
- data/lib/nominatim/search.rb +98 -0
- data/lib/nominatim/version.rb +3 -0
- data/nominatim.gemspec +25 -0
- data/spec/fixtures/search.json +1 -0
- data/spec/nominatim/address_spec.rb +209 -0
- data/spec/nominatim/client_spec.rb +23 -0
- data/spec/nominatim/place_spec.rb +199 -0
- data/spec/nominatim/search_spec.rb +140 -0
- data/spec/nominatim_spec.rb +54 -0
- data/spec/spec_helper.rb +36 -0
- metadata +174 -0
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nominatim::Search do
|
4
|
+
|
5
|
+
let(:search) { Nominatim::Search.new }
|
6
|
+
|
7
|
+
it 'has no criteria set' do
|
8
|
+
search.criteria.should be_empty
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'allows chaining of criterions' do
|
12
|
+
search.query('Los Angeles').limit(1)
|
13
|
+
search.criteria[:q].should eq 'Los Angeles'
|
14
|
+
search.criteria[:limit].should eq 1
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#each' do
|
18
|
+
|
19
|
+
let(:search) { Nominatim::Search.new.query('Los Angeles').limit(1) }
|
20
|
+
|
21
|
+
before do
|
22
|
+
stub_get('/search').
|
23
|
+
with(query: { q: 'Los Angeles', limit: 1 }).
|
24
|
+
to_return(body: fixture('search.json'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'iterates over the matching places' do
|
28
|
+
search.each do |place|
|
29
|
+
place.should be_a Nominatim::Place
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns all matching places' do
|
34
|
+
search.count.should eq 1
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns correct places' do
|
38
|
+
search.first.display_name.should eq 'Los Angeles, California, United States of America'
|
39
|
+
search.first.lat.should eq '34.0966764'
|
40
|
+
search.first.lon.should eq '-117.7196785'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#query' do
|
45
|
+
it 'adds a query criterion' do
|
46
|
+
search.query('Los Angeles')
|
47
|
+
search.criteria[:q].should eq 'Los Angeles'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#country_codes' do
|
52
|
+
it 'adds a country codes criterion' do
|
53
|
+
search.country_codes('us')
|
54
|
+
search.criteria[:countrycodes].should eq 'us'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'adds all country codes when set with an array' do
|
58
|
+
search.country_codes(['us', 'ca'])
|
59
|
+
search.criteria[:countrycodes].should eq 'us,ca'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#viewbox' do
|
64
|
+
it 'adds a viewbox criterion' do
|
65
|
+
search.viewbox(["52.5487442016602", "-1.81651306152344", "52.5488510131836", "-1.81634628772736"])
|
66
|
+
search.criteria[:viewbox].should eq "52.5487442016602,-1.81651306152344,52.5488510131836,-1.81634628772736"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#bounded' do
|
71
|
+
it 'adds a bounded criterion' do
|
72
|
+
search.bounded(true)
|
73
|
+
search.criteria[:bounded].should eq 1
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'sets 1 when set with true' do
|
77
|
+
search.bounded(true)
|
78
|
+
search.criteria[:bounded].should eq 1
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'sets 0 when set with false' do
|
82
|
+
search.bounded(false)
|
83
|
+
search.criteria[:bounded].should eq 0
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#polygon' do
|
88
|
+
it 'adds a polygon criterion' do
|
89
|
+
search.polygon(true)
|
90
|
+
search.criteria[:polygon].should eq 1
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'sets 1 when set with true' do
|
94
|
+
search.polygon(true)
|
95
|
+
search.criteria[:polygon].should eq 1
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'sets 0 when set with false' do
|
99
|
+
search.polygon(false)
|
100
|
+
search.criteria[:polygon].should eq 0
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#address_details' do
|
105
|
+
it 'adds an address details criterion' do
|
106
|
+
search.address_details(true)
|
107
|
+
search.criteria[:addressdetails].should eq 1
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'sets 1 when set with true' do
|
111
|
+
search.address_details(true)
|
112
|
+
search.criteria[:addressdetails].should eq 1
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'sets 0 when set with false' do
|
116
|
+
search.address_details(false)
|
117
|
+
search.criteria[:addressdetails].should eq 0
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#exclude_place_ids' do
|
122
|
+
it 'excludes given place ids' do
|
123
|
+
search.exclude_place_ids('1')
|
124
|
+
search.criteria[:exclude_place_ids].should eq '1'
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'adds all place ids when set with an array' do
|
128
|
+
search.exclude_place_ids(['1', '2', '3'])
|
129
|
+
search.criteria[:exclude_place_ids].should eq '1,2,3'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#limit' do
|
134
|
+
it 'adds a limit criterion' do
|
135
|
+
search.limit(1)
|
136
|
+
search.criteria[:limit].should eq 1
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nominatim do
|
4
|
+
describe '.search' do
|
5
|
+
it 'returns a Nominatim::Search' do
|
6
|
+
Nominatim.search.should be_a Nominatim::Search
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'adds a query criterion if given as a parameter' do
|
10
|
+
search = Nominatim.search('San Francisco')
|
11
|
+
search.criteria[:q].should eq 'San Francisco'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.configure' do
|
16
|
+
|
17
|
+
before do
|
18
|
+
Nominatim.config.reset!
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'has a default endpoint' do
|
22
|
+
Nominatim.config.endpoint.should eq "http://nominatim.openstreetmap.org"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'sets the endpoint' do
|
26
|
+
Nominatim.configure do |config|
|
27
|
+
config.endpoint = "http://nominatim.org/"
|
28
|
+
end
|
29
|
+
Nominatim.config.endpoint.should eq "http://nominatim.org/"
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'has a default user agent' do
|
33
|
+
Nominatim.config.user_agent.should eq "Nominatim Ruby Gem #{Nominatim::VERSION}"
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'sets the user agent' do
|
37
|
+
Nominatim.configure do |config|
|
38
|
+
config.user_agent = "MyApp"
|
39
|
+
end
|
40
|
+
Nominatim.config.user_agent.should eq "MyApp"
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'has a default email' do
|
44
|
+
Nominatim.config.email.should be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets the email' do
|
48
|
+
Nominatim.configure do |config|
|
49
|
+
config.email = "foo@bar.com"
|
50
|
+
end
|
51
|
+
Nominatim.config.email.should eq "foo@bar.com"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'nominatim'
|
8
|
+
require 'webmock/rspec'
|
9
|
+
|
10
|
+
WebMock.disable_net_connect!
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
config.before do
|
18
|
+
Nominatim.config.reset!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def a_get(path)
|
23
|
+
a_request(:get, "#{Nominatim.config.endpoint}#{path}").with(query: { format: 'json' })
|
24
|
+
end
|
25
|
+
|
26
|
+
def stub_get(path)
|
27
|
+
stub_request(:get, "#{Nominatim.config.endpoint}#{path}").with(query: { format: 'json' })
|
28
|
+
end
|
29
|
+
|
30
|
+
def fixture_path
|
31
|
+
File.expand_path('../fixtures', __FILE__)
|
32
|
+
end
|
33
|
+
|
34
|
+
def fixture(file)
|
35
|
+
File.new(fixture_path + '/' + file)
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nominatim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jakub Svehla
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multi_json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.10'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.10'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: webmock
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: yard
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: A Ruby wrapper for the Nominatim API.
|
111
|
+
email:
|
112
|
+
- jakub.svehla@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- .rspec
|
119
|
+
- .travis.yml
|
120
|
+
- CHANGELOG.md
|
121
|
+
- Gemfile
|
122
|
+
- Guardfile
|
123
|
+
- LICENSE
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- lib/nominatim.rb
|
127
|
+
- lib/nominatim/address.rb
|
128
|
+
- lib/nominatim/client.rb
|
129
|
+
- lib/nominatim/configuration.rb
|
130
|
+
- lib/nominatim/place.rb
|
131
|
+
- lib/nominatim/response/parse_json.rb
|
132
|
+
- lib/nominatim/search.rb
|
133
|
+
- lib/nominatim/version.rb
|
134
|
+
- nominatim.gemspec
|
135
|
+
- spec/fixtures/search.json
|
136
|
+
- spec/nominatim/address_spec.rb
|
137
|
+
- spec/nominatim/client_spec.rb
|
138
|
+
- spec/nominatim/place_spec.rb
|
139
|
+
- spec/nominatim/search_spec.rb
|
140
|
+
- spec/nominatim_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
homepage: ''
|
143
|
+
licenses: []
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 1.8.23
|
163
|
+
signing_key:
|
164
|
+
specification_version: 3
|
165
|
+
summary: A Ruby wrapper for the Nominatim API.
|
166
|
+
test_files:
|
167
|
+
- spec/fixtures/search.json
|
168
|
+
- spec/nominatim/address_spec.rb
|
169
|
+
- spec/nominatim/client_spec.rb
|
170
|
+
- spec/nominatim/place_spec.rb
|
171
|
+
- spec/nominatim/search_spec.rb
|
172
|
+
- spec/nominatim_spec.rb
|
173
|
+
- spec/spec_helper.rb
|
174
|
+
has_rdoc:
|