geocoder 1.4.9 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geocoder might be problematic. Click here for more details.

Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +352 -958
  4. data/lib/generators/geocoder/config/templates/initializer.rb +1 -1
  5. data/lib/geocoder/cli.rb +2 -2
  6. data/lib/geocoder/configuration.rb +1 -1
  7. data/lib/geocoder/exceptions.rb +1 -1
  8. data/lib/geocoder/ip_address.rb +1 -1
  9. data/lib/geocoder/lookup.rb +1 -2
  10. data/lib/geocoder/lookups/amap.rb +7 -3
  11. data/lib/geocoder/lookups/baidu.rb +14 -10
  12. data/lib/geocoder/lookups/baidu_ip.rb +6 -35
  13. data/lib/geocoder/lookups/ban_data_gouv_fr.rb +4 -4
  14. data/lib/geocoder/lookups/base.rb +21 -3
  15. data/lib/geocoder/lookups/bing.rb +8 -12
  16. data/lib/geocoder/lookups/db_ip_com.rb +9 -6
  17. data/lib/geocoder/lookups/dstk.rb +4 -2
  18. data/lib/geocoder/lookups/esri.rb +1 -16
  19. data/lib/geocoder/lookups/freegeoip.rb +4 -0
  20. data/lib/geocoder/lookups/geocoder_ca.rb +4 -4
  21. data/lib/geocoder/lookups/geocoder_us.rb +17 -9
  22. data/lib/geocoder/lookups/geocodio.rb +5 -5
  23. data/lib/geocoder/lookups/geoportail_lu.rb +7 -7
  24. data/lib/geocoder/lookups/google.rb +8 -8
  25. data/lib/geocoder/lookups/google_places_details.rb +4 -4
  26. data/lib/geocoder/lookups/google_places_search.rb +4 -4
  27. data/lib/geocoder/lookups/google_premier.rb +10 -0
  28. data/lib/geocoder/lookups/here.rb +4 -4
  29. data/lib/geocoder/lookups/ip2location.rb +74 -0
  30. data/lib/geocoder/lookups/ipapi_com.rb +7 -12
  31. data/lib/geocoder/lookups/ipdata_co.rb +4 -0
  32. data/lib/geocoder/lookups/ipinfo_io.rb +10 -19
  33. data/lib/geocoder/lookups/ipstack.rb +9 -10
  34. data/lib/geocoder/lookups/latlon.rb +4 -4
  35. data/lib/geocoder/lookups/location_iq.rb +10 -4
  36. data/lib/geocoder/lookups/mapbox.rb +7 -6
  37. data/lib/geocoder/lookups/mapquest.rb +4 -5
  38. data/lib/geocoder/lookups/maxmind.rb +4 -4
  39. data/lib/geocoder/lookups/maxmind_geoip2.rb +4 -0
  40. data/lib/geocoder/lookups/nominatim.rb +4 -4
  41. data/lib/geocoder/lookups/opencagedata.rb +6 -5
  42. data/lib/geocoder/lookups/pelias.rb +6 -6
  43. data/lib/geocoder/lookups/pickpoint.rb +9 -3
  44. data/lib/geocoder/lookups/pointpin.rb +7 -6
  45. data/lib/geocoder/lookups/postcode_anywhere_uk.rb +4 -5
  46. data/lib/geocoder/lookups/postcodes_io.rb +6 -3
  47. data/lib/geocoder/lookups/smarty_streets.rb +8 -8
  48. data/lib/geocoder/lookups/telize.rb +21 -1
  49. data/lib/geocoder/lookups/yandex.rb +4 -4
  50. data/lib/geocoder/results/baidu.rb +10 -10
  51. data/lib/geocoder/results/base.rb +13 -1
  52. data/lib/geocoder/results/bing.rb +1 -1
  53. data/lib/geocoder/results/db_ip_com.rb +0 -5
  54. data/lib/geocoder/results/freegeoip.rb +0 -5
  55. data/lib/geocoder/results/geocoder_ca.rb +3 -3
  56. data/lib/geocoder/results/geoip2.rb +0 -4
  57. data/lib/geocoder/results/geoportail_lu.rb +5 -3
  58. data/lib/geocoder/results/ip2location.rb +22 -0
  59. data/lib/geocoder/results/ipdata_co.rb +0 -5
  60. data/lib/geocoder/results/maxmind.rb +0 -5
  61. data/lib/geocoder/results/maxmind_local.rb +0 -5
  62. data/lib/geocoder/results/telize.rb +0 -5
  63. data/lib/geocoder/results/test.rb +1 -1
  64. data/lib/geocoder/stores/active_record.rb +0 -2
  65. data/lib/geocoder/version.rb +1 -1
  66. metadata +5 -7
  67. data/lib/geocoder/lookups/okf.rb +0 -44
  68. data/lib/geocoder/lookups/ovi.rb +0 -62
  69. data/lib/geocoder/results/okf.rb +0 -106
  70. data/lib/geocoder/results/ovi.rb +0 -71
@@ -0,0 +1,22 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Ip2location < Base
5
+
6
+ def address(format = :full)
7
+ "#{city_name} #{zip_code}, #{country_name}".sub(/^[ ,]*/, '')
8
+ end
9
+
10
+ def self.response_attributes
11
+ %w[country_code country_name region_name city_name latitude longitude
12
+ zip_code time_zone isp domain net_speed idd_code area_code usage_type
13
+ weather_station_code weather_station_name mcc mnc mobile_brand elevation]
14
+ end
15
+
16
+ response_attributes.each do |attr|
17
+ define_method attr do
18
+ @data[attr] || ""
19
+ end
20
+ end
21
+ end
22
+ end
@@ -3,11 +3,6 @@ require 'geocoder/results/base'
3
3
  module Geocoder::Result
4
4
  class IpdataCo < Base
5
5
 
6
- def address(format = :full)
7
- s = state_code.to_s == "" ? "" : ", #{state_code}"
8
- "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
9
- end
10
-
11
6
  def city
12
7
  @data['city']
13
8
  end
@@ -87,11 +87,6 @@ module Geocoder::Result
87
87
  [data_hash[:latitude].to_f, data_hash[:longitude].to_f]
88
88
  end
89
89
 
90
- def address(format = :full)
91
- s = state_code.to_s == "" ? "" : ", #{state_code}"
92
- "#{city}#{s} #{postal_code}, #{country_code}".sub(/^[ ,]*/, "")
93
- end
94
-
95
90
  def city
96
91
  data_hash[:city_name]
97
92
  end
@@ -3,11 +3,6 @@ require 'geocoder/results/base'
3
3
  module Geocoder::Result
4
4
  class MaxmindLocal < Base
5
5
 
6
- def address(format = :full)
7
- s = state.to_s == "" ? "" : ", #{state}"
8
- "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
9
- end
10
-
11
6
  def coordinates
12
7
  [@data[:latitude], @data[:longitude]]
13
8
  end
@@ -3,11 +3,6 @@ require 'geocoder/results/base'
3
3
  module Geocoder::Result
4
4
  class Telize < Base
5
5
 
6
- def address(format = :full)
7
- s = state_code.to_s == "" ? "" : ", #{state_code}"
8
- "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
9
- end
10
-
11
6
  def city
12
7
  @data['city']
13
8
  end
@@ -15,7 +15,7 @@ module Geocoder
15
15
  end
16
16
  end
17
17
 
18
- %w[latitude longitude neighborhood city state state_code sub_state
18
+ %w[coordinates neighborhood city state state_code sub_state
19
19
  sub_state_code province province_code postal_code country
20
20
  country_code address street_address street_number route geometry].each do |attr|
21
21
  add_result_attribute(attr)
@@ -166,8 +166,6 @@ module Geocoder::Store
166
166
  }
167
167
  end
168
168
 
169
- private # ----------------------------------------------------------------
170
-
171
169
  ##
172
170
  # SQL for calculating distance based on the current database's
173
171
  # capabilities (trig functions?).
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.4.9"
2
+ VERSION = "1.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geocoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.9
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-27 00:00:00.000000000 Z
11
+ date: 2018-07-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides object geocoding (by street or IP address), reverse geocoding
14
14
  (coordinates to street address), distance queries for ActiveRecord and Mongoid,
@@ -68,6 +68,7 @@ files:
68
68
  - lib/geocoder/lookups/google_places_search.rb
69
69
  - lib/geocoder/lookups/google_premier.rb
70
70
  - lib/geocoder/lookups/here.rb
71
+ - lib/geocoder/lookups/ip2location.rb
71
72
  - lib/geocoder/lookups/ipapi_com.rb
72
73
  - lib/geocoder/lookups/ipdata_co.rb
73
74
  - lib/geocoder/lookups/ipinfo_io.rb
@@ -81,9 +82,7 @@ files:
81
82
  - lib/geocoder/lookups/maxmind_geoip2.rb
82
83
  - lib/geocoder/lookups/maxmind_local.rb
83
84
  - lib/geocoder/lookups/nominatim.rb
84
- - lib/geocoder/lookups/okf.rb
85
85
  - lib/geocoder/lookups/opencagedata.rb
86
- - lib/geocoder/lookups/ovi.rb
87
86
  - lib/geocoder/lookups/pelias.rb
88
87
  - lib/geocoder/lookups/pickpoint.rb
89
88
  - lib/geocoder/lookups/pointpin.rb
@@ -121,6 +120,7 @@ files:
121
120
  - lib/geocoder/results/google_places_search.rb
122
121
  - lib/geocoder/results/google_premier.rb
123
122
  - lib/geocoder/results/here.rb
123
+ - lib/geocoder/results/ip2location.rb
124
124
  - lib/geocoder/results/ipapi_com.rb
125
125
  - lib/geocoder/results/ipdata_co.rb
126
126
  - lib/geocoder/results/ipinfo_io.rb
@@ -134,9 +134,7 @@ files:
134
134
  - lib/geocoder/results/maxmind_geoip2.rb
135
135
  - lib/geocoder/results/maxmind_local.rb
136
136
  - lib/geocoder/results/nominatim.rb
137
- - lib/geocoder/results/okf.rb
138
137
  - lib/geocoder/results/opencagedata.rb
139
- - lib/geocoder/results/ovi.rb
140
138
  - lib/geocoder/results/pelias.rb
141
139
  - lib/geocoder/results/pickpoint.rb
142
140
  - lib/geocoder/results/pointpin.rb
@@ -175,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
173
  requirements:
176
174
  - - ">="
177
175
  - !ruby/object:Gem::Version
178
- version: 1.9.3
176
+ version: 2.0.0
179
177
  required_rubygems_version: !ruby/object:Gem::Requirement
180
178
  requirements:
181
179
  - - ">="
@@ -1,44 +0,0 @@
1
- require 'geocoder/lookups/base'
2
- require "geocoder/results/okf"
3
-
4
- module Geocoder::Lookup
5
- class Okf < Base
6
-
7
- def name
8
- "Okf"
9
- end
10
-
11
- def query_url(query)
12
- "#{protocol}://data.okf.fi/gis/1/geocode/json?" + url_query_string(query)
13
- end
14
-
15
- private # ---------------------------------------------------------------
16
-
17
- def valid_response?(response)
18
- json = parse_json(response.body)
19
- status = json["status"] if json
20
- super(response) and ['OK', 'ZERO_RESULTS'].include?(status)
21
- end
22
-
23
- def results(query)
24
- return [] unless doc = fetch_data(query)
25
- case doc['status']; when "OK" # OK status implies >0 results
26
- return doc['results']
27
- end
28
- return []
29
- end
30
-
31
- def query_url_okf_params(query)
32
- params = {
33
- (query.reverse_geocode? ? :latlng : :address) => query.sanitized_text,
34
- :sensor => "false",
35
- :language => (query.language || configuration.language)
36
- }
37
- params
38
- end
39
-
40
- def query_url_params(query)
41
- query_url_okf_params(query).merge(super)
42
- end
43
- end
44
- end
@@ -1,62 +0,0 @@
1
- require 'geocoder/lookups/base'
2
- require 'geocoder/results/ovi'
3
-
4
- module Geocoder::Lookup
5
- class Ovi < Base
6
-
7
- def name
8
- "Ovi"
9
- end
10
-
11
- def required_api_key_parts
12
- []
13
- end
14
-
15
- def query_url(query)
16
- "#{protocol}://lbs.ovi.com/search/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" + url_query_string(query)
17
- end
18
-
19
- private # ---------------------------------------------------------------
20
-
21
- def results(query)
22
- return [] unless doc = fetch_data(query)
23
- return [] unless doc['Response'] && doc['Response']['View']
24
- if r=doc['Response']['View']
25
- return [] if r.nil? || !r.is_a?(Array) || r.empty?
26
- return r.first['Result']
27
- end
28
- []
29
- end
30
-
31
- def query_url_params(query)
32
- options = {
33
- :gen=>1,
34
- :app_id=>api_key,
35
- :app_code=>api_code
36
- }
37
-
38
- if query.reverse_geocode?
39
- super.merge(options).merge(
40
- :prox=>query.sanitized_text,
41
- :mode=>:retrieveAddresses
42
- )
43
- else
44
- super.merge(options).merge(
45
- :searchtext=>query.sanitized_text
46
- )
47
- end
48
- end
49
-
50
- def api_key
51
- if a=configuration.api_key
52
- return a.first if a.is_a?(Array)
53
- end
54
- end
55
-
56
- def api_code
57
- if a=configuration.api_key
58
- return a.last if a.is_a?(Array)
59
- end
60
- end
61
- end
62
- end
@@ -1,106 +0,0 @@
1
- require 'geocoder/results/base'
2
-
3
- module Geocoder::Result
4
- class Okf < Base
5
-
6
- def coordinates
7
- ['lat', 'lng'].map{ |i| geometry['location'][i] }
8
- end
9
-
10
- def address(format = :full)
11
- formatted_address
12
- end
13
-
14
- def city
15
- fields = [:locality, :sublocality,
16
- :administrative_area_level_3,
17
- :administrative_area_level_2]
18
- fields.each do |f|
19
- if entity = address_components_of_type(f).first
20
- return entity['long_name']
21
- end
22
- end
23
- return nil # no appropriate components found
24
- end
25
-
26
- def state
27
- ""
28
- end
29
-
30
- def sub_state
31
- ""
32
- end
33
-
34
- def state_code
35
- ""
36
- end
37
-
38
- def country
39
- if country = address_components_of_type(:country).first
40
- country['long_name']
41
- end
42
- end
43
-
44
- def country_code
45
- if country = address_components_of_type(:country).first
46
- country['short_name']
47
- end
48
- end
49
-
50
- def postal_code
51
- if postal = address_components_of_type(:postal_code).first
52
- postal['long_name']
53
- end
54
- end
55
-
56
- def route
57
- if route = address_components_of_type(:route).first
58
- route['long_name']
59
- end
60
- end
61
-
62
- def street_number
63
- if street_number = address_components_of_type(:street_number).first
64
- street_number['long_name']
65
- end
66
- end
67
-
68
- def street_address
69
- [route, street_number].compact.join(' ')
70
- end
71
-
72
- def types
73
- @data['types']
74
- end
75
-
76
- def formatted_address
77
- @data['formatted_address']
78
- end
79
-
80
- def address_components
81
- @data['address_components']
82
- end
83
-
84
- ##
85
- # Get address components of a given type. Valid types are defined in
86
- # Google's Geocoding API documentation and include (among others):
87
- #
88
- # :street_number
89
- # :locality
90
- # :neighborhood
91
- # :route
92
- # :postal_code
93
- #
94
- def address_components_of_type(type)
95
- address_components.select{ |c| c['types'].include?(type.to_s) }
96
- end
97
-
98
- def geometry
99
- @data['geometry']
100
- end
101
-
102
- def precision
103
- geometry['location_type'] if geometry
104
- end
105
- end
106
- end
@@ -1,71 +0,0 @@
1
- require 'geocoder/results/base'
2
-
3
- module Geocoder::Result
4
- class Ovi < Base
5
-
6
- ##
7
- # A string in the given format.
8
- #
9
- def address(format = :full)
10
- address_data['Label']
11
- end
12
-
13
- ##
14
- # A two-element array: [lat, lon].
15
- #
16
- def coordinates
17
- fail unless d = @data['Location']['DisplayPosition']
18
- [d['Latitude'].to_f, d['Longitude'].to_f]
19
- end
20
-
21
- def state
22
- address_data['County']
23
- end
24
-
25
- def province
26
- address_data['County']
27
- end
28
-
29
- def postal_code
30
- address_data['PostalCode']
31
- end
32
-
33
- def city
34
- address_data['City']
35
- end
36
-
37
- def state_code
38
- address_data['State']
39
- end
40
-
41
- def province_code
42
- address_data['State']
43
- end
44
-
45
- def country
46
- fail unless d = address_data['AdditionalData']
47
- if v = d.find{|ad| ad['key']=='CountryName'}
48
- return v['value']
49
- end
50
- end
51
-
52
- def country_code
53
- address_data['Country']
54
- end
55
-
56
- def viewport
57
- map_view = data['Location']['MapView'] || fail
58
- south = map_view['BottomRight']['Latitude']
59
- west = map_view['TopLeft']['Longitude']
60
- north = map_view['TopLeft']['Latitude']
61
- east = map_view['BottomRight']['Longitude']
62
- [south, west, north, east]
63
- end
64
-
65
- private # ----------------------------------------------------------------
66
-
67
- def address_data
68
- @data['Location']['Address'] || fail
69
- end
70
- end
71
- end