Sha256: 37b92f90e9f268d059b2d42e629cb9782a4bfa12813dde9dbd0e033b22fd13e7

Contents?: true

Size: 1.46 KB

Versions: 22

Compression:

Stored size: 1.46 KB

Contents

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

module Geocoder
  module Lookup
    class GeoportailLu < Base

      def name
        "Geoportail.lu"
      end

      def query_url(query)
        url_base_path(query) + url_query_string(query)
      end

      private

      def url_base_path(query)
        query.reverse_geocode? ? reverse_geocode_url_base_path : search_url_base_path
      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

22 entries across 22 versions & 3 rubygems

Version Path
geocoder-1.4.9 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.4.8 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.4.7 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.4.6 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.4.5 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.4.4 lib/geocoder/lookups/geoportail_lu.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/geocoder-1.4.3/lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.4.3 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.4.2 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.4.1 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.4.0 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.3.7 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.3.6 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.3.5 lib/geocoder/lookups/geoportail_lu.rb
broken-geocoder-1.3.6 lib/geocoder/lookups/geoportail_lu.rb
broken-geocoder-1.3.5 lib/geocoder/lookups/geoportail_lu.rb
broken-geocoder-1.3.4 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.3.4 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.3.3 lib/geocoder/lookups/geoportail_lu.rb
geocoder-1.3.2 lib/geocoder/lookups/geoportail_lu.rb