open_street_map 1.0 → 1.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.
- checksums.yaml +4 -4
- data/README.md +15 -3
- data/lib/open_street_map/client.rb +2 -0
- data/lib/open_street_map/client/reverse.rb +4 -2
- data/lib/open_street_map/client/search.rb +4 -2
- data/lib/open_street_map/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ecb1e86901f5a99ee48c747fc4fda5c24e541f45faac9dd20541d112de3b2ab
|
4
|
+
data.tar.gz: b35872595d45d4b7ff9aedb9c157b570ea515d69f7edf00c1d988d89778c4378
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eae9c8162b19e8e508fedf2528091e13edc0e9701a2d4efc447eea465796ffb0200b9cad4bc7429ae490380b41812fcc0013542fcea4bd3d401d57cf82ec7d91
|
7
|
+
data.tar.gz: 54dff490b60bd0e7414e2319faf8bacccbdb71f8129cbfe1350af78ca40298745c83e07099154371f756361f02cb811e9aaa73a690e59123e1c1cfef90a2624c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# OpenStreetMap
|
2
2
|
|
3
|
-
Integration of OpenStreetMap api from [Nominatim](https://wiki.openstreetmap.org/wiki/Nominatim)
|
3
|
+
Integration of OpenStreetMap api from [Nominatim](https://wiki.openstreetmap.org/wiki/Nominatim)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -31,7 +31,7 @@ Or install it yourself as:
|
|
31
31
|
Request for search objects is #search.
|
32
32
|
|
33
33
|
```ruby
|
34
|
-
client.search(q: '135 pilkington avenue, birmingham', format: 'json', addressdetails: '1')
|
34
|
+
client.search(q: '135 pilkington avenue, birmingham', format: 'json', addressdetails: '1', accept_language: 'ru')
|
35
35
|
```
|
36
36
|
q - query
|
37
37
|
format - one of the [xml|json|jsonv2]
|
@@ -42,6 +42,10 @@ Request for search objects is #search.
|
|
42
42
|
limit - Limit the number of returned results, integer
|
43
43
|
extratags - Include additional information in the result if available, one of the [0|1]
|
44
44
|
namedetails - Include a list of alternative names in the results, one of the [0|1]
|
45
|
+
accept_language - Preferred language order for showing search results, default - en
|
46
|
+
email - If you are making large numbers of request please include a valid email address
|
47
|
+
user_agent - User-Agent identifying the application, default - webgents/open_street_map_gem_random
|
48
|
+
hostname - allow overwriting the host name for users who have their own Nominatim installation, default - https://nominatim.openstreetmap.org/
|
45
49
|
|
46
50
|
#### Responces
|
47
51
|
|
@@ -80,7 +84,7 @@ Request for search objects is #search.
|
|
80
84
|
Request for objects by coordinates is #reverse.
|
81
85
|
|
82
86
|
```ruby
|
83
|
-
client.reverse(format: 'json', lat: '52.594417', lon: '39.493115')
|
87
|
+
client.reverse(format: 'json', lat: '52.594417', lon: '39.493115', accept_language: 'ru')
|
84
88
|
```
|
85
89
|
format - one of the [xml|json|jsonv2]
|
86
90
|
zoom - Level of detail required where 0 is country and 18 is house/building, one of the [0-18]
|
@@ -89,6 +93,10 @@ Request for objects by coordinates is #reverse.
|
|
89
93
|
lon - Longitude, required
|
90
94
|
extratags - Include additional information in the result if available, one of the [0|1]
|
91
95
|
namedetails - Include a list of alternative names in the results, one of the [0|1]
|
96
|
+
accept_language - Preferred language order for showing search results, default - en
|
97
|
+
email - If you are making large numbers of request please include a valid email address
|
98
|
+
user_agent - User-Agent identifying the application, default - webgents/open_street_map_gem_random
|
99
|
+
hostname - allow overwriting the host name for users who have their own Nominatim installation, default - https://nominatim.openstreetmap.org/
|
92
100
|
|
93
101
|
#### Responces
|
94
102
|
|
@@ -124,3 +132,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/WebGen
|
|
124
132
|
## License
|
125
133
|
|
126
134
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
135
|
+
|
136
|
+
## Disclaimer
|
137
|
+
|
138
|
+
Use this package at your own peril and risk, the author tried to simplify the use of [Nominatim service](https://wiki.openstreetmap.org/wiki/Nominatim) for integration into Ruby on Rails web applications.
|
@@ -10,6 +10,8 @@ module OpenStreetMap
|
|
10
10
|
include OpenStreetMap::Client::Search
|
11
11
|
|
12
12
|
BASE_URI = 'https://nominatim.openstreetmap.org/'.freeze
|
13
|
+
DEFAULT_USER_AGENT = "webgents/open_street_map_gem_#{SecureRandom.urlsafe_base64}".freeze
|
14
|
+
REQUEST_TIMEOUT = 1
|
13
15
|
|
14
16
|
def initialize(args = {}); end
|
15
17
|
end
|
@@ -3,7 +3,8 @@ module OpenStreetMap
|
|
3
3
|
# Reverse geocoding generates an address from a latitude and longitude
|
4
4
|
module Reverse
|
5
5
|
def reverse(args = {})
|
6
|
-
response = RestClient.get("#{BASE_URI}reverse?#{reverse_args_to_url(args)}")
|
6
|
+
response = RestClient.get("#{args[:hostname] || BASE_URI}reverse?#{reverse_args_to_url(args)}", user_agent: args[:user_agent] || DEFAULT_USER_AGENT)
|
7
|
+
sleep(REQUEST_TIMEOUT)
|
7
8
|
args[:format] == 'xml' ? response.body : JSON.parse(response.body)
|
8
9
|
rescue
|
9
10
|
{ 'errors' => 'Bad request' }
|
@@ -13,13 +14,14 @@ module OpenStreetMap
|
|
13
14
|
|
14
15
|
def reverse_args_to_url(args, result = [])
|
15
16
|
valid_reverse_args(args).each do |key, value|
|
17
|
+
key = 'accept-language' if key == :accept_language
|
16
18
|
result << "#{key}=#{value}"
|
17
19
|
end
|
18
20
|
result.join('&')
|
19
21
|
end
|
20
22
|
|
21
23
|
def valid_reverse_args(args)
|
22
|
-
args.slice(:format, :lat, :lon, :zoom, :addressdetails, :extratags, :namedetails)
|
24
|
+
args.slice(:format, :lat, :lon, :zoom, :addressdetails, :extratags, :namedetails, :accept_language, :email)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -3,7 +3,8 @@ module OpenStreetMap
|
|
3
3
|
# Search objects by query
|
4
4
|
module Search
|
5
5
|
def search(args = {})
|
6
|
-
response = RestClient.get("#{BASE_URI}search?#{search_arg(args[:q])}&#{search_args_to_url(args)}")
|
6
|
+
response = RestClient.get("#{args[:hostname] || BASE_URI}search?#{search_arg(args[:q])}&#{search_args_to_url(args)}", user_agent: args[:user_agent] || DEFAULT_USER_AGENT)
|
7
|
+
sleep(REQUEST_TIMEOUT)
|
7
8
|
args[:format] == 'xml' ? response.body : JSON.parse(response.body)
|
8
9
|
rescue
|
9
10
|
{ 'errors' => 'Bad request' }
|
@@ -17,13 +18,14 @@ module OpenStreetMap
|
|
17
18
|
|
18
19
|
def search_args_to_url(args, result = [])
|
19
20
|
valid_search_args(args).each do |key, value|
|
21
|
+
key = 'accept-language' if key == :accept_language
|
20
22
|
result << "#{key}=#{value}"
|
21
23
|
end
|
22
24
|
result.join('&')
|
23
25
|
end
|
24
26
|
|
25
27
|
def valid_search_args(args)
|
26
|
-
args.slice(:format, :addressdetails, :extratags, :namedetails, :viewbox, :bounded, :exclude_place_ids, :limit)
|
28
|
+
args.slice(:format, :addressdetails, :extratags, :namedetails, :viewbox, :bounded, :exclude_place_ids, :limit, :accept_language, :email)
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_street_map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JungleCoders
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|