Normalize /Api/Type under TypeResponse

This commit is contained in:
JustArchi
2018-02-12 11:11:17 +01:00
parent bb06b9a887
commit 139bc1c951

View File

@@ -554,7 +554,7 @@ namespace ArchiSteamFarm {
{ nameof(targetType.CustomAttributes), targetType.CustomAttributes.Select(attribute => attribute.AttributeType.GetUnifiedName()) }
};
Dictionary<string, object> body = new Dictionary<string, object>();
Dictionary<string, string> body = new Dictionary<string, string>();
if (targetType.IsClass) {
foreach (FieldInfo field in targetType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(field => !field.IsPrivate)) {
@@ -573,12 +573,7 @@ namespace ArchiSteamFarm {
}
}
Dictionary<string, object> result = new Dictionary<string, object>(2) {
{ "Properties", properties },
{ "Body", body }
};
await ResponseJsonObject(request, response, new GenericResponse(true, "OK", result)).ConfigureAwait(false);
await ResponseJsonObject(request, response, new GenericResponse(true, "OK", new TypeResponse(body, properties))).ConfigureAwait(false);
return true;
}
@@ -927,5 +922,22 @@ namespace ArchiSteamFarm {
internal const string Get = "GET";
internal const string Post = "POST";
}
private sealed class TypeResponse {
[JsonProperty]
internal readonly Dictionary<string, string> Body;
[JsonProperty]
internal readonly Dictionary<string, object> Properties;
internal TypeResponse(Dictionary<string, string> body, Dictionary<string, object> properties) {
if ((body == null) || (properties == null)) {
throw new ArgumentNullException(nameof(body) + " || " + nameof(properties));
}
Body = body;
Properties = properties;
}
}
}
}