Better json management
This commit is contained in:
@@ -9,10 +9,13 @@ import util;
|
||||
* 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;
|
||||
|
||||
/++
|
||||
@@ -25,24 +28,23 @@ class ASObject {
|
||||
with (this) {
|
||||
const(JSONValue)* ascontext = "@context" in json;
|
||||
|
||||
if (ascontext == null)
|
||||
throw new Exception("No context in ActivityStream Object");
|
||||
if (ascontext) {
|
||||
switch ((*ascontext).type) {
|
||||
case JSONType.ARRAY:
|
||||
context = (*ascontext)[0].str;
|
||||
break;
|
||||
|
||||
switch ((*ascontext).type) {
|
||||
case JSONType.ARRAY:
|
||||
context = (*ascontext)[0].str;
|
||||
break;
|
||||
case JSONType.STRING:
|
||||
context = (*ascontext).str;
|
||||
break;
|
||||
|
||||
case JSONType.STRING:
|
||||
context = (*ascontext).str;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception("Invalid @context type for ActivityStream Object");
|
||||
default:
|
||||
throw new Exception("Invalid @context type for ActivityStream Object");
|
||||
}
|
||||
}
|
||||
|
||||
id = json.requiredKey!"id".str;
|
||||
type = json.requiredKey!"type".str;
|
||||
optional(json, "id", id);
|
||||
optional(json, "type", type);
|
||||
|
||||
raw = json;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user