geocoder 1.7.3 → 1.7.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dab5b671e230411d805a864ef61517f45eb01d4b83091a3eb5b84693dbbc06a
4
- data.tar.gz: 39fcd37053a8c6cdb3270cd6d4daaa8ee025d0ed74c534b3a7c62bf6743013b7
3
+ metadata.gz: e298d39c596857e28539779ed539ad5f9995368f3021f6541deb53d478b80a0a
4
+ data.tar.gz: ed9831a260f47cba9d9bc9a069c6e04362621e3cb72175c56332973196420679
5
5
  SHA512:
6
- metadata.gz: 2b25a577d6d1522b831eb78fb6d6d9af85f1e4d592cd16e2202b8e473376fdf69a87de56c52152a6d7eddf506f6635cf887bb4766680cb8f697ab12c50fab624
7
- data.tar.gz: f8901d2a0187cbb81483a0a94334b32222ae254f08b97c0b1c1f58f39d53148871083b839a2a2e661ba94eb0783a4a399990306e7633a1cc6d3424861cd21408
6
+ metadata.gz: a7801cdd189f6ae89c512b42ce57d4a34a37a0750596f2df4f299693be2318ab2e3d0f55970ec0f9f14435c05d86c56bb3989f28748f972aa8d8fc9409adf927
7
+ data.tar.gz: cc35bb7280bcb43bb9c082dfac6ca5dc395fe3690080d809054761cf147a943868d05ce4f8ce9e4a31b2c67e019e483abcb7c114c7ca711b9c9961e523e57425
data/CHANGELOG.md CHANGED
@@ -3,6 +3,11 @@ Changelog
3
3
 
4
4
  Major changes to Geocoder for each release. Please see the Git log for complete list of changes.
5
5
 
6
+ 1.7.4 (2022 Mar 14)
7
+ -------------------
8
+ * Add ability to use app-defined lookups (thanks github.com/januszm).
9
+ * Updates to LocationIQ and FreeGeoIP lookups.
10
+
6
11
  1.7.3 (2022 Jan 17)
7
12
  -------------------
8
13
  * Get rid of unnecessary cache_prefix deprecation warnings.
data/README.md CHANGED
@@ -20,7 +20,7 @@ Compatibility:
20
20
 
21
21
  * Ruby versions: 2.1+, and JRuby.
22
22
  * Databases: MySQL, PostgreSQL, SQLite, and MongoDB.
23
- * Rails: 5.x and 6.x.
23
+ * Rails: 5.x, 6.x, and 7.x.
24
24
  * Works outside of Rails with the `json` (for MRI) or `json_pure` (for JRuby) gem.
25
25
 
26
26
 
@@ -78,7 +78,7 @@ results.first.address
78
78
  # => "Hôtel de Ville, 75004 Paris, France"
79
79
  ```
80
80
 
81
- You can also look up the location of an IP addresses:
81
+ You can also look up the location of an IP address:
82
82
 
83
83
  ```ruby
84
84
  results = Geocoder.search("172.56.21.89")
@@ -0,0 +1,22 @@
1
+ # To extend the Geocoder with additional lookups that come from the application,
2
+ # not shipped with the gem, define a "child" lookup in your application, based on existing one.
3
+ # This is required because the Geocoder::Configuration is a Singleton and stores one api key per lookup.
4
+
5
+ # in app/libs/geocoder/lookup/my_preciousss.rb
6
+ module Geocoder::Lookup
7
+ class MyPreciousss < Google
8
+ end
9
+ end
10
+
11
+ # Update Geocoder's street_services on initialize:
12
+ # config/initializers/geocoder.rb
13
+ Geocoder::Lookup.street_services << :my_preciousss
14
+
15
+ # Override the configuration when necessary (e.g. provide separate Google API key for the account):
16
+ Geocoder.configure(my_preciousss: { api_key: 'abcdef' })
17
+
18
+ # Lastly, search using your custom lookup service/api keys
19
+ Geocoder.search("Paris", lookup: :my_preciousss)
20
+
21
+ # This is useful when we have groups of users in the application who use Google paid services
22
+ # and we want to properly separate them and allow using individual API KEYS or timeouts.
@@ -117,8 +117,7 @@ module Geocoder
117
117
  def spawn(name)
118
118
  if all_services.include?(name)
119
119
  name = name.to_s
120
- require "geocoder/lookups/#{name}"
121
- Geocoder::Lookup.const_get(classify_name(name)).new
120
+ instantiate_lookup(name)
122
121
  else
123
122
  valids = all_services.map(&:inspect).join(", ")
124
123
  raise ConfigurationError, "Please specify a valid lookup for Geocoder " +
@@ -132,5 +131,18 @@ module Geocoder
132
131
  def classify_name(filename)
133
132
  filename.to_s.split("_").map{ |i| i[0...1].upcase + i[1..-1] }.join
134
133
  end
134
+
135
+ ##
136
+ # Safely instantiate Lookup
137
+ #
138
+ def instantiate_lookup(name)
139
+ class_name = classify_name(name)
140
+ begin
141
+ Geocoder::Lookup.const_get(class_name)
142
+ rescue NameError
143
+ require "geocoder/lookups/#{name}"
144
+ end
145
+ Geocoder::Lookup.const_get(class_name).new
146
+ end
135
147
  end
136
148
  end
@@ -17,14 +17,16 @@ module Geocoder::Lookup
17
17
  end
18
18
  end
19
19
 
20
- def query_url(query)
21
- "#{protocol}://#{host}/json/#{query.sanitized_text}"
22
- end
23
-
24
20
  private # ---------------------------------------------------------------
25
21
 
26
- def cache_key(query)
27
- query_url(query)
22
+ def base_query_url(query)
23
+ "#{protocol}://#{host}/json/#{query.sanitized_text}?"
24
+ end
25
+
26
+ def query_url_params(query)
27
+ {
28
+ :apikey => configuration.api_key
29
+ }.merge(super)
28
30
  end
29
31
 
30
32
  def parse_raw_data(raw_data)
@@ -11,6 +11,10 @@ module Geocoder::Lookup
11
11
  ["api_key"]
12
12
  end
13
13
 
14
+ def supported_protocols
15
+ [:https]
16
+ end
17
+
14
18
  private # ----------------------------------------------------------------
15
19
 
16
20
  def base_query_url(query)
@@ -25,7 +29,7 @@ module Geocoder::Lookup
25
29
  end
26
30
 
27
31
  def configured_host
28
- configuration[:host] || "locationiq.org"
32
+ configuration[:host] || "us1.locationiq.com"
29
33
  end
30
34
 
31
35
  def results(query)
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.7.3"
2
+ VERSION = "1.7.4"
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.7.3
4
+ version: 1.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-03-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Object geocoding (by street or IP address), reverse geocoding (coordinates
14
14
  to street address), distance queries for ActiveRecord and Mongoid, result caching,
@@ -25,6 +25,7 @@ files:
25
25
  - README.md
26
26
  - bin/console
27
27
  - bin/geocode
28
+ - examples/app_defined_lookup_services.rb
28
29
  - examples/cache_bypass.rb
29
30
  - examples/reverse_geocode_job.rb
30
31
  - lib/easting_northing.rb