diff --git a/app/objects/nominatim_client.rb b/app/objects/nominatim_client.rb index 171fd4c..fd7a697 100644 --- a/app/objects/nominatim_client.rb +++ b/app/objects/nominatim_client.rb @@ -19,7 +19,11 @@ def search(query:, limit: 10, language: "en") query_params = params.map { |k, v| "#{k}=#{v}" }.join("&") Sync do response = client.get("/search?#{query_params}", headers: base_headers) - JSON.parse(response.read) + # TODO: (renatolond, 2024-11-05) I'm not too sure of the result format, but it will do for now + JSON.parse(response.read, symbolize_names: true) + .map do |loc| + loc.slice(:lat, :lon, :display_name) + end ensure response&.close end diff --git a/test/app/objects/nominatim_client_test.rb b/test/app/objects/nominatim_client_test.rb index f7af784..4cbb145 100644 --- a/test/app/objects/nominatim_client_test.rb +++ b/test/app/objects/nominatim_client_test.rb @@ -4,7 +4,9 @@ describe NominatimClient do it "calls nominatim and gets a response" do - expected_response = [] + expected_response = [ + { lat: "-22.90173", lon: "-43.2797093", display_name: "Méier, Rio de Janeiro, Região Geográfica Imediata do Rio de Janeiro, Região Metropolitana do Rio de Janeiro, Região Geográfica Intermediária do Rio de Janeiro, Rio de Janeiro, Região Sudeste, Brasil" } + ] stub_request(:get, "https://nominatim.openstreetmap.org/search?featureType=settlement&format=jsonv2&language=en&layer=address&limit=10&q=M%C3%A9ier,%20Rio%20de%20Janeiro") .to_return(webfixture_json_file("nominatim.meier"))