Sha256: 06084214637d1da137f002f23cf4e38333b0c7dd96d789e4c3655d1781b8e454

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require 'faraday'
require 'json'
require 'crawler/address'

module Crawler
  module Address
    module Providers
      module GouvFr
        def self.resolve(street, zipcode, _city, _country)
          response = Faraday.get('https://api-adresse.data.gouv.fr/search',
            q: street,
            postcode: zipcode
          )

          return [] if !response.success? || !response.body

          json = JSON.parse(response.body)
          json['features'].map do |feature|
            geometry = feature['geometry']
            properties = feature['properties']

            {
              street: properties['name'],
              zipcode: properties['postcode'],
              city: properties['city'],
              country: 'fr',
              coordinates: {
                latitude: geometry['coordinates'].last,
                longitude: geometry['coordinates'].first
              }
            }
          end
        end
      end
    end
  end
end

Crawler::Address.add_provider :gouv_fr, score: 0.95, country: :fr

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
crawler-address-gouv-fr-1.0.0 lib/crawler/address/providers/gouv_fr.rb
crawler-address-gouv-fr-0.1.0 lib/crawler/address/providers/gouv_fr.rb