Skip to content

Commit

Permalink
Fixed empty POST requests
Browse files Browse the repository at this point in the history
and added support for parenthesis in filters.
  • Loading branch information
Uralstech committed Sep 7, 2024
1 parent 60526b1 commit 254d992
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ namespace Uralstech.UCloud.Operations
/// </summary>
public class OperationFilterConditions
{
/// <summary>
/// Is this object also the start of a parenthetical condition? If <see langword="true"/>, then a ( symbol is added to the start of this conditino.
/// </summary>
public bool IsStartOfParentheticalCondition = false;

/// <summary>
/// Is this object also the end of a parenthetical condition? If <see langword="true"/>, then a ) symbol is added to the end of this conditino.
/// </summary>
public bool IsEndOfParentheticalCondition = false;

/// <summary>
/// The Left-Hand-Side operand.
/// </summary>
Expand All @@ -25,9 +35,11 @@ public class OperationFilterConditions
/// <inheritdoc/>
public override string ToString()
{
return Operator == OperationFilterOperator.None
string expression = Operator == OperationFilterOperator.None
? OperandA.ToString()
: $"{OperandA}{JsonConvert.SerializeObject(Operator)[1..^1]}{OperandB}";

return (IsStartOfParentheticalCondition ? '(' : string.Empty) + expression + (IsEndOfParentheticalCondition ? ')' : string.Empty);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Uralstech.UCloud.Operations
{
/// <summary>
/// Requests metadata for an operation. Return type is <see cref="OperationsListResponse"/> or <see cref="Generic.OperationsListResponse{TMetadata, TResponse}"/>.
/// Requests metadata for an operation. Return type is <see cref="OperationsListResponse"/> or <see cref="Generic.OperationsListResponse{TOperation}"/>.
/// </summary>
public class OperationsListRequest : IOperationsGetRequest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ namespace Uralstech.UCloud.Operations
[AddComponentMenu("Uralstech/UCloud/Operations/Operations Manager")]
public class OperationsManager : Singleton<OperationsManager>
{
/// <summary>
/// An empty JSON object.
/// </summary>
private const string EmptyJsonObject = "{}";

/// <summary>
/// Computes a GET request on the google.longrunning API.
/// </summary>
///
/// <typeparam name="TResponse">
/// The response type. For example, a request of type <see cref="OperationsListRequest"/> corresponds
/// to a response type of <see cref="OperationsListResponse"/> or <see cref="Generic.OperationsListResponse{TMetadata, TResponse}"/>.
/// to a response type of <see cref="OperationsListResponse"/> or <see cref="Generic.OperationsListResponse{TOperation}"/>.
/// </typeparam>
///
/// <param name="accessToken">The OAuth Access Token to use for authentication.</param>
Expand Down Expand Up @@ -149,7 +154,7 @@ private TResponse ConfirmResponse<TResponse>(UnityWebRequest request)
/// <exception cref="OperationResponseParsingException">Thrown if the response was not empty.</exception>
private void ConfirmResponse(UnityWebRequest request)
{
if (!string.IsNullOrEmpty(request.downloadHandler?.text))
if (!string.IsNullOrEmpty(request.downloadHandler?.text) || request.downloadHandler.text.Trim() == EmptyJsonObject)
{
Debug.LogError($"Failed to confirm successful API response:\n{request.downloadHandler?.text}");
throw new OperationResponseParsingException(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Cloud",
"Integration"
],
"version": "1.1.0-preview.3",
"version": "1.1.0-preview.4",
"unity": "2022.3",
"hideInEditor": false,
"documentationUrl": "https://uralstech.github.io/UCloud.Operations/",
Expand Down

0 comments on commit 254d992

Please sign in to comment.