-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: shipped config + SingleJsonRpcResult missing
- Loading branch information
1 parent
aa2e3ee
commit 61e34f0
Showing
2 changed files
with
189 additions
and
46 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/Tochka.JsonRpc.Client/Models/Single/SingleJsonRpcResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Text.Json; | ||
using JetBrains.Annotations; | ||
using Tochka.JsonRpc.Common.Models.Response; | ||
using Tochka.JsonRpc.Common.Models.Response.Untyped; | ||
|
||
namespace Tochka.JsonRpc.Client.Models.Single; | ||
|
||
/// <inheritdoc cref="Tochka.JsonRpc.Client.Models.Single.ISingleJsonRpcResult" /> | ||
[PublicAPI] | ||
public sealed class SingleJsonRpcResult : SingleJsonRpcResult<object>, ISingleJsonRpcResult | ||
{ | ||
/// <summary></summary> | ||
public SingleJsonRpcResult(IJsonRpcCallContext context, JsonSerializerOptions headersJsonSerializerOptions, | ||
JsonSerializerOptions dataJsonSerializerOptions) : base(context, headersJsonSerializerOptions, dataJsonSerializerOptions) | ||
{ } | ||
|
||
/// <inheritdoc /> | ||
public TResponse? GetResponseOrThrow<TResponse>() => Advanced.GetResponseOrThrow<TResponse>(); | ||
|
||
/// <inheritdoc /> | ||
public TResponse? AsResponse<TResponse>() => Advanced.AsResponse<TResponse>(); | ||
} | ||
|
||
|
||
/// <inheritdoc /> | ||
[PublicAPI] | ||
public class SingleJsonRpcResult<TResponse> : ISingleJsonRpcResult<TResponse> | ||
{ | ||
/// <summary> | ||
/// Context with all information about request and response | ||
/// </summary> | ||
protected readonly IJsonRpcCallContext Context; | ||
|
||
/// <summary> | ||
/// JsonSerializerOptions used to process JSON-RPC root object. Does not affect JSON-RPC params/result/error.data | ||
/// </summary> | ||
protected readonly JsonSerializerOptions HeadersJsonSerializerOptions; | ||
|
||
/// <summary> | ||
/// JsonSerializerOptions used to process JSON-RPC params/result/error.data. Does not affect JSON-RPC root object | ||
/// </summary> | ||
protected readonly JsonSerializerOptions DataJsonSerializerOptions; | ||
|
||
/// <summary> | ||
/// Response if call was request | ||
/// </summary> | ||
protected readonly IResponse? Response; | ||
|
||
/// <inheritdoc /> | ||
public ISingleJsonRpcResultAdvanced Advanced { get; init; } | ||
|
||
/// <summary></summary> | ||
public SingleJsonRpcResult(IJsonRpcCallContext context, JsonSerializerOptions headersJsonSerializerOptions, JsonSerializerOptions dataJsonSerializerOptions) | ||
{ | ||
Context = context; | ||
if (context.BatchResponse != null) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(context), "Expected single response"); | ||
} | ||
|
||
Response = context.SingleResponse; | ||
HeadersJsonSerializerOptions = headersJsonSerializerOptions; | ||
DataJsonSerializerOptions = dataJsonSerializerOptions; | ||
Advanced = new SingleJsonSingleJsonRpcResultAdvanced(Context, HeadersJsonSerializerOptions, DataJsonSerializerOptions); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public TResponse? GetResponseOrThrow() => Advanced.GetResponseOrThrow<TResponse>(); | ||
|
||
/// <inheritdoc /> | ||
public TResponse? AsResponse() => Advanced.AsResponse<TResponse>(); | ||
|
||
/// <inheritdoc /> | ||
public bool HasError() => Response is UntypedErrorResponse; | ||
} |
Oops, something went wrong.