geocoder 1.6.3 → 1.7.3
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 +4 -4
- data/CHANGELOG.md +39 -0
- data/LICENSE +1 -1
- data/README.md +328 -231
- data/lib/generators/geocoder/config/templates/initializer.rb +7 -1
- data/lib/geocoder/cache.rb +16 -33
- data/lib/geocoder/cache_stores/base.rb +40 -0
- data/lib/geocoder/cache_stores/generic.rb +35 -0
- data/lib/geocoder/cache_stores/redis.rb +34 -0
- data/lib/geocoder/configuration.rb +11 -4
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/ip_address.rb +6 -0
- data/lib/geocoder/lookup.rb +16 -2
- data/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/lib/geocoder/lookups/amazon_location_service.rb +54 -0
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +1 -1
- data/lib/geocoder/lookups/base.rb +8 -2
- data/lib/geocoder/lookups/bing.rb +1 -1
- data/lib/geocoder/lookups/esri.rb +4 -0
- data/lib/geocoder/lookups/geoapify.rb +72 -0
- data/lib/geocoder/lookups/geocodio.rb +1 -1
- data/lib/geocoder/lookups/geoip2.rb +4 -0
- data/lib/geocoder/lookups/google.rb +7 -2
- data/lib/geocoder/lookups/google_places_details.rb +8 -14
- data/lib/geocoder/lookups/google_places_search.rb +28 -2
- data/lib/geocoder/lookups/google_premier.rb +4 -0
- data/lib/geocoder/lookups/ip2location.rb +10 -6
- data/lib/geocoder/lookups/ipdata_co.rb +1 -1
- data/lib/geocoder/lookups/ipqualityscore.rb +50 -0
- data/lib/geocoder/lookups/maxmind_local.rb +7 -1
- data/lib/geocoder/lookups/melissa_street.rb +41 -0
- data/lib/geocoder/lookups/photon.rb +89 -0
- data/lib/geocoder/lookups/test.rb +4 -0
- data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +1 -1
- data/lib/geocoder/results/abstract_api.rb +146 -0
- data/lib/geocoder/results/amazon_location_service.rb +57 -0
- data/lib/geocoder/results/ban_data_gouv_fr.rb +26 -1
- data/lib/geocoder/results/db_ip_com.rb +1 -1
- data/lib/geocoder/results/esri.rb +5 -2
- data/lib/geocoder/results/geoapify.rb +179 -0
- data/lib/geocoder/results/ipqualityscore.rb +54 -0
- data/lib/geocoder/results/ipregistry.rb +4 -8
- data/lib/geocoder/results/mapbox.rb +10 -4
- data/lib/geocoder/results/melissa_street.rb +46 -0
- data/lib/geocoder/results/nationaal_georegister_nl.rb +1 -1
- data/lib/geocoder/results/nominatim.rb +27 -15
- data/lib/geocoder/results/photon.rb +119 -0
- data/lib/geocoder/util.rb +29 -0
- data/lib/geocoder/version.rb +1 -1
- metadata +18 -5
- data/examples/autoexpire_cache_dalli.rb +0 -62
- data/examples/autoexpire_cache_redis.rb +0 -30
- data/lib/hash_recursive_merge.rb +0 -73
    
        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 | 
            +
              version: 1.7.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Alex Reisner
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2022-01-17 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,8 +25,6 @@ files: | |
| 25 25 | 
             
            - README.md
         | 
| 26 26 | 
             
            - bin/console
         | 
| 27 27 | 
             
            - bin/geocode
         | 
| 28 | 
            -
            - examples/autoexpire_cache_dalli.rb
         | 
| 29 | 
            -
            - examples/autoexpire_cache_redis.rb
         | 
| 30 28 | 
             
            - examples/cache_bypass.rb
         | 
| 31 29 | 
             
            - examples/reverse_geocode_job.rb
         | 
| 32 30 | 
             
            - lib/easting_northing.rb
         | 
| @@ -39,6 +37,9 @@ files: | |
| 39 37 | 
             
            - lib/generators/geocoder/migration_version.rb
         | 
| 40 38 | 
             
            - lib/geocoder.rb
         | 
| 41 39 | 
             
            - lib/geocoder/cache.rb
         | 
| 40 | 
            +
            - lib/geocoder/cache_stores/base.rb
         | 
| 41 | 
            +
            - lib/geocoder/cache_stores/generic.rb
         | 
| 42 | 
            +
            - lib/geocoder/cache_stores/redis.rb
         | 
| 42 43 | 
             
            - lib/geocoder/calculations.rb
         | 
| 43 44 | 
             
            - lib/geocoder/cli.rb
         | 
| 44 45 | 
             
            - lib/geocoder/configuration.rb
         | 
| @@ -49,7 +50,9 @@ files: | |
| 49 50 | 
             
            - lib/geocoder/kernel_logger.rb
         | 
| 50 51 | 
             
            - lib/geocoder/logger.rb
         | 
| 51 52 | 
             
            - lib/geocoder/lookup.rb
         | 
| 53 | 
            +
            - lib/geocoder/lookups/abstract_api.rb
         | 
| 52 54 | 
             
            - lib/geocoder/lookups/amap.rb
         | 
| 55 | 
            +
            - lib/geocoder/lookups/amazon_location_service.rb
         | 
| 53 56 | 
             
            - lib/geocoder/lookups/baidu.rb
         | 
| 54 57 | 
             
            - lib/geocoder/lookups/baidu_ip.rb
         | 
| 55 58 | 
             
            - lib/geocoder/lookups/ban_data_gouv_fr.rb
         | 
| @@ -59,6 +62,7 @@ files: | |
| 59 62 | 
             
            - lib/geocoder/lookups/dstk.rb
         | 
| 60 63 | 
             
            - lib/geocoder/lookups/esri.rb
         | 
| 61 64 | 
             
            - lib/geocoder/lookups/freegeoip.rb
         | 
| 65 | 
            +
            - lib/geocoder/lookups/geoapify.rb
         | 
| 62 66 | 
             
            - lib/geocoder/lookups/geocoder_ca.rb
         | 
| 63 67 | 
             
            - lib/geocoder/lookups/geocodio.rb
         | 
| 64 68 | 
             
            - lib/geocoder/lookups/geoip2.rb
         | 
| @@ -73,6 +77,7 @@ files: | |
| 73 77 | 
             
            - lib/geocoder/lookups/ipdata_co.rb
         | 
| 74 78 | 
             
            - lib/geocoder/lookups/ipgeolocation.rb
         | 
| 75 79 | 
             
            - lib/geocoder/lookups/ipinfo_io.rb
         | 
| 80 | 
            +
            - lib/geocoder/lookups/ipqualityscore.rb
         | 
| 76 81 | 
             
            - lib/geocoder/lookups/ipregistry.rb
         | 
| 77 82 | 
             
            - lib/geocoder/lookups/ipstack.rb
         | 
| 78 83 | 
             
            - lib/geocoder/lookups/latlon.rb
         | 
| @@ -82,11 +87,13 @@ files: | |
| 82 87 | 
             
            - lib/geocoder/lookups/maxmind.rb
         | 
| 83 88 | 
             
            - lib/geocoder/lookups/maxmind_geoip2.rb
         | 
| 84 89 | 
             
            - lib/geocoder/lookups/maxmind_local.rb
         | 
| 90 | 
            +
            - lib/geocoder/lookups/melissa_street.rb
         | 
| 85 91 | 
             
            - lib/geocoder/lookups/nationaal_georegister_nl.rb
         | 
| 86 92 | 
             
            - lib/geocoder/lookups/nominatim.rb
         | 
| 87 93 | 
             
            - lib/geocoder/lookups/opencagedata.rb
         | 
| 88 94 | 
             
            - lib/geocoder/lookups/osmnames.rb
         | 
| 89 95 | 
             
            - lib/geocoder/lookups/pelias.rb
         | 
| 96 | 
            +
            - lib/geocoder/lookups/photon.rb
         | 
| 90 97 | 
             
            - lib/geocoder/lookups/pickpoint.rb
         | 
| 91 98 | 
             
            - lib/geocoder/lookups/pointpin.rb
         | 
| 92 99 | 
             
            - lib/geocoder/lookups/postcode_anywhere_uk.rb
         | 
| @@ -105,7 +112,9 @@ files: | |
| 105 112 | 
             
            - lib/geocoder/query.rb
         | 
| 106 113 | 
             
            - lib/geocoder/railtie.rb
         | 
| 107 114 | 
             
            - lib/geocoder/request.rb
         | 
| 115 | 
            +
            - lib/geocoder/results/abstract_api.rb
         | 
| 108 116 | 
             
            - lib/geocoder/results/amap.rb
         | 
| 117 | 
            +
            - lib/geocoder/results/amazon_location_service.rb
         | 
| 109 118 | 
             
            - lib/geocoder/results/baidu.rb
         | 
| 110 119 | 
             
            - lib/geocoder/results/baidu_ip.rb
         | 
| 111 120 | 
             
            - lib/geocoder/results/ban_data_gouv_fr.rb
         | 
| @@ -115,6 +124,7 @@ files: | |
| 115 124 | 
             
            - lib/geocoder/results/dstk.rb
         | 
| 116 125 | 
             
            - lib/geocoder/results/esri.rb
         | 
| 117 126 | 
             
            - lib/geocoder/results/freegeoip.rb
         | 
| 127 | 
            +
            - lib/geocoder/results/geoapify.rb
         | 
| 118 128 | 
             
            - lib/geocoder/results/geocoder_ca.rb
         | 
| 119 129 | 
             
            - lib/geocoder/results/geocodio.rb
         | 
| 120 130 | 
             
            - lib/geocoder/results/geoip2.rb
         | 
| @@ -129,6 +139,7 @@ files: | |
| 129 139 | 
             
            - lib/geocoder/results/ipdata_co.rb
         | 
| 130 140 | 
             
            - lib/geocoder/results/ipgeolocation.rb
         | 
| 131 141 | 
             
            - lib/geocoder/results/ipinfo_io.rb
         | 
| 142 | 
            +
            - lib/geocoder/results/ipqualityscore.rb
         | 
| 132 143 | 
             
            - lib/geocoder/results/ipregistry.rb
         | 
| 133 144 | 
             
            - lib/geocoder/results/ipstack.rb
         | 
| 134 145 | 
             
            - lib/geocoder/results/latlon.rb
         | 
| @@ -138,11 +149,13 @@ files: | |
| 138 149 | 
             
            - lib/geocoder/results/maxmind.rb
         | 
| 139 150 | 
             
            - lib/geocoder/results/maxmind_geoip2.rb
         | 
| 140 151 | 
             
            - lib/geocoder/results/maxmind_local.rb
         | 
| 152 | 
            +
            - lib/geocoder/results/melissa_street.rb
         | 
| 141 153 | 
             
            - lib/geocoder/results/nationaal_georegister_nl.rb
         | 
| 142 154 | 
             
            - lib/geocoder/results/nominatim.rb
         | 
| 143 155 | 
             
            - lib/geocoder/results/opencagedata.rb
         | 
| 144 156 | 
             
            - lib/geocoder/results/osmnames.rb
         | 
| 145 157 | 
             
            - lib/geocoder/results/pelias.rb
         | 
| 158 | 
            +
            - lib/geocoder/results/photon.rb
         | 
| 146 159 | 
             
            - lib/geocoder/results/pickpoint.rb
         | 
| 147 160 | 
             
            - lib/geocoder/results/pointpin.rb
         | 
| 148 161 | 
             
            - lib/geocoder/results/postcode_anywhere_uk.rb
         | 
| @@ -159,8 +172,8 @@ files: | |
| 159 172 | 
             
            - lib/geocoder/stores/mongo_base.rb
         | 
| 160 173 | 
             
            - lib/geocoder/stores/mongo_mapper.rb
         | 
| 161 174 | 
             
            - lib/geocoder/stores/mongoid.rb
         | 
| 175 | 
            +
            - lib/geocoder/util.rb
         | 
| 162 176 | 
             
            - lib/geocoder/version.rb
         | 
| 163 | 
            -
            - lib/hash_recursive_merge.rb
         | 
| 164 177 | 
             
            - lib/maxmind_database.rb
         | 
| 165 178 | 
             
            - lib/tasks/geocoder.rake
         | 
| 166 179 | 
             
            - lib/tasks/maxmind.rake
         | 
| @@ -1,62 +0,0 @@ | |
| 1 | 
            -
            # This class implements a cache with simple delegation to the the Dalli Memcached client
         | 
| 2 | 
            -
            # https://github.com/mperham/dalli
         | 
| 3 | 
            -
            #
         | 
| 4 | 
            -
            # A TTL is set on initialization
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            class AutoexpireCacheDalli
         | 
| 7 | 
            -
              def initialize(store, ttl = 86400)
         | 
| 8 | 
            -
                @store = store
         | 
| 9 | 
            -
                @keys = 'GeocoderDalliClientKeys'
         | 
| 10 | 
            -
                @ttl = ttl
         | 
| 11 | 
            -
              end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              def [](url)
         | 
| 14 | 
            -
                res = @store.get(url)
         | 
| 15 | 
            -
                res = YAML::load(res) if res.present?
         | 
| 16 | 
            -
                res
         | 
| 17 | 
            -
              end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              def []=(url, value)
         | 
| 20 | 
            -
                if value.nil?
         | 
| 21 | 
            -
                  del(url)
         | 
| 22 | 
            -
                else
         | 
| 23 | 
            -
                  key_cache_add(url) if @store.add(url, YAML::dump(value), @ttl)
         | 
| 24 | 
            -
                end
         | 
| 25 | 
            -
                value
         | 
| 26 | 
            -
              end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
              def keys
         | 
| 29 | 
            -
                key_cache
         | 
| 30 | 
            -
              end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
              def del(url)
         | 
| 33 | 
            -
                key_cache_delete(url) if @store.delete(url)
         | 
| 34 | 
            -
              end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
              private
         | 
| 37 | 
            -
             | 
| 38 | 
            -
              def key_cache
         | 
| 39 | 
            -
                the_keys = @store.get(@keys)
         | 
| 40 | 
            -
                if the_keys.nil?
         | 
| 41 | 
            -
                  @store.add(@keys, YAML::dump([]))
         | 
| 42 | 
            -
                  []
         | 
| 43 | 
            -
                else
         | 
| 44 | 
            -
                  YAML::load(the_keys)
         | 
| 45 | 
            -
                end
         | 
| 46 | 
            -
              end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
              def key_cache_add(key)
         | 
| 49 | 
            -
                @store.replace(@keys, YAML::dump(key_cache << key))
         | 
| 50 | 
            -
              end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
              def key_cache_delete(key)
         | 
| 53 | 
            -
                tmp = key_cache
         | 
| 54 | 
            -
                tmp.delete(key)
         | 
| 55 | 
            -
                @store.replace(@keys, YAML::dump(tmp))
         | 
| 56 | 
            -
              end
         | 
| 57 | 
            -
            end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
            # Here Dalli is set up as on Heroku using the Memcachier gem.
         | 
| 60 | 
            -
            # https://devcenter.heroku.com/articles/memcachier#ruby
         | 
| 61 | 
            -
            # On other setups you might have to specify your Memcached server in Dalli::Client.new
         | 
| 62 | 
            -
            Geocoder.configure(:cache => AutoexpireCacheDalli.new(Dalli::Client.new))
         | 
| @@ -1,30 +0,0 @@ | |
| 1 | 
            -
            # This class implements a cache with simple delegation to the Redis store, but
         | 
| 2 | 
            -
            # when it creates a key/value pair, it also sends an EXPIRE command with a TTL.
         | 
| 3 | 
            -
            # It should be fairly simple to do the same thing with Memcached.
         | 
| 4 | 
            -
            # Alternatively, this class could inherit from Redis, which would make most
         | 
| 5 | 
            -
            # of the below methods unnecessary.
         | 
| 6 | 
            -
            class AutoexpireCacheRedis
         | 
| 7 | 
            -
              def initialize(store, ttl = 86400)
         | 
| 8 | 
            -
                @store = store
         | 
| 9 | 
            -
                @ttl = ttl
         | 
| 10 | 
            -
              end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              def [](url)
         | 
| 13 | 
            -
                @store.get(url)
         | 
| 14 | 
            -
              end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
              def []=(url, value)
         | 
| 17 | 
            -
                @store.set(url, value)
         | 
| 18 | 
            -
                @store.expire(url, @ttl)
         | 
| 19 | 
            -
              end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
              def keys
         | 
| 22 | 
            -
                @store.keys
         | 
| 23 | 
            -
              end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
              def del(url)
         | 
| 26 | 
            -
                @store.del(url)
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
            end
         | 
| 29 | 
            -
             | 
| 30 | 
            -
            Geocoder.configure(:cache => AutoexpireCacheRedis.new(Redis.new))
         | 
    
        data/lib/hash_recursive_merge.rb
    DELETED
    
    | @@ -1,73 +0,0 @@ | |
| 1 | 
            -
            # 
         | 
| 2 | 
            -
            # = Hash Recursive Merge
         | 
| 3 | 
            -
            # 
         | 
| 4 | 
            -
            # Merges a Ruby Hash recursively, Also known as deep merge.
         | 
| 5 | 
            -
            # Recursive version of Hash#merge and Hash#merge!.
         | 
| 6 | 
            -
            # 
         | 
| 7 | 
            -
            # Category::    Ruby
         | 
| 8 | 
            -
            # Package::     Hash
         | 
| 9 | 
            -
            # Author::      Simone Carletti <weppos@weppos.net>
         | 
| 10 | 
            -
            # Copyright::   2007-2008 The Authors
         | 
| 11 | 
            -
            # License::     MIT License
         | 
| 12 | 
            -
            # Link::        http://www.simonecarletti.com/
         | 
| 13 | 
            -
            # Source::      http://gist.github.com/gists/6391/
         | 
| 14 | 
            -
            #
         | 
| 15 | 
            -
            module HashRecursiveMerge
         | 
| 16 | 
            -
             | 
| 17 | 
            -
              #
         | 
| 18 | 
            -
              # Recursive version of Hash#merge!
         | 
| 19 | 
            -
              # 
         | 
| 20 | 
            -
              # Adds the contents of +other_hash+ to +hsh+, 
         | 
| 21 | 
            -
              # merging entries in +hsh+ with duplicate keys with those from +other_hash+.
         | 
| 22 | 
            -
              # 
         | 
| 23 | 
            -
              # Compared with Hash#merge!, this method supports nested hashes.
         | 
| 24 | 
            -
              # When both +hsh+ and +other_hash+ contains an entry with the same key,
         | 
| 25 | 
            -
              # it merges and returns the values from both arrays.
         | 
| 26 | 
            -
              # 
         | 
| 27 | 
            -
              #    h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
         | 
| 28 | 
            -
              #    h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
         | 
| 29 | 
            -
              #    h1.rmerge!(h2)   #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
         | 
| 30 | 
            -
              #    
         | 
| 31 | 
            -
              # Simply using Hash#merge! would return
         | 
| 32 | 
            -
              # 
         | 
| 33 | 
            -
              #    h1.merge!(h2)    #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
         | 
| 34 | 
            -
              # 
         | 
| 35 | 
            -
              def rmerge!(other_hash)
         | 
| 36 | 
            -
                merge!(other_hash) do |key, oldval, newval|
         | 
| 37 | 
            -
                  oldval.class == self.class ? oldval.rmerge!(newval) : newval
         | 
| 38 | 
            -
                end
         | 
| 39 | 
            -
              end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
              #
         | 
| 42 | 
            -
              # Recursive version of Hash#merge
         | 
| 43 | 
            -
              # 
         | 
| 44 | 
            -
              # Compared with Hash#merge!, this method supports nested hashes.
         | 
| 45 | 
            -
              # When both +hsh+ and +other_hash+ contains an entry with the same key,
         | 
| 46 | 
            -
              # it merges and returns the values from both arrays.
         | 
| 47 | 
            -
              # 
         | 
| 48 | 
            -
              # Compared with Hash#merge, this method provides a different approch
         | 
| 49 | 
            -
              # for merging nasted hashes.
         | 
| 50 | 
            -
              # If the value of a given key is an Hash and both +other_hash+ abd +hsh
         | 
| 51 | 
            -
              # includes the same key, the value is merged instead replaced with
         | 
| 52 | 
            -
              # +other_hash+ value.
         | 
| 53 | 
            -
              # 
         | 
| 54 | 
            -
              #    h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
         | 
| 55 | 
            -
              #    h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
         | 
| 56 | 
            -
              #    h1.rmerge(h2)    #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
         | 
| 57 | 
            -
              #    
         | 
| 58 | 
            -
              # Simply using Hash#merge would return
         | 
| 59 | 
            -
              # 
         | 
| 60 | 
            -
              #    h1.merge(h2)     #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
         | 
| 61 | 
            -
              # 
         | 
| 62 | 
            -
              def rmerge(other_hash)
         | 
| 63 | 
            -
                merge(other_hash) do |key, oldval, newval|
         | 
| 64 | 
            -
                  oldval.class == self.class ? oldval.rmerge(newval) : newval
         | 
| 65 | 
            -
                end
         | 
| 66 | 
            -
              end
         | 
| 67 | 
            -
             | 
| 68 | 
            -
            end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
            class Hash
         | 
| 72 | 
            -
              include HashRecursiveMerge
         | 
| 73 | 
            -
            end
         |