open_street_map 0.1.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8590c3c8a1547bd9e558e8aca7a9173e5a47aa8c0efcc2dbca0b3b92a79ca6f5
4
- data.tar.gz: 1e0068a04ca2da16c7dbf0d7033aca125775650c2ee553fe6bf864aa2d233b44
3
+ metadata.gz: 0245145c2c7910156d7e9104e20a8473fd68c121b03adfd362d11a6fb72de5ff
4
+ data.tar.gz: 5e22a03e1249dc6ba2461c190e15d155b85c3d69a93e66f170b3de94c74263e7
5
5
  SHA512:
6
- metadata.gz: a9e91b075933e006f7d7f299b3b16e3bbd8e3e873d3f57cb97646b23c1eb12b0e6bc4a097e5fcfde8f5d264123b8e579faf7dd46eebfadc32cf92752602eef82
7
- data.tar.gz: 19772c38fe7dd7945ac226053715581cf561fe40eaafeda7249718f338e399a93e9dec871ee303e1f2e59e4b867119aee185deae8064ee7e108f6a7558218758
6
+ metadata.gz: e06ec27a0c5f8540a09cc107967c16ae70ec0dd700e767889806795e8aeed893d716155a93f60363ae3107e7f529206fb727a329fa625acc6696c81be9cb1d71
7
+ data.tar.gz: f28a7bcf80fb0375b56502bad6aef3c7727396b1906997d2a520ab0cbfe111977c67f91477e82dcb30426d37e121c7ee2d511ede5a5168afbd989aaf4d77a6c2
data/.rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - bin/*
4
+ TargetRubyVersion: 2.5.0
4
5
 
5
6
  Metrics/AbcSize:
6
7
  Enabled: false
@@ -39,11 +40,18 @@ Layout/AlignHash:
39
40
  Style/GuardClause:
40
41
  Enabled: false
41
42
 
42
- Style/FileName:
43
+ Naming:
43
44
  Enabled: false
44
45
 
45
46
  Style/FormatStringToken:
46
47
  EnforcedStyle: template
47
48
 
48
49
  Style/ExpandPathArguments:
49
- Enabled: false
50
+ Enabled: false
51
+
52
+ Style/FrozenStringLiteralComment:
53
+ Enabled: false
54
+
55
+ Style/RescueStandardError:
56
+ Enabled: false
57
+
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # OpenStreetMap
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/open_street_map`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Integration of OpenStreetMap api from [Nominatim](https://wiki.openstreetmap.org/wiki/Nominatim)
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,22 +20,107 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ### Create OpenStreetMap client object
24
+
25
+ ```ruby
26
+ client = OpenStreetMap::Client.new
27
+ ```
28
+
29
+ ### Search
30
+
31
+ Request for search objects is #search.
32
+
33
+ ```ruby
34
+ client.search(q: '135 pilkington avenue, birmingham', format: 'json', addressdetails: '1')
35
+ ```
36
+ q - query
37
+ format - one of the [xml|json|jsonv2]
38
+ viewbox - The preferred area to find search results like <x1>,<y1>,<x2>,<y2>
39
+ bounded - Restrict the results to only items contained with the viewbox, one of the [0|1]
40
+ addressdetails - Include a breakdown of the address into elements, one of the [0|1]
41
+ exclude_place_ids - If you do not want certain openstreetmap objects to appear in the search result, give a comma separated list of the place_id's you want to skip
42
+ limit - Limit the number of returned results, integer
43
+ extratags - Include additional information in the result if available, one of the [0|1]
44
+ namedetails - Include a list of alternative names in the results, one of the [0|1]
45
+
46
+ #### Responces
47
+
48
+ ```ruby
49
+ [
50
+ {
51
+ "place_id":"91015286",
52
+ "licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright",
53
+ "osm_type":"way",
54
+ "osm_id":"90394480",
55
+ "boundingbox":["52.5487473","52.5488481","-1.816513","-1.8163464"],
56
+ "lat":"52.5487921",
57
+ "lon":"-1.8164308339635",
58
+ "display_name":"135, Pilkington Avenue, Sutton Coldfield, Бирмингем, West Midlands Combined Authority, Западный Мидленд, Англия, B72 1LH, Великобритания",
59
+ "class":"building",
60
+ "type":"yes",
61
+ "importance":0.31025,
62
+ "address": {
63
+ "house_number":"135",
64
+ "road":"Pilkington Avenue",
65
+ "town":"Sutton Coldfield",
66
+ "city":"Бирмингем",
67
+ "county":"West Midlands Combined Authority",
68
+ "state_district":"Западный Мидленд",
69
+ "state":"Англия",
70
+ "postcode":"B72 1LH",
71
+ "country":"Великобритания",
72
+ "country_code":"gb"
73
+ }
74
+ }
75
+ ]
76
+ ```
77
+
78
+ ### Reverse
26
79
 
27
- ## Development
80
+ Request for objects by coordinates is #reverse.
81
+
82
+ ```ruby
83
+ client.reverse(format: 'json', lat: '52.594417', lon: '39.493115')
84
+ ```
85
+ format - one of the [xml|json|jsonv2]
86
+ zoom - Level of detail required where 0 is country and 18 is house/building, one of the [0-18]
87
+ addressdetails - Include a breakdown of the address into elements, one of the [0|1]
88
+ lat - Latitude, required
89
+ lon - Longitude, required
90
+ extratags - Include additional information in the result if available, one of the [0|1]
91
+ namedetails - Include a list of alternative names in the results, one of the [0|1]
28
92
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
93
+ #### Responces
30
94
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
95
+ ```ruby
96
+ {
97
+ "place_id":"150727169",
98
+ "licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright",
99
+ "osm_type":"way",
100
+ "osm_id":"367091730",
101
+ "lat":"52.5944624",
102
+ "lon":"39.4931348495468",
103
+ "display_name":"4, улица Хренникова, микрорайон Елецкий, Сырский рудник, Советский округ, Липецк, городской округ Липецк, Липецкая область, Центральный федеральный округ, 398000, РФ",
104
+ "address":{
105
+ "house_number":"4",
106
+ "road":"улица Хренникова",
107
+ "residential":"микрорайон Елецкий",
108
+ "suburb":"городской округ Липецк",
109
+ "city_district":"Советский округ",
110
+ "city":"Липецк",
111
+ "state":"Липецкая область",
112
+ "postcode":"398000",
113
+ "country":"РФ",
114
+ "country_code":"ru"
115
+ },
116
+ "boundingbox":["52.5943024","52.5946223","39.4929211","39.4933486"]
117
+ }
118
+ ```
32
119
 
33
120
  ## Contributing
34
121
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/WebGents/open_street_map. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
122
+ Bug reports and pull requests are welcome on GitHub at https://github.com/WebGents/open_street_map.
36
123
 
37
124
  ## License
38
125
 
39
126
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the OpenStreetMap project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/open_street_map/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,26 @@
1
+ module OpenStreetMap
2
+ class Client
3
+ # Reverse geocoding generates an address from a latitude and longitude
4
+ module Reverse
5
+ def reverse(args = {})
6
+ response = RestClient.get("#{BASE_URI}reverse?#{reverse_args_to_url(args)}")
7
+ args[:format] == 'xml' ? response.body : JSON.parse(response.body)
8
+ rescue
9
+ { 'errors' => 'Bad request' }
10
+ end
11
+
12
+ private
13
+
14
+ def reverse_args_to_url(args, result = [])
15
+ valid_reverse_args(args).each do |key, value|
16
+ result << "#{key}=#{value}"
17
+ end
18
+ result.join('&')
19
+ end
20
+
21
+ def valid_reverse_args(args)
22
+ args.slice(:format, :lat, :lon, :zoom, :addressdetails, :extratags, :namedetails)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module OpenStreetMap
2
+ class Client
3
+ # Search objects by query
4
+ module Search
5
+ def search(args = {})
6
+ response = RestClient.get("#{BASE_URI}search?#{search_arg(args[:q])}&#{search_args_to_url(args)}")
7
+ args[:format] == 'xml' ? response.body : JSON.parse(response.body)
8
+ rescue
9
+ { 'errors' => 'Bad request' }
10
+ end
11
+
12
+ private
13
+
14
+ def search_arg(arg)
15
+ "q=#{arg.gsub(/\s+/, '+')}"
16
+ end
17
+
18
+ def search_args_to_url(args, result = [])
19
+ valid_search_args(args).each do |key, value|
20
+ result << "#{key}=#{value}"
21
+ end
22
+ result.join('&')
23
+ end
24
+
25
+ def valid_search_args(args)
26
+ args.slice(:format, :addressdetails, :extratags, :namedetails, :viewbox, :bounded, :exclude_place_ids, :limit)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require_relative 'client/reverse'
4
+ require_relative 'client/search'
5
+
6
+ module OpenStreetMap
7
+ # Client requests
8
+ class Client
9
+ include OpenStreetMap::Client::Reverse
10
+ include OpenStreetMap::Client::Search
11
+
12
+ BASE_URI = 'https://nominatim.openstreetmap.org/'.freeze
13
+
14
+ def initialize(args = {}); end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module OpenStreetMap
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '1.0'.freeze
3
3
  end
@@ -1,5 +1,6 @@
1
- require 'open_street_map/version'
1
+ require_relative 'open_street_map/version'
2
+ require_relative 'open_street_map/client'
2
3
 
3
- # Mail declaration
4
+ # Main declaration
4
5
  module OpenStreetMap
5
6
  end
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
+ spec.required_ruby_version = '>= 2.5.0'
24
+
23
25
  spec.add_development_dependency 'bundler', '~> 1.15'
24
26
  spec.add_development_dependency 'rake', '~> 10.0'
25
27
  spec.add_development_dependency 'rspec', '~> 3.0'
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: 0.1.0
4
+ version: '1.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: 2018-07-02 00:00:00.000000000 Z
12
+ date: 2018-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -100,6 +100,9 @@ files:
100
100
  - bin/console
101
101
  - bin/setup
102
102
  - lib/open_street_map.rb
103
+ - lib/open_street_map/client.rb
104
+ - lib/open_street_map/client/reverse.rb
105
+ - lib/open_street_map/client/search.rb
103
106
  - lib/open_street_map/version.rb
104
107
  - open_street_map.gemspec
105
108
  homepage: https://github.com/WebGents/open_street_map
@@ -114,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
117
  requirements:
115
118
  - - ">="
116
119
  - !ruby/object:Gem::Version
117
- version: '0'
120
+ version: 2.5.0
118
121
  required_rubygems_version: !ruby/object:Gem::Requirement
119
122
  requirements:
120
123
  - - ">="