Reuse existing addresses when creating an event

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-08-22 15:57:44 +02:00
parent ebf5534003
commit 0e0b68445b
22 changed files with 410 additions and 121 deletions

File diff suppressed because one or more lines are too long

View File

@@ -6,23 +6,22 @@
"method": "get",
"options": [],
"request_body": "",
"url": "https://maps.googleapis.com/maps/api/geocode/json?address=10%20rue%20Jangot&limit=10&key=toto&language=en"
"url": "https://maps.googleapis.com/maps/api/geocode/json?limit=10&key=toto&language=en&address=10%20rue%20Jangot"
},
"response": {
"binary": false,
"body": "{\n \"results\" : [\n {\n \"address_components\" : [\n {\n \"long_name\" : \"10\",\n \"short_name\" : \"10\",\n \"types\" : [ \"street_number\" ]\n },\n {\n \"long_name\" : \"Rue Jangot\",\n \"short_name\" : \"Rue Jangot\",\n \"types\" : [ \"route\" ]\n },\n {\n \"long_name\" : \"Lyon\",\n \"short_name\" : \"Lyon\",\n \"types\" : [ \"locality\", \"political\" ]\n },\n {\n \"long_name\" : \"Rhône\",\n \"short_name\" : \"Rhône\",\n \"types\" : [ \"administrative_area_level_2\", \"political\" ]\n },\n {\n \"long_name\" : \"Auvergne-Rhône-Alpes\",\n \"short_name\" : \"Auvergne-Rhône-Alpes\",\n \"types\" : [ \"administrative_area_level_1\", \"political\" ]\n },\n {\n \"long_name\" : \"France\",\n \"short_name\" : \"FR\",\n \"types\" : [ \"country\", \"political\" ]\n },\n {\n \"long_name\" : \"69007\",\n \"short_name\" : \"69007\",\n \"types\" : [ \"postal_code\" ]\n }\n ],\n \"formatted_address\" : \"10 Rue Jangot, 69007 Lyon, France\",\n \"geometry\" : {\n \"location\" : {\n \"lat\" : 45.75164940000001,\n \"lng\" : 4.8424032\n },\n \"location_type\" : \"ROOFTOP\",\n \"viewport\" : {\n \"northeast\" : {\n \"lat\" : 45.75299838029151,\n \"lng\" : 4.843752180291502\n },\n \"southwest\" : {\n \"lat\" : 45.75030041970851,\n \"lng\" : 4.841054219708497\n }\n }\n },\n \"place_id\" : \"ChIJtW0QikTq9EcRLI4Vy6bRx0U\",\n \"plus_code\" : {\n \"compound_code\" : \"QR2R+MX Lyon, France\",\n \"global_code\" : \"8FQ6QR2R+MX\"\n },\n \"types\" : [ \"street_address\" ]\n }\n ],\n \"status\" : \"OK\"\n}\n",
"headers": {
"Content-Type": "application/json; charset=UTF-8",
"Date": "Wed, 13 Mar 2019 17:50:19 GMT",
"Expires": "Thu, 14 Mar 2019 17:50:19 GMT",
"Date": "Thu, 22 Aug 2019 13:05:39 GMT",
"Expires": "Thu, 22 Aug 2019 13:06:09 GMT",
"Cache-Control": "public, max-age=30",
"Access-Control-Allow-Origin": "*",
"Server": "mafe",
"X-XSS-Protection": "1; mode=block",
"X-XSS-Protection": "0",
"X-Frame-Options": "SAMEORIGIN",
"Server-Timing": "gfet4t7; dur=52",
"Cache-Control": "public, max-age=86400",
"Age": "17",
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"46,44,43,39\"",
"Server-Timing": "gfet4t7; dur=44",
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"46,43,39\"",
"Accept-Ranges": "none",
"Vary": "Accept-Encoding",
"Transfer-Encoding": "chunked"
@@ -30,5 +29,35 @@
"status_code": 200,
"type": "ok"
}
},
{
"request": {
"body": "",
"headers": [],
"method": "get",
"options": [],
"request_body": "",
"url": "https://maps.googleapis.com/maps/api/place/details/json?key=toto&placeid=ChIJtW0QikTq9EcRLI4Vy6bRx0U"
},
"response": {
"binary": false,
"body": "{\n \"html_attributions\" : [],\n \"result\" : {\n \"address_components\" : [\n {\n \"long_name\" : \"10\",\n \"short_name\" : \"10\",\n \"types\" : [ \"street_number\" ]\n },\n {\n \"long_name\" : \"Rue Jangot\",\n \"short_name\" : \"Rue Jangot\",\n \"types\" : [ \"route\" ]\n },\n {\n \"long_name\" : \"Lyon\",\n \"short_name\" : \"Lyon\",\n \"types\" : [ \"locality\", \"political\" ]\n },\n {\n \"long_name\" : \"Rhône\",\n \"short_name\" : \"Rhône\",\n \"types\" : [ \"administrative_area_level_2\", \"political\" ]\n },\n {\n \"long_name\" : \"Auvergne-Rhône-Alpes\",\n \"short_name\" : \"Auvergne-Rhône-Alpes\",\n \"types\" : [ \"administrative_area_level_1\", \"political\" ]\n },\n {\n \"long_name\" : \"France\",\n \"short_name\" : \"FR\",\n \"types\" : [ \"country\", \"political\" ]\n },\n {\n \"long_name\" : \"69007\",\n \"short_name\" : \"69007\",\n \"types\" : [ \"postal_code\" ]\n }\n ],\n \"adr_address\" : \"\\u003cspan class=\\\"street-address\\\"\\u003e10 Rue Jangot\\u003c/span\\u003e, \\u003cspan class=\\\"postal-code\\\"\\u003e69007\\u003c/span\\u003e \\u003cspan class=\\\"locality\\\"\\u003eLyon\\u003c/span\\u003e, \\u003cspan class=\\\"country-name\\\"\\u003eFrance\\u003c/span\\u003e\",\n \"formatted_address\" : \"10 Rue Jangot, 69007 Lyon, France\",\n \"geometry\" : {\n \"location\" : {\n \"lat\" : 45.75164940000001,\n \"lng\" : 4.842403200000001\n },\n \"viewport\" : {\n \"northeast\" : {\n \"lat\" : 45.7530412802915,\n \"lng\" : 4.843668630291503\n },\n \"southwest\" : {\n \"lat\" : 45.75034331970851,\n \"lng\" : 4.840970669708498\n }\n }\n },\n \"icon\" : \"https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png\",\n \"id\" : \"61b9418d092d2ed05ddd65a55dddefda5b9628cc\",\n \"name\" : \"10 Rue Jangot\",\n \"place_id\" : \"ChIJtW0QikTq9EcRLI4Vy6bRx0U\",\n \"plus_code\" : {\n \"compound_code\" : \"QR2R+MX Lyon, France\",\n \"global_code\" : \"8FQ6QR2R+MX\"\n },\n \"reference\" : \"ChIJtW0QikTq9EcRLI4Vy6bRx0U\",\n \"scope\" : \"GOOGLE\",\n \"types\" : [ \"street_address\" ],\n \"url\" : \"https://maps.google.com/?q=10+Rue+Jangot,+69007+Lyon,+France&ftid=0x47f4ea448a106db5:0x45c7d1a6cb158e2c\",\n \"utc_offset\" : 120,\n \"vicinity\" : \"Lyon\"\n },\n \"status\" : \"OK\"\n}\n",
"headers": {
"Content-Type": "application/json; charset=UTF-8",
"Date": "Thu, 22 Aug 2019 13:05:39 GMT",
"Expires": "Thu, 22 Aug 2019 13:10:39 GMT",
"Cache-Control": "public, max-age=300",
"Server": "scaffolding on HTTPServer2",
"X-XSS-Protection": "0",
"X-Frame-Options": "SAMEORIGIN",
"Server-Timing": "gfet4t7; dur=86",
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"46,43,39\"",
"Accept-Ranges": "none",
"Vary": "Accept-Language,Accept-Encoding",
"Transfer-Encoding": "chunked"
},
"status_code": 200,
"type": "ok"
}
}
]
]

View File

@@ -43,7 +43,7 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
use_cassette "geospatial/google_maps/search" do
assert %Address{
locality: "Lyon",
description: "10 Rue Jangot, 69007 Lyon, France",
description: "10 Rue Jangot",
region: "Auvergne-Rhône-Alpes",
country: "France",
postal_code: "69007",
@@ -52,8 +52,13 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
coordinates: {4.8424032, 45.75164940000001},
properties: %{},
srid: 4326
}
} == GoogleMaps.search("10 rue Jangot", api_key: "toto") |> hd
},
origin_id: "gm:ChIJtW0QikTq9EcRLI4Vy6bRx0U"
} ==
GoogleMaps.search("10 rue Jangot",
api_key: "toto"
)
|> hd
end
end
@@ -61,16 +66,17 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
use_cassette "geospatial/google_maps/geocode" do
assert %Address{
locality: "Lyon",
description: "10 Rue Jangot, 69007 Lyon, France",
description: "10bis Rue Jangot",
region: "Auvergne-Rhône-Alpes",
country: "France",
postal_code: "69007",
street: "10 Rue Jangot",
street: "10bis Rue Jangot",
geom: %Geo.Point{
coordinates: {4.8424967, 45.751725},
coordinates: {4.8424966, 45.751725},
properties: %{},
srid: 4326
}
},
origin_id: "gm:ChIJrW0QikTq9EcR96jk2OnO75w"
} ==
GoogleMaps.geocode(4.842569, 45.751718, api_key: "toto")
|> hd

View File

@@ -39,7 +39,8 @@ defmodule Mobilizon.Service.Geospatial.NominatimTest do
coordinates: {4.8425657, 45.7517141},
properties: %{},
srid: 4326
}
},
origin_id: "osm:3078260611"
} == Nominatim.search("10 rue Jangot") |> hd
end
end
@@ -58,7 +59,8 @@ defmodule Mobilizon.Service.Geospatial.NominatimTest do
coordinates: {4.8425657, 45.7517141},
properties: %{},
srid: 4326
}
},
origin_id: "osm:3078260611"
} ==
Nominatim.geocode(4.842569, 45.751718)
|> hd