power-osmn 0.3.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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +16 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +0 -0
- data/README.md +76 -0
- data/Rakefile +15 -0
- data/lib/osmn/request.rb +23 -0
- data/lib/osmn/search.rb +28 -0
- data/lib/osmn/version.rb +3 -0
- data/lib/osmn.rb +33 -0
- data/osmn.gemspec +24 -0
- data/test/reverse_test.rb +55 -0
- data/test/search_test.rb +63 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 138bcd59b2015968ebdd16a4c60ffdd93a0d09284b86586e745a0d1cac20801c
|
4
|
+
data.tar.gz: 4e92d1bd816b6100ac4d2d4cb0a6bde97d5dacb72639df275a7d051847fe19a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca45c5e1fcaa93b6a82714350bfda7a6ab3eec561eff0a31f0752857da5ecb9414674c5f75eb28ebe1f5f54f2483f03ee09309edde2eae7509cc914e8e7c625f
|
7
|
+
data.tar.gz: 8444dc220df168a03b1f2a640736127bf53573cb889d6e7aaf3bebe730a37dc0355e0b59b3d7fddbd3cd969ce4b06929d4d98187927557afd0c5d840187487d6
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- CC_TEST_REPORTER_ID=cd374ecebbc117b8a6055a17a56200ae87f61844d2c34893eaa0be55e3abf628
|
4
|
+
language: ruby
|
5
|
+
rvm:
|
6
|
+
- 2.2.0
|
7
|
+
- 2.4.2
|
8
|
+
before_script:
|
9
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
10
|
+
- chmod +x ./cc-test-reporter
|
11
|
+
- ./cc-test-reporter before-build
|
12
|
+
script:
|
13
|
+
- bundle exec rake test
|
14
|
+
after_script:
|
15
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
16
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
osmn (0.3.0)
|
5
|
+
ostruct
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
minitest (5.25.4)
|
11
|
+
ostruct (0.6.1)
|
12
|
+
rake (13.2.1)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
arm64-darwin-24
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
minitest
|
20
|
+
osmn!
|
21
|
+
rake
|
22
|
+
|
23
|
+
BUNDLED WITH
|
24
|
+
2.6.2
|
data/LICENSE
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# OSMN [](https://codeclimate.com/github/max-power/osmn/maintainability)
|
2
|
+
|
3
|
+
A Ruby wrapper for the OpenStreetMap Nominatim API.
|
4
|
+
|
5
|
+
> Nominatim is a tool to search osm data by name and address
|
6
|
+
and to generate synthetic addresses of osm points (reverse geocoding).
|
7
|
+
|
8
|
+
Service can be found at http://nominatim.openstreetmap.org
|
9
|
+
API Details can be found at https://nominatim.org/release-docs/develop/api/Overview/
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
$ gem install power-osmn
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
### The easy way:
|
17
|
+
```ruby
|
18
|
+
# search for a place
|
19
|
+
OSMN.search('135 pilkington avenue, birmingham')
|
20
|
+
|
21
|
+
# convert latitude and longitude into a place
|
22
|
+
OSMN.reverse_geocode(52.5487429714954, -1.81602098644987)
|
23
|
+
|
24
|
+
# lookup osm id
|
25
|
+
lookup = OSMN.lookup("R146656","W50637691","N240109189")
|
26
|
+
lookup.map(&:name) # => ["Manchester", "Brandenburger Tor", "Berlin"]
|
27
|
+
|
28
|
+
|
29
|
+
# OSMN status
|
30
|
+
OSMN.status
|
31
|
+
```
|
32
|
+
|
33
|
+
### Search with parameters:
|
34
|
+
You can set any parameter defined in the Nominatim documentation page (https://nominatim.org/release-docs/develop/api/Search/)
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
OSMN.search('10117 Berlin', country: "DE", format: :geojson, polygon_geojson: true)
|
38
|
+
OSMN.search('Paris', featureType: 'city')
|
39
|
+
OSMN.reverse_geocode(52.5487429714954, -1.81602098644987, addressdetails: true)
|
40
|
+
|
41
|
+
params = {
|
42
|
+
lat: 52.5487429714954,
|
43
|
+
lon: -1.81602098644987,
|
44
|
+
'accept-language': 'en',
|
45
|
+
osm_type: 'W',
|
46
|
+
zoom: 18,
|
47
|
+
addressdetails: 1
|
48
|
+
}
|
49
|
+
OSMN.search(params)
|
50
|
+
```
|
51
|
+
|
52
|
+
|
53
|
+
Check the complete list of parameters for each query on the Nominatim documentation page (https://nominatim.org/release-docs/develop/api/Search/)
|
54
|
+
|
55
|
+
## License
|
56
|
+
Permission is hereby granted, free of charge, to any
|
57
|
+
person obtaining a copy of this software and associated
|
58
|
+
documentation files (the "Software"), to deal in the
|
59
|
+
Software without restriction, including without limitation
|
60
|
+
the rights to use, copy, modify, merge, publish,
|
61
|
+
distribute, sublicense, and/or sell copies of the
|
62
|
+
Software, and to permit persons to whom the Software is
|
63
|
+
furnished to do so, subject to the following conditions:
|
64
|
+
|
65
|
+
The above copyright notice and this permission notice
|
66
|
+
shall be included in all copies or substantial portions of
|
67
|
+
the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
70
|
+
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
71
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
72
|
+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
73
|
+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
74
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
75
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
76
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
t.test_files = FileList['test/*_test.rb']
|
7
|
+
end
|
8
|
+
|
9
|
+
desc 'Run tests'
|
10
|
+
task default: :test
|
11
|
+
|
12
|
+
desc 'Open an irb session preloaded with this library'
|
13
|
+
task :console do
|
14
|
+
exec 'irb -rubygems -I lib -r osmn'
|
15
|
+
end
|
data/lib/osmn/request.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module OSMN
|
2
|
+
class Request
|
3
|
+
def initialize(host, path, **params)
|
4
|
+
@host = host
|
5
|
+
@path = path
|
6
|
+
@params = params
|
7
|
+
end
|
8
|
+
|
9
|
+
def fetch
|
10
|
+
Net::HTTP.get uri
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def uri
|
16
|
+
URI::HTTPS.build host: @host, path: @path, query: query
|
17
|
+
end
|
18
|
+
|
19
|
+
def query
|
20
|
+
URI.encode_www_form @params
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/osmn/search.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module OSMN
|
2
|
+
class Search
|
3
|
+
attr_accessor :params
|
4
|
+
|
5
|
+
def initialize(path='/search', **params)
|
6
|
+
@path = path
|
7
|
+
@params = default_params.merge(params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
parse response
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def default_params
|
17
|
+
{ format: :json }
|
18
|
+
end
|
19
|
+
|
20
|
+
def response
|
21
|
+
Request.new(HOST, @path, **params).fetch
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse(response)
|
25
|
+
JSON.parse response, object_class: OpenStruct
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/osmn/version.rb
ADDED
data/lib/osmn.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'osmn/request'
|
5
|
+
require 'osmn/search'
|
6
|
+
require 'osmn/version'
|
7
|
+
|
8
|
+
module OSMN
|
9
|
+
HOST = 'nominatim.openstreetmap.org'.freeze
|
10
|
+
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def search(query = nil, **params)
|
14
|
+
params.merge!(q: query) unless query.to_s.empty?
|
15
|
+
request '/search', **params
|
16
|
+
end
|
17
|
+
|
18
|
+
def reverse_geocode(lat, lon, **params)
|
19
|
+
request '/reverse', **params.merge(lat: lat, lon: lon)
|
20
|
+
end
|
21
|
+
|
22
|
+
def lookup(*osm_ids, **params)
|
23
|
+
request '/lookup', **params.merge(osm_ids: osm_ids.join(','))
|
24
|
+
end
|
25
|
+
|
26
|
+
def status
|
27
|
+
request '/status'
|
28
|
+
end
|
29
|
+
|
30
|
+
def request(path, **params)
|
31
|
+
Search.new(path, **params).call
|
32
|
+
end
|
33
|
+
end
|
data/osmn.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/osmn/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'power-osmn'
|
6
|
+
gem.version = OSMN::VERSION
|
7
|
+
gem.authors = ['Kevin Melchert']
|
8
|
+
gem.email = 'kevin.melchert@gmail.com'
|
9
|
+
gem.summary = 'A Ruby wrapper for the OpenStreetMap Nominatim API.'
|
10
|
+
gem.homepage = 'http://github.com/max-power/osmn'
|
11
|
+
|
12
|
+
gem.files = `git ls-files -z`.split("\x0").reject do |f|
|
13
|
+
f.match(%r{^(test|spec|features)/})
|
14
|
+
end
|
15
|
+
|
16
|
+
gem.test_files = ['test/search_test.rb', 'test/reverse_test.rb']
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
|
19
|
+
gem.required_ruby_version = '>= 3.0'
|
20
|
+
|
21
|
+
gem.add_dependency 'ostruct'
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
gem.add_development_dependency 'minitest'
|
24
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SearchTests < Minitest::Test
|
4
|
+
def test_nil_reverse
|
5
|
+
assert_raises ArgumentError do
|
6
|
+
OSMN.reverse_geocode
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_reverse
|
11
|
+
response = OSMN.reverse_geocode(52.5487921, -1.8164307339635)
|
12
|
+
|
13
|
+
assert_equal '91015286', response.place_id
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_reverse_geocode
|
17
|
+
response = OSMN.reverse_geocode(52.5487429714954, -1.81602098644987, addressdetails: 0)
|
18
|
+
|
19
|
+
assert_equal "91015268", response.place_id
|
20
|
+
assert_equal "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", response.licence
|
21
|
+
assert_equal "way", response.osm_type
|
22
|
+
assert_equal "90394420", response.osm_id
|
23
|
+
assert_equal "52.54877605", response.lat
|
24
|
+
assert_equal "-1.81627033283164", response.lon
|
25
|
+
assert_equal "137, Pilkington Avenue, Sutton Coldfield, Birmingham, West Midlands Combined Authority, West Midlands, England, B72 1LH, UK", response.display_name
|
26
|
+
|
27
|
+
assert_raises NoMethodError do
|
28
|
+
response.address.house_number
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_reverse_geocode_with_address_details
|
33
|
+
response = OSMN.reverse_geocode(52.5487429714954, -1.81602098644987, addressdetails: 1)
|
34
|
+
|
35
|
+
assert_respond_to(response, :place_id)
|
36
|
+
assert_respond_to(response, :licence)
|
37
|
+
assert_respond_to(response, :osm_type)
|
38
|
+
assert_respond_to(response, :osm_id)
|
39
|
+
assert_respond_to(response, :lat)
|
40
|
+
assert_respond_to(response, :lon)
|
41
|
+
assert_respond_to(response, :display_name)
|
42
|
+
assert_respond_to(response, :address)
|
43
|
+
|
44
|
+
assert_respond_to(response.address, :house_number)
|
45
|
+
assert_respond_to(response.address, :road)
|
46
|
+
assert_respond_to(response.address, :suburb)
|
47
|
+
assert_respond_to(response.address, :city)
|
48
|
+
assert_respond_to(response.address, :county)
|
49
|
+
assert_respond_to(response.address, :state_district)
|
50
|
+
assert_respond_to(response.address, :state)
|
51
|
+
assert_respond_to(response.address, :postcode)
|
52
|
+
assert_respond_to(response.address, :country)
|
53
|
+
assert_respond_to(response.address, :country_code)
|
54
|
+
end
|
55
|
+
end
|
data/test/search_test.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SearchTests < Minitest::Test
|
4
|
+
|
5
|
+
def test_nil_search
|
6
|
+
assert_raises ArgumentError do
|
7
|
+
OSMN.search
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_search
|
12
|
+
response = OSMN.search('135 pilkington avenue, birmingham')[0]
|
13
|
+
|
14
|
+
assert_equal('91015286', response.place_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_search_with_no_details
|
18
|
+
response = OSMN.search('135 pilkington avenue, birmingham', addressdetails: 0)[0]
|
19
|
+
|
20
|
+
assert_respond_to(response, :place_id)
|
21
|
+
assert_respond_to(response, :licence)
|
22
|
+
assert_respond_to(response, :osm_type)
|
23
|
+
assert_respond_to(response, :osm_id)
|
24
|
+
assert_respond_to(response, :boundingbox)
|
25
|
+
assert_respond_to(response, :lat)
|
26
|
+
assert_respond_to(response, :lon)
|
27
|
+
assert_respond_to(response, :display_name)
|
28
|
+
assert_respond_to(response, :class)
|
29
|
+
assert_respond_to(response, :type)
|
30
|
+
|
31
|
+
assert_raises NoMethodError do
|
32
|
+
response.address.house_number
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_search_with_details
|
37
|
+
response = OSMN.search('135 pilkington avenue, birmingham', addressdetails: 1)[0]
|
38
|
+
|
39
|
+
assert_respond_to(response, :place_id)
|
40
|
+
assert_respond_to(response, :licence)
|
41
|
+
assert_respond_to(response, :osm_type)
|
42
|
+
assert_respond_to(response, :osm_id)
|
43
|
+
assert_respond_to(response, :boundingbox)
|
44
|
+
assert_respond_to(response, :lat)
|
45
|
+
assert_respond_to(response, :lon)
|
46
|
+
assert_respond_to(response, :display_name)
|
47
|
+
assert_respond_to(response, :class)
|
48
|
+
assert_respond_to(response, :type)
|
49
|
+
assert_respond_to(response, :address)
|
50
|
+
# assert_respond_to(response, :icon)
|
51
|
+
|
52
|
+
assert_respond_to(response.address, :house_number)
|
53
|
+
assert_respond_to(response.address, :road)
|
54
|
+
assert_respond_to(response.address, :suburb)
|
55
|
+
assert_respond_to(response.address, :city)
|
56
|
+
assert_respond_to(response.address, :county)
|
57
|
+
assert_respond_to(response.address, :state_district)
|
58
|
+
assert_respond_to(response.address, :state)
|
59
|
+
assert_respond_to(response.address, :postcode)
|
60
|
+
assert_respond_to(response.address, :country)
|
61
|
+
assert_respond_to(response.address, :country_code)
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: power-osmn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Melchert
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: ostruct
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: minitest
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
email: kevin.melchert@gmail.com
|
55
|
+
executables: []
|
56
|
+
extensions: []
|
57
|
+
extra_rdoc_files: []
|
58
|
+
files:
|
59
|
+
- ".gitignore"
|
60
|
+
- ".travis.yml"
|
61
|
+
- Gemfile
|
62
|
+
- Gemfile.lock
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/osmn.rb
|
67
|
+
- lib/osmn/request.rb
|
68
|
+
- lib/osmn/search.rb
|
69
|
+
- lib/osmn/version.rb
|
70
|
+
- osmn.gemspec
|
71
|
+
- test/reverse_test.rb
|
72
|
+
- test/search_test.rb
|
73
|
+
homepage: http://github.com/max-power/osmn
|
74
|
+
licenses: []
|
75
|
+
metadata: {}
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.6.9
|
91
|
+
specification_version: 4
|
92
|
+
summary: A Ruby wrapper for the OpenStreetMap Nominatim API.
|
93
|
+
test_files:
|
94
|
+
- test/reverse_test.rb
|
95
|
+
- test/search_test.rb
|