parallel588_nominatim 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +8 -0
- data/Guardfile +13 -0
- data/LICENSE +22 -0
- data/README.md +90 -0
- data/Rakefile +11 -0
- data/lib/nominatim/address.rb +83 -0
- data/lib/nominatim/client.rb +41 -0
- data/lib/nominatim/configuration.rb +49 -0
- data/lib/nominatim/place.rb +93 -0
- data/lib/nominatim/point.rb +30 -0
- data/lib/nominatim/polygon.rb +13 -0
- data/lib/nominatim/response/parse_json.rb +16 -0
- data/lib/nominatim/reverse.rb +44 -0
- data/lib/nominatim/search.rb +99 -0
- data/lib/nominatim/version.rb +3 -0
- data/lib/nominatim.rb +36 -0
- data/nominatim.gemspec +26 -0
- data/spec/fixtures/reverse.json +1 -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 +172 -0
- data/spec/nominatim/point_spec.rb +53 -0
- data/spec/nominatim/polygon_spec.rb +19 -0
- data/spec/nominatim/reverse_spec.rb +68 -0
- data/spec/nominatim/search_spec.rb +140 -0
- data/spec/nominatim_spec.rb +66 -0
- data/spec/spec_helper.rb +38 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c87c3a865bd29b87e5167aa9e96a723c2c18f34
|
4
|
+
data.tar.gz: 7dea46b5fba7824df8734cf43cbe455ab99728e8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ecd2cb433ba0c71ad3a7cb94c5a0fdbd7a3bf57ea8763327c246101ea4379c8fb7a8715c07d593d11118e229bde63f22765d63f32d048db03c6eb145920a2c8a
|
7
|
+
data.tar.gz: 4e72f15402d6ca7d71cda3c25fc9d864319b3853154b6008b2fbb098a026b3ee29b91910fb8dc8fef8edc2a239194c545faeb8c6fd0959bb5610406b07871e8c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'bundler' do
|
5
|
+
watch('Gemfile')
|
6
|
+
watch(/^.+\.gemspec/)
|
7
|
+
end
|
8
|
+
|
9
|
+
guard 'rspec', :version => 2 do
|
10
|
+
watch(%r{^spec/.+_spec\.rb$})
|
11
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
12
|
+
watch('spec/spec_helper.rb') { "spec" }
|
13
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jakub Svehla
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Nominatim
|
2
|
+
|
3
|
+
A Ruby wrapper for the Nominatim API. [![Build Status](https://secure.travis-ci.org/jakubsvehla/nominatim.png?branch=master)](http://travis-ci.org/jakubsvehla/nominatim)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'nominatim'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install nominatim
|
18
|
+
|
19
|
+
## Documentation
|
20
|
+
|
21
|
+
[http://rdoc.info/gems/nominatim][documentation]
|
22
|
+
|
23
|
+
[documentation]: http://rdoc.info/gems/nominatim
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
places = Nominatim.search('San Francisco').limit(10).address_details(true)
|
29
|
+
|
30
|
+
for place in places
|
31
|
+
puts "#{place.display_name} (#{place.type})"
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "Found #{places.count} places."
|
35
|
+
```
|
36
|
+
|
37
|
+
## Configuration
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
Nominatim.configure do |config|
|
41
|
+
config.email = 'your-email-address@example.com'
|
42
|
+
config.endpoint = 'http://open.mapquestapi.com/nominatim/v1'
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. [Fork the repository.][fork]
|
49
|
+
2. [Create a topic branch.][branch]
|
50
|
+
3. Add specs for your unimplemented feature or bug fix.
|
51
|
+
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
|
52
|
+
5. Implement your feature or bug fix.
|
53
|
+
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
|
54
|
+
7. Run `open coverage/index.html`. If your changes are not completely covered
|
55
|
+
by your tests, return to step 3.
|
56
|
+
8. Add, commit, and push your changes.
|
57
|
+
9. [Submit a pull request.][pr]
|
58
|
+
|
59
|
+
[fork]: http://help.github.com/fork-a-repo/
|
60
|
+
[branch]: http://learn.github.com/p/branching.html
|
61
|
+
[pr]: http://help.github.com/send-pull-requests/
|
62
|
+
|
63
|
+
## Supported Ruby Versions
|
64
|
+
|
65
|
+
Nominatim is tested under 1.9.2 and 1.9.3.
|
66
|
+
|
67
|
+
## Copyright
|
68
|
+
|
69
|
+
Copyright (c) 2012 Jakub Svehla
|
70
|
+
|
71
|
+
MIT License
|
72
|
+
|
73
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
74
|
+
a copy of this software and associated documentation files (the
|
75
|
+
"Software"), to deal in the Software without restriction, including
|
76
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
77
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
78
|
+
permit persons to whom the Software is furnished to do so, subject to
|
79
|
+
the following conditions:
|
80
|
+
|
81
|
+
The above copyright notice and this permission notice shall be
|
82
|
+
included in all copies or substantial portions of the Software.
|
83
|
+
|
84
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
85
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
86
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
87
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
88
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
89
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
90
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
module Nominatim
|
2
|
+
class Address
|
3
|
+
def initialize(attrs = {})
|
4
|
+
@attrs = attrs
|
5
|
+
end
|
6
|
+
|
7
|
+
def attraction
|
8
|
+
@attraction ||= @attrs[:attraction]
|
9
|
+
end
|
10
|
+
|
11
|
+
def clothes
|
12
|
+
@clothes ||= @attrs[:clothes]
|
13
|
+
end
|
14
|
+
|
15
|
+
def house_number
|
16
|
+
@house_number ||= @attrs[:house_number]
|
17
|
+
end
|
18
|
+
|
19
|
+
def road
|
20
|
+
@road ||= @attrs[:road]
|
21
|
+
end
|
22
|
+
|
23
|
+
def commercial
|
24
|
+
@commercial ||= @attrs[:commercial]
|
25
|
+
end
|
26
|
+
|
27
|
+
def pedestrian
|
28
|
+
@pedestrian ||= @attrs[:pedestrian]
|
29
|
+
end
|
30
|
+
|
31
|
+
def suburb
|
32
|
+
@suburb ||= @attrs[:suburb]
|
33
|
+
end
|
34
|
+
|
35
|
+
def city_district
|
36
|
+
@city_district ||= @attrs[:city_district]
|
37
|
+
end
|
38
|
+
|
39
|
+
def city
|
40
|
+
@city ||= @attrs[:city]
|
41
|
+
end
|
42
|
+
|
43
|
+
def administrative
|
44
|
+
@administrative ||= @attrs[:administrative]
|
45
|
+
end
|
46
|
+
|
47
|
+
def county
|
48
|
+
@county ||= @attrs[:county]
|
49
|
+
end
|
50
|
+
|
51
|
+
def state_district
|
52
|
+
@state_district ||= @attrs[:state_district]
|
53
|
+
end
|
54
|
+
|
55
|
+
def state
|
56
|
+
@state ||= @attrs[:state]
|
57
|
+
end
|
58
|
+
|
59
|
+
def postcode
|
60
|
+
@postcode ||= @attrs[:postcode]
|
61
|
+
end
|
62
|
+
|
63
|
+
def country
|
64
|
+
@country ||= @attrs[:country]
|
65
|
+
end
|
66
|
+
|
67
|
+
def country_code
|
68
|
+
@country_code ||= @attrs[:country_code]
|
69
|
+
end
|
70
|
+
|
71
|
+
def place
|
72
|
+
@place ||= @attrs[:place]
|
73
|
+
end
|
74
|
+
|
75
|
+
def town
|
76
|
+
@town ||= @attrs[:town]
|
77
|
+
end
|
78
|
+
|
79
|
+
def village
|
80
|
+
@village ||= @attrs[:village]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Nominatim
|
4
|
+
class Client
|
5
|
+
|
6
|
+
# Performs an HTTP GET request
|
7
|
+
def get(path, params = {})
|
8
|
+
connection.get path, params
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# Returns a Faraday::Connection object
|
14
|
+
#
|
15
|
+
# @return [Faraday::Connection]
|
16
|
+
def connection
|
17
|
+
return @connection if defined? @connection
|
18
|
+
|
19
|
+
options = {
|
20
|
+
request: {
|
21
|
+
timeout: Nominatim.config.timeout
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
options[:proxy] = Nominatim.config.proxy if Nominatim.config.proxy
|
26
|
+
|
27
|
+
@connection = Faraday.new Nominatim.config.endpoint, options do |builder|
|
28
|
+
builder.use Nominatim::Response::ParseJson
|
29
|
+
builder.adapter Faraday.default_adapter
|
30
|
+
end
|
31
|
+
|
32
|
+
@connection.params[:format] = 'json'
|
33
|
+
@connection.params[:email] = Nominatim.config.email if Nominatim.config.email
|
34
|
+
|
35
|
+
@connection.headers[:user_agent] = Nominatim.config.user_agent
|
36
|
+
@connection.headers[:"accept-language"] = Nominatim.config.accept_language
|
37
|
+
|
38
|
+
@connection
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Nominatim
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
DEFAULT_ENDPOINT = 'http://nominatim.openstreetmap.org'
|
5
|
+
|
6
|
+
DEFAULT_USER_AGENT = "Nominatim Ruby Gem #{Nominatim::VERSION}"
|
7
|
+
|
8
|
+
DEFAULT_EMAIL = nil
|
9
|
+
|
10
|
+
DEFAULT_LANGUAGE = 'en'
|
11
|
+
|
12
|
+
DEFAULT_TIMEOUT = nil
|
13
|
+
|
14
|
+
DEFAULT_SEARCH_URL = 'search'
|
15
|
+
DEFAULT_REVERSE_URL = 'reverse'
|
16
|
+
|
17
|
+
VALID_OPTIONS_KEYS = [
|
18
|
+
:endpoint,
|
19
|
+
:user_agent,
|
20
|
+
:email,
|
21
|
+
:accept_language,
|
22
|
+
:timeout,
|
23
|
+
:search_url,
|
24
|
+
:reverse_url,
|
25
|
+
:proxy
|
26
|
+
]
|
27
|
+
|
28
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
29
|
+
|
30
|
+
def initialize
|
31
|
+
reset!
|
32
|
+
end
|
33
|
+
|
34
|
+
def configure
|
35
|
+
yield self
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset!
|
40
|
+
self.endpoint = DEFAULT_ENDPOINT
|
41
|
+
self.user_agent = DEFAULT_USER_AGENT
|
42
|
+
self.email = DEFAULT_EMAIL
|
43
|
+
self.accept_language = DEFAULT_LANGUAGE
|
44
|
+
self.timeout = DEFAULT_TIMEOUT
|
45
|
+
self.search_url = DEFAULT_SEARCH_URL
|
46
|
+
self.reverse_url = DEFAULT_REVERSE_URL
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Nominatim
|
2
|
+
class Place
|
3
|
+
# attr_reader :attrs
|
4
|
+
# alias to_hash attrs
|
5
|
+
|
6
|
+
def initialize(attrs = {})
|
7
|
+
@attrs = attrs
|
8
|
+
end
|
9
|
+
|
10
|
+
# Return display name
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
def display_name
|
14
|
+
@display_name ||= @attrs[:display_name]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Return a class
|
18
|
+
#
|
19
|
+
# @return [String]
|
20
|
+
def class
|
21
|
+
@class ||= @attrs[:class]
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return a type
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
def type
|
28
|
+
@type ||= @attrs[:type]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Return an address
|
32
|
+
#
|
33
|
+
# @return [Nominatim::Address]
|
34
|
+
def address
|
35
|
+
@address ||= Nominatim::Address.new(@attrs[:address]) if @attrs[:address]
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return a latitude
|
39
|
+
#
|
40
|
+
# @return [Float]
|
41
|
+
def lat
|
42
|
+
point.lat
|
43
|
+
end
|
44
|
+
alias latitude lat
|
45
|
+
|
46
|
+
# Return a longitude
|
47
|
+
#
|
48
|
+
# @return [Float]
|
49
|
+
def lon
|
50
|
+
point.lon
|
51
|
+
end
|
52
|
+
alias longitude lon
|
53
|
+
|
54
|
+
def boundingbox
|
55
|
+
@boundingbox ||= @attrs[:boundingbox]
|
56
|
+
end
|
57
|
+
alias bounding_box boundingbox
|
58
|
+
|
59
|
+
# Return a polygon
|
60
|
+
#
|
61
|
+
# @return [Nominatim::Polygon]
|
62
|
+
def polygonpoints
|
63
|
+
@polygonpoints ||= Nominatim::Polygon.new(@attrs[:polygonpoints]) if @attrs[:polygonpoints]
|
64
|
+
end
|
65
|
+
|
66
|
+
# Return a place id
|
67
|
+
#
|
68
|
+
# @return [Integer]
|
69
|
+
def place_id
|
70
|
+
@place_id ||= @attrs[:place_id].to_i if @attrs[:place_id]
|
71
|
+
end
|
72
|
+
|
73
|
+
# Return an OSM id
|
74
|
+
#
|
75
|
+
# @return [Integer]
|
76
|
+
def osm_id
|
77
|
+
@osm_id ||= @attrs[:osm_id].to_i if @attrs[:osm_id]
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return an OSM type
|
81
|
+
#
|
82
|
+
# @return [String]
|
83
|
+
def osm_type
|
84
|
+
@osm_type ||= @attrs[:osm_type]
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def point
|
90
|
+
@point ||= Nominatim::Point.new(@attrs[:lat], @attrs[:lon])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|