From 39b7a5b94857bea6f5bb7b16913478a2bca55467 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 16 Dec 2019 11:47:57 +0100 Subject: [PATCH] Improve JSON-LD representation for Address and add it to the docs Signed-off-by: Thomas Citharel --- docs/contribute/activity_pub.md | 58 +++++++++++++++++++++++++++++++ lib/service/activity_pub/utils.ex | 20 +++++++++++ 2 files changed, 78 insertions(+) diff --git a/docs/contribute/activity_pub.md b/docs/contribute/activity_pub.md index 27017c1d6..88f383e06 100644 --- a/docs/contribute/activity_pub.md +++ b/docs/contribute/activity_pub.md @@ -111,3 +111,61 @@ Example: "url": "http://mobilizon1.com/events/8cf76e9f-c426-4912-9cd6-c7030b969611" } ``` + +#### location + +We use Schema.org's `location` property on `Event`. +[The ActivityStream vocabulary to represent places](https://www.w3.org/TR/activitystreams-vocabulary/#places) is quite limited so instead of using `Place` from ActivityStreams we use `Place` from Schema.org. + +A [Schema.org `Place` type](https://schema.org/Place) has [an `address` property](https://schema.org/address), which we assume to be [of `PostalAddress` type](https://schema.org/PostalAddress) and [a `geo` property](https://schema.org/geo), which is assumed to be of [`GeoCoordinates` type](https://schema.org/GeoCoordinates). + +```json +{ + "@context": [ + "...", + { + "GeoCoordinates": "sc:GeoCoordinates", + "Place": "sc:Place", + "PostalAddress": "sc:PostalAddress", + "address": { + "@id": "sc:address", + "@type": "sc:PostalAddress" + }, + "addressCountry": "sc:addressCountry", + "addressLocality": "sc:addressLocality", + "addressRegion": "sc:addressRegion", + "geo": { + "@id": "sc:geo", + "@type": "sc:GeoCoordinates" + }, + "location": { + "@id": "sc:location", + "@type": "sc:Place" + }, + "postalCode": "sc:postalCode", + "sc": "http://schema.org#", + "streetAddress": "sc:streetAddress", + } + ], + "id": "http://mobilizon2.com/events/945f350d-a3e6-4bcd-9bf2-0bd2e4d353c5", + "location": { + "address": { + "addressCountry": "France", + "addressLocality": "Lyon", + "addressRegion": "Auvergne-Rhône-Alpes", + "postalCode": "69007", + "streetAddress": "10 Rue Jangot", + "type": "PostalAddress" + }, + "geo": { + "latitude": 4.8425657, + "longitude": 45.7517141, + "type": "GeoCoordinates" + }, + "id": "http://mobilizon2.com/address/bdf7fb53-7177-46f3-8fb3-93c25a802522", + "name": "10 Rue Jangot", + "type": "Place" + }, + "type": "Event" +} +``` \ No newline at end of file diff --git a/lib/service/activity_pub/utils.ex b/lib/service/activity_pub/utils.ex index 3e99e7bd6..dc8e7eb95 100644 --- a/lib/service/activity_pub/utils.ex +++ b/lib/service/activity_pub/utils.ex @@ -37,6 +37,26 @@ defmodule Mobilizon.Service.ActivityPub.Utils do "category" => "sc:category", "uuid" => "sc:identifier", "maximumAttendeeCapacity" => "sc:maximumAttendeeCapacity", + "location" => %{ + "@id" => "sc:location", + "@type" => "sc:Place" + }, + "Place" => "sc:Place", + "PostalAddress" => "sc:PostalAddress", + "GeoCoordinates" => "sc:GeoCoordinates", + "address" => %{ + "@id" => "sc:address", + "@type" => "sc:PostalAddress" + }, + "geo" => %{ + "@id" => "sc:geo", + "@type" => "sc:GeoCoordinates" + }, + "addressCountry" => "sc:addressCountry", + "addressRegion" => "sc:addressRegion", + "postalCode" => "sc:postalCode", + "addressLocality" => "sc:addressLocality", + "streetAddress" => "sc:streetAddress", "mz" => "https://joinmobilizon.org/ns#", "repliesModerationOptionType" => %{ "@id" => "mz:repliesModerationOptionType",