9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/crawler/address/providers/gouv_fr.rb', line 9
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
|