Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Managing notifications
In this exemple, you can get invited to Julius Caesar book release party. You may be 2000 years late, but cool people never show up on time anyway.
Discovering a resource's inbox
To find out where to reach any resource, all you have to do is ask! Inboxes are announced using the LDP term ldp:inbox
in resources' RDF representation.
What is Cleopatra's inbox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const axios = require("axios")
const {fetch_inbox} = require("./discover-inbox")
// You can change that to your own webid
const resource_iri = "https://cleopatra.solid.community/profile/card#me"
// First, let's see the plain RDF representation of the resource
axios.get(resource_iri)
.then(response => {
// Let us just display the content of the resource
console.log(response.data);
console.log("\n --- \n");
// And now, let's just filter for its inbox
fetch_inbox(resource_iri)
.then(inbox => {
console.log("The inbox of "+resource_iri+" is "+inbox)
})
.catch(error => {
console.log(error);
})})
.catch(error => {
console.log(error);
})
Enter to Rename, Shift+Enter to Preview
1
const axios = require("axios")
Enter to Rename, Shift+Enter to Preview
Sending a notification
In the following snippet, after discovering the target's inbox, an invite is sent. Want to weasle your way in the coolest party of the Roman empire ? Just change the calendar_iri
to your own!
Let's get crazy sending out invites
1
2
3
4
5
6
7
8
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
34
35
36
37
38
39
40
41
const axios = require("axios")
const $rdf = require("rdflib")
const {invite} = require("./invite")
const {fetch_inbox} = require("./discover-inbox")
const timeout = 3000
const LDP = $rdf.Namespace("http://www.w3.org/ns/ldp#")
// Let's assume that we know the IRI of the invitee's calendar
const calendar_iri = "https://cleopatra.solid.community/public/calendar/"
const store = $rdf.graph();
const fetcher = new $rdf.Fetcher(store, timeout)
// First, fetch the inbox...
fetch_inbox(calendar_iri)
.then(inbox => {
// ...and thenr perform a POST to the target inbox to send
// the invite defined in invite.js
axios({
method: 'post',
url: inbox,
data: invite,
headers: {
"Content-type": "text/turtle",
"Slug": "We gonna parteyy"
}
}).then (response => {
console.log(response.status)
}).catch(error => {
console.log(error)
});
}).catch(error => {
console.log(error)
})
Enter to Rename, Shift+Enter to Preview
1
Enter to Rename, Shift+Enter to Preview
1
const axios = require("axios")
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content