Updated random.org objects to allow for proper deserialization.

This commit is contained in:
2025-06-18 08:30:51 -04:00
parent 6c8bc6fa01
commit 86e821c702
2 changed files with 12 additions and 18 deletions

View File

@@ -26,18 +26,10 @@ namespace osrs_toolbox
replacement = AllowDuplicates
}
};
string TestString = string.Empty;
TestString += string.Format("{0}: {1}\n", nameof(Request.jsonrpc), Request.jsonrpc);
TestString += string.Format("{0}: {1}\n", nameof(Request.method), Request.method);
string RequestJson = Request.GetJson();
TestString += string.Format("{0}\n", RequestJson);
string ResponseJson = await RestServices.GetPostResponseAsync(new Uri(BaseEndpoint), RequestJson, APIKey).ConfigureAwait(false);
TestString += string.Format("{0}", ResponseJson);
MessageBox.Show(TestString);
RandomIntegerRequestResponse response = JsonSerializer.Deserialize<RandomIntegerRequestResponse>(ResponseJson);
return response.result.random.data;
//return TestString;
//return ResponseJson;
}
}
}

View File

@@ -11,7 +11,9 @@ namespace osrs_toolbox
{
public class RandomIntegerRequest
{
[JsonPropertyName("jsonrpc")]
public string jsonrpc { get; set; } = "2.0";
[JsonPropertyName("method")]
public string method { get; set; } = "generateIntegers";
[JsonPropertyName("params")]
public RandomIntegerRequestParameters parameters { get; set; } = new();
@@ -34,23 +36,23 @@ namespace osrs_toolbox
public class RandomIntegerRequestResponse
{
public string jsonrpc;
public RandomIntegerResult result;
public int id;
public string jsonrpc { get; set; }
public RandomIntegerResult result { get; set; }
public long id { get; set; }
}
public class RandomIntegerResult
{
public RandomIntegerData random;
public int bitsUsed;
public int bitsLeft;
public int requestsLeft;
public int advisoryDelay;
public RandomIntegerData random { get; set; }
public int bitsUsed { get; set; }
public int bitsLeft { get; set; }
public int requestsLeft { get; set; }
public int advisoryDelay { get; set; }
}
public class RandomIntegerData
{
public int[] data;
public DateTime completionTime;
public int[] data { get; set; }
public string completionTime { get; set; }
}
}