Sha256: d2c979ec584d864c08f6bb0ff924f4af30e9a0f49e65bc34715d30f443de0949

Contents?: true

Size: 1.48 KB

Versions: 20

Compression:

Stored size: 1.48 KB

Contents

require 'geocoder/lookups/base'
require "geocoder/results/geoportail_lu"

module Geocoder
  module Lookup
    class GeoportailLu < Base

      def name
        "Geoportail.lu"
      end

      private # ---------------------------------------------------------------

      def base_query_url(query)
        if query.reverse_geocode?
          reverse_geocode_url_base_path
        else
          search_url_base_path
        end
      end

      def search_url_base_path
        "#{protocol}://api.geoportail.lu/geocoder/search?"
      end

      def reverse_geocode_url_base_path
        "#{protocol}://api.geoportail.lu/geocoder/reverseGeocode?"
      end

      def query_url_geoportail_lu_params(query)
        query.reverse_geocode? ? reverse_geocode_params(query) : search_params(query)
      end

      def search_params(query)
        {
            queryString: query.sanitized_text
        }
      end

      def reverse_geocode_params(query)
        lat_lon = query.coordinates
        {
            lat: lat_lon.first,
            lon: lat_lon.last
        }
      end

      def query_url_params(query)
        query_url_geoportail_lu_params(query).merge(super)
      end

      def results(query)
        return [] unless doc = fetch_data(query)
        if doc['success'] == true
          result = doc['results']
        else
          result = []
          raise_error(Geocoder::Error) ||
              warn("Geportail.lu Geocoding API error")
        end
        result
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
geocoder-1.8.0 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.7.5 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.7.4 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.7.3 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.7.2 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.7.1 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.7.0 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.6.7 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.6.6 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.6.5 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.6.4 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.6.3 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.6.2 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.6.1 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.6.0 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.5.2 lib/geocoder/lookups/geoportail_lu.rb
really-broken-geocoder-2.0.0 lib/geocoder/lookups/geoportail_lu.rb
really-broken-geocoder-1.5.1 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.5.1 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.5.0 lib/geocoder/lookups/geoportail_lu.rb