53 lines
1.1 KiB
D
53 lines
1.1 KiB
D
module ap.activity_stream;
|
|
|
|
import std.json;
|
|
|
|
import util;
|
|
|
|
/++
|
|
* Basic ActivityStream Object
|
|
* https://www.w3.org/TR/activitypub/#obj
|
|
+/
|
|
class ASObject {
|
|
// Required fields (for root objects)
|
|
string context; /// Must be activitystream context
|
|
string id; /// AP requirement for unique identifier
|
|
string type; /// AP requirement for type of object
|
|
|
|
// Optional fields
|
|
|
|
JSONValue raw;
|
|
|
|
/++
|
|
+ Constructs the object according to json source
|
|
+ Params:
|
|
+ json = the source json
|
|
+ Returns: Object
|
|
+/
|
|
this(JSONValue json) {
|
|
with (this) {
|
|
const(JSONValue)* ascontext = "@context" in json;
|
|
|
|
if (ascontext) {
|
|
switch ((*ascontext).type) {
|
|
case JSONType.ARRAY:
|
|
context = (*ascontext)[0].str;
|
|
break;
|
|
|
|
case JSONType.STRING:
|
|
context = (*ascontext).str;
|
|
break;
|
|
|
|
default:
|
|
throw new Exception("Invalid @context type for ActivityStream Object");
|
|
}
|
|
}
|
|
|
|
optional(json, "id", id);
|
|
optional(json, "type", type);
|
|
|
|
raw = json;
|
|
}
|
|
}
|
|
}
|