open_street_map 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/README.md +1 -1
- data/lib/open_street_map/client/request.rb +10 -58
- data/lib/open_street_map/client.rb +2 -3
- data/lib/open_street_map/version.rb +1 -1
- data/open_street_map.gemspec +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef13982f80f3101da6717ce75cbf3d853e7dbaa2
|
4
|
+
data.tar.gz: d38d83c223e35c0fcf941fc7e8833ebda8f99735
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d01b5afab4da89cc08a4dfe8cb221f1233b01a4148f266b4b22a30a7d31a3ca07b0325eb9962cc6ecb034c930a76381882482bb97da7b6d0ccb4b1b18916a352
|
7
|
+
data.tar.gz: 8af45e7070eae2e6b6fa9fc32d9812ae88ade2c5019a23e2688abfeeb22138dbbc7eaf17ab6c1015eacb5d451656c8b93448394151ca1e19c21d981f578e4aa1
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/README.md
CHANGED
@@ -4,71 +4,28 @@ module OpenStreetMap
|
|
4
4
|
module Request
|
5
5
|
private
|
6
6
|
|
7
|
-
def call(type, args)
|
8
|
-
url = generate_url(type, args)
|
9
|
-
response = fetch(url, args)
|
10
|
-
sleep(REQUEST_TIMEOUT)
|
11
|
-
parse(response, args[:format])
|
12
|
-
rescue
|
13
|
-
{ 'errors' => 'Bad request' }
|
14
|
-
end
|
15
|
-
|
16
|
-
# generate url from args
|
17
|
-
def generate_url(type, args)
|
18
|
-
valid_args_list = valid_args(type)
|
19
|
-
args = args.select { |key, _value| valid_args_list.include?(key) }
|
20
|
-
url = args.inject('') { |acc, (key, value)| acc + add_to_options(key, value, acc) }
|
21
|
-
type + url
|
22
|
-
end
|
23
|
-
|
24
7
|
# make request to API
|
25
|
-
def
|
26
|
-
url = hostname(args[:hostname]) +
|
27
|
-
|
8
|
+
def call(type, args)
|
9
|
+
url = hostname(args[:hostname]) + type
|
10
|
+
headers = { 'User-Agent' => user_agent(args[:user_agent]) }
|
11
|
+
self.class.get(url, query: generate_body(type, args), headers: headers).parsed_response
|
28
12
|
end
|
29
13
|
|
30
|
-
#
|
31
|
-
def
|
32
|
-
if
|
33
|
-
|
34
|
-
else
|
35
|
-
response.body
|
36
|
-
end
|
14
|
+
# generate body from args
|
15
|
+
def generate_body(type, args)
|
16
|
+
args['accept-language'.to_sym] = args[:accept_language] if args.key?(:accept_language)
|
17
|
+
args.select { |key, _| valid_args(type).include?(key) }
|
37
18
|
end
|
38
19
|
|
39
20
|
# get list of permitted args
|
40
21
|
def valid_args(type)
|
41
22
|
case type
|
42
|
-
when 'search' then %i[q format addressdetails extratags namedetails viewbox bounded exclude_place_ids limit
|
43
|
-
when 'reverse' then %i[format lat lon zoom addressdetails extratags namedetails
|
23
|
+
when 'search' then %i[q format addressdetails extratags namedetails viewbox bounded exclude_place_ids limit accept-language email]
|
24
|
+
when 'reverse' then %i[format lat lon zoom addressdetails extratags namedetails accept-language email]
|
44
25
|
else []
|
45
26
|
end
|
46
27
|
end
|
47
28
|
|
48
|
-
# make combination of special symbol and param with value
|
49
|
-
def add_to_options(key, value, acc)
|
50
|
-
symbol_for_param(acc) + key_value_param(key, remove_spaces(value))
|
51
|
-
end
|
52
|
-
|
53
|
-
# select special symbol
|
54
|
-
def symbol_for_param(acc)
|
55
|
-
acc == '' ? '?' : '&'
|
56
|
-
end
|
57
|
-
|
58
|
-
# make combination of param with value
|
59
|
-
def key_value_param(key, value)
|
60
|
-
if key == :accept_language
|
61
|
-
"accept-language=#{value}"
|
62
|
-
else
|
63
|
-
"#{key}=#{value}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# replace spaces with + for values
|
68
|
-
def remove_spaces(value)
|
69
|
-
value.gsub(/\s+/, '+')
|
70
|
-
end
|
71
|
-
|
72
29
|
# select hostname for request
|
73
30
|
def hostname(value)
|
74
31
|
value || BASE_URI
|
@@ -78,11 +35,6 @@ module OpenStreetMap
|
|
78
35
|
def user_agent(value)
|
79
36
|
value || DEFAULT_USER_AGENT
|
80
37
|
end
|
81
|
-
|
82
|
-
# if format equal json then allow parsing
|
83
|
-
def json_parse_valid?(format)
|
84
|
-
format == 'json' || format == 'jsonv2'
|
85
|
-
end
|
86
38
|
end
|
87
39
|
end
|
88
40
|
end
|
@@ -1,15 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
require 'json'
|
1
|
+
require 'httparty'
|
3
2
|
require_relative 'client/request'
|
4
3
|
|
5
4
|
module OpenStreetMap
|
6
5
|
# Client requests
|
7
6
|
class Client
|
7
|
+
include HTTParty
|
8
8
|
include OpenStreetMap::Client::Request
|
9
9
|
|
10
10
|
BASE_URI = 'https://nominatim.openstreetmap.org/'.freeze
|
11
11
|
DEFAULT_USER_AGENT = "webgents/open_street_map_gem_#{SecureRandom.urlsafe_base64}".freeze
|
12
|
-
REQUEST_TIMEOUT = 1
|
13
12
|
|
14
13
|
# Search objects by query
|
15
14
|
def search(args = {})
|
data/open_street_map.gemspec
CHANGED
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
28
|
spec.add_development_dependency 'rubocop', '~> 0.57.2'
|
29
|
-
spec.add_dependency '
|
29
|
+
spec.add_dependency 'httparty', '~> 0.16'
|
30
30
|
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.2.0
|
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:
|
12
|
+
date: 2019-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -68,19 +68,19 @@ dependencies:
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 0.57.2
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: httparty
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: '0.16'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
83
|
+
version: '0.16'
|
84
84
|
description: Integration with OpenStrretMap API
|
85
85
|
email:
|
86
86
|
- kortirso@gmail.com
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- ".gitignore"
|
92
92
|
- ".rspec"
|
93
93
|
- ".rubocop.yml"
|
94
|
+
- ".ruby-version"
|
94
95
|
- ".travis.yml"
|
95
96
|
- CODE_OF_CONDUCT.md
|
96
97
|
- Gemfile
|