Initial AP objects implementation
This commit is contained in:
77
source/ap/actor.d
Normal file
77
source/ap/actor.d
Normal file
@@ -0,0 +1,77 @@
|
||||
module ap.actor;
|
||||
|
||||
import std.json;
|
||||
|
||||
import ap.activity_stream;
|
||||
import util;
|
||||
|
||||
/++
|
||||
* Represents an ActivityPub Actor
|
||||
* https://www.w3.org/TR/activitypub/#actors
|
||||
+/
|
||||
class Actor : ASObject {
|
||||
/* Required fields */
|
||||
string inbox; /// Link to messages received by this actor. Required
|
||||
string outbox; /// Link to messages produced by this actor. Required
|
||||
string following; /// Link to a collection of the actors that this actor is following. Required
|
||||
string followers; /// Link to a collection of the actors that follow this actor. Required
|
||||
|
||||
/* Optional fields */
|
||||
string liked; /// Link to a collection of objects this actor has liked
|
||||
string streams; /// Supplementary list of Collections of interest
|
||||
string preferredUsername; /// A short username for referencing this actor
|
||||
ActorEndpoints endpoints; /// Useful endpoints for this actor
|
||||
|
||||
JSONValue raw;
|
||||
|
||||
/++
|
||||
+ Creates an Actor object based on its json representation
|
||||
+ Params:
|
||||
+ json = ActivityPub actor JSON representation
|
||||
+/
|
||||
this(JSONValue json) {
|
||||
super(json);
|
||||
|
||||
with (this) {
|
||||
inbox = json.requiredKey!"inbox".str;
|
||||
outbox = json.requiredKey!"outbox".str;
|
||||
following = json.requiredKey!"following".str;
|
||||
followers = json.requiredKey!"followers".str;
|
||||
|
||||
liked = json.checkKey!string("liked");
|
||||
streams = json.checkKey!string("streams");
|
||||
preferredUsername = json.checkKey!string("preferredUsername");
|
||||
|
||||
if (JSONValue* j = "endpoints" in json)
|
||||
endpoints = ActorEndpoints.fromJson(*j);
|
||||
else
|
||||
endpoints = ActorEndpoints();
|
||||
|
||||
raw = json;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ActorEndpoints {
|
||||
string proxyUrl;
|
||||
string oauthAuthorizationEndpoint;
|
||||
string oauthTokenEndpoint;
|
||||
string provideClientKey;
|
||||
string signClientKey;
|
||||
string sharedInbox;
|
||||
|
||||
static ActorEndpoints fromJson(JSONValue json) {
|
||||
ActorEndpoints endpoints = ActorEndpoints();
|
||||
|
||||
with (endpoints) {
|
||||
proxyUrl = json.checkKey!string("proxyUrl");
|
||||
oauthAuthorizationEndpoint = json.checkKey!string("oauthAuthorizationEndpoint");
|
||||
oauthTokenEndpoint = json.checkKey!string("oauthTokenEndpoint");
|
||||
provideClientKey = json.checkKey!string("provideClientKey");
|
||||
signClientKey = json.checkKey!string("signClientKey");
|
||||
sharedInbox = json.checkKey!string("sharedInbox");
|
||||
}
|
||||
|
||||
return endpoints;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user