Files
ActivityPubD/source/ap/activity_stream.d

51 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 {
string context; /// Must be activitystream context
string id; /// AP requirement for unique identifier
string type; /// AP requirement for type of object
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 == null)
throw new Exception("No context in ActivityStream Object");
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");
}
id = json.requiredKey!"id".str;
type = json.requiredKey!"type".str;
raw = json;
}
}
}