75 lines
2.1 KiB
D
75 lines
2.1 KiB
D
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) {
|
|
required(json, "inbox", inbox);
|
|
required(json, "outbox", outbox);
|
|
required(json, "following", following);
|
|
required(json, "followers", followers);
|
|
|
|
optional(json, "liked", liked);
|
|
optional(json, "streams", streams);
|
|
optional(json, "preferredUsername", preferredUsername);
|
|
|
|
endpoints = ActorEndpoints.fromJson(json.optional!JSONValue("endpoints"));
|
|
|
|
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) {
|
|
optional(json, "proxyUrl", proxyUrl);
|
|
optional(json, "oauthAuthorizationEndpoint", oauthAuthorizationEndpoint);
|
|
optional(json, "oauthTokenEndpoint", oauthTokenEndpoint);
|
|
optional(json, "provideClientKey", provideClientKey);
|
|
optional(json, "signClientKey", signClientKey);
|
|
optional(json, "sharedInbox", sharedInbox);
|
|
}
|
|
|
|
return endpoints;
|
|
}
|
|
}
|