Skip to content

Commit

Permalink
feat: codestyle and summary
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaStarkova-Tochka committed Sep 16, 2024
1 parent f535662 commit 18a1975
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 55 deletions.
96 changes: 85 additions & 11 deletions src/Tochka.JsonRpc.Client/IJsonRpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,42 +253,120 @@ Task<ISingleJsonRpcResult<TResponse>> SendRequest<TParams, TResponse>(IRpcId id,
where TParams : class
where TResponse : class;

/// <summary>
/// Send request to given url. Expects HTTP 200 with JSON-RPC Rpc response
/// </summary>
/// <param name="requestUrl">Relative path, appended to BaseAddress. Must not start with '/'</param>
/// <param name="request">JSON-RPC request</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
/// <exception cref="JsonException">When reading or deserializing JSON from body failed</exception>
/// <exception cref="System.ArgumentException">When requestUrl starts with '/'</exception>
Task<ISingleJsonRpcResult> SendRequest(string requestUrl, Request request, CancellationToken cancellationToken);

/// <summary>
/// Send request to BaseUrl. Expects HTTP 200 with JSON-RPC response
/// </summary>
/// <param name="request">JSON-RPC request</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
/// <exception cref="JsonException">When reading or deserializing JSON from body failed</exception>
Task<ISingleJsonRpcResult> SendRequest(Request request, CancellationToken cancellationToken);

/// <summary>
/// Send request to given url. Id is generated with IJsonRpcIdGenerator. Expects HTTP 200 with JSON-RPC response
/// </summary>
/// <param name="requestUrl">Relative path, appended to BaseAddress. Must not start with '/'</param>
/// <param name="method">JSON-RPC method</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
/// <exception cref="JsonException">When reading or deserializing JSON from body failed</exception>
/// <exception cref="System.ArgumentException">When requestUrl starts with '/'</exception>
Task<ISingleJsonRpcResult> SendRequest(string requestUrl, string method, CancellationToken cancellationToken);

/// <summary>
/// Send request to BaseUrl. Id is generated with IJsonRpcIdGenerator. Expects HTTP 200 with JSON-RPC response
/// </summary>
/// <param name="method">JSON-RPC method</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
/// <exception cref="JsonException">When reading or deserializing JSON from body failed</exception>
Task<ISingleJsonRpcResult> SendRequest(string method, CancellationToken cancellationToken);

/// <summary>
/// Send request to given url. Expects HTTP 200 with JSON-RPC response
/// </summary>
/// <param name="requestUrl">Relative path, appended to BaseAddress. Must not start with '/'</param>
/// <param name="id">JSON-RPC request id. Can be null</param>
/// <param name="method">JSON-RPC method</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
/// <exception cref="JsonException">When reading or deserializing JSON from body failed</exception>
/// <exception cref="System.ArgumentException">When requestUrl starts with '/'</exception>
Task<ISingleJsonRpcResult> SendRequest(string requestUrl, IRpcId id, string method, CancellationToken cancellationToken);

/// <summary>
/// Send request to BaseUrl. Expects HTTP 200 with JSON-RPC response
/// </summary>
/// <param name="id">JSON-RPC request id. Can be null</param>
/// <param name="method">JSON-RPC method</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
/// <exception cref="JsonException">When reading or deserializing JSON from body failed</exception>
/// <exception cref="System.ArgumentException">When requestUrl starts with '/'</exception>
Task<ISingleJsonRpcResult> SendRequest(IRpcId id, string method, CancellationToken cancellationToken);

/// <summary>
/// Send request to given url. Expects HTTP 200 with JSON-RPC Rpc typed response
/// </summary>
/// <typeparam name="TResponse">Type of response</typeparam>
/// <param name="requestUrl">Relative path, appended to BaseAddress. Must not start with '/'</param>
/// <param name="request">JSON-RPC request</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
/// <exception cref="JsonException">When reading or deserializing JSON from body failed</exception>
/// <exception cref="System.ArgumentException">When requestUrl starts with '/'</exception>
Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string requestUrl, Request request, CancellationToken cancellationToken)
where TResponse : class;

/// <summary>
/// Send request to BaseUrl. Expects HTTP 200 with JSON-RPC typed response
/// </summary>
/// <typeparam name="TResponse">Type of response</typeparam>
/// <param name="request">JSON-RPC request</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
/// <exception cref="JsonException">When reading or deserializing JSON from body failed</exception>
Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(Request request, CancellationToken cancellationToken)
where TResponse : class;

/// <summary>
///
/// Send request to given url. Id is generated with IJsonRpcIdGenerator. Expects HTTP 200 with JSON-RPC typed response
/// </summary>
/// <param name="requestUrl"></param>
/// <param name="method"></param>
/// <typeparam name="TResponse">Type of response</typeparam>
/// <param name="requestUrl">Relative path, appended to BaseAddress. Must not start with '/'</param>
/// <param name="method">JSON-RPC method</param>
/// <param name="cancellationToken"></param>
/// <typeparam name="TResponse"></typeparam>
/// <returns></returns>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
/// <exception cref="JsonException">When reading or deserializing JSON from body failed</exception>
/// <exception cref="System.ArgumentException">When requestUrl starts with '/'</exception>
Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string requestUrl, string method, CancellationToken cancellationToken)
where TResponse : class;

/// <summary>
/// Send request to BaseUrl. Id is generated with IJsonRpcIdGenerator. Expects HTTP 200 with JSON-RPC typed response
/// </summary>
/// <typeparam name="TParams">Type of params</typeparam>
/// <typeparam name="TResponse">Type of response</typeparam>
/// <param name="method">JSON-RPC method</param>
/// <param name="parameters">JSON-RPC params - This member MAY be omitted</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
Expand All @@ -299,12 +377,10 @@ Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string method, Canc
/// <summary>
/// Send request to given url. Expects HTTP 200 with JSON-RPC typed response
/// </summary>
/// <typeparam name="TParams">Type of params</typeparam>
/// <typeparam name="TResponse">Type of response</typeparam>
/// <param name="requestUrl">Relative path, appended to BaseAddress. Must not start with '/'</param>
/// <param name="id">JSON-RPC request id. Can be null</param>
/// <param name="method">JSON-RPC method</param>
/// <param name="parameters">JSON-RPC params - This member MAY be omitted</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
Expand All @@ -316,11 +392,9 @@ Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string requestUrl,
/// <summary>
/// Send request to BaseUrl. Expects HTTP 200 with JSON-RPC typed response
/// </summary>
/// <typeparam name="TParams">Type of params</typeparam>
/// <typeparam name="TResponse">Type of response</typeparam>
/// <param name="id">JSON-RPC request id. Can be null</param>
/// <param name="method">JSON-RPC method</param>
/// <param name="parameters">JSON-RPC params - This member MAY be omitted</param>
/// <param name="cancellationToken"></param>
/// <returns>Result to be inspected for response data or errors</returns>
/// <exception cref="JsonRpcException">When HTTP status code is not 200, body is empty or deserialized as batch response</exception>
Expand Down
34 changes: 23 additions & 11 deletions src/Tochka.JsonRpc.Client/JsonRpcClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,23 @@ public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TParams, TRespons
return await SendRequestInternal<TParams, TResponse>(null, request, cancellationToken);
}

/// <inheritdoc />
public async Task<ISingleJsonRpcResult> SendRequest(string requestUrl, Request request, CancellationToken cancellationToken)
{
var id = RpcIdGenerator.GenerateId();
Log.LogTrace("Generated request id [{requestId}]", id);
return await SendRequestInternal(requestUrl, request, cancellationToken);
}

/// <inheritdoc />
public async Task<ISingleJsonRpcResult> SendRequest(Request request, CancellationToken cancellationToken)
{
var id = RpcIdGenerator.GenerateId();
Log.LogTrace("Generated request id [{requestId}]", id);
return await SendRequestInternal(null, request, cancellationToken);
}

/// <inheritdoc />
public async Task<ISingleJsonRpcResult> SendRequest(string requestUrl, string method, CancellationToken cancellationToken)
{
var id = RpcIdGenerator.GenerateId();
Expand All @@ -223,6 +226,7 @@ public async Task<ISingleJsonRpcResult> SendRequest(string requestUrl, string me
return await SendRequestInternal(requestUrl, request, cancellationToken);
}

/// <inheritdoc />
public async Task<ISingleJsonRpcResult> SendRequest(string method, CancellationToken cancellationToken)
{
var id = RpcIdGenerator.GenerateId();
Expand All @@ -238,30 +242,36 @@ public async Task<ISingleJsonRpcResult> SendRequest(string requestUrl, IRpcId id
return await SendRequestInternal(requestUrl, request, cancellationToken);
}

/// <inheritdoc />
public async Task<ISingleJsonRpcResult> SendRequest(IRpcId id, string method, CancellationToken cancellationToken)
{
var request = new Request(id, method);
return await SendRequestInternal(null, request, cancellationToken);
}

public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string requestUrl, Request request, CancellationToken cancellationToken)
where TResponse : class
/// <inheritdoc />
public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string requestUrl, Request request, CancellationToken cancellationToken)
where TResponse : class
=> await SendRequestInternal<TResponse>(requestUrl, request, cancellationToken);


/// <inheritdoc />
public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(Request request, CancellationToken cancellationToken)
where TResponse : class
=> await SendRequestInternal<TResponse>(null, request, cancellationToken);

public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string requestUrl, string method, CancellationToken cancellationToken) where TResponse : class

/// <inheritdoc />
public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string requestUrl, string method, CancellationToken cancellationToken)
where TResponse : class
{
var id = RpcIdGenerator.GenerateId();
Log.LogTrace("Generated request id [{requestId}]", id);
var request = new Request(id, method);
return await SendRequestInternal<TResponse>(requestUrl, request, cancellationToken);
}

public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string method, CancellationToken cancellationToken) where TResponse : class
/// <inheritdoc />
public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string method, CancellationToken cancellationToken)
where TResponse : class
{
var id = RpcIdGenerator.GenerateId();
Log.LogTrace("Generated request id [{requestId}]", id);
Expand All @@ -276,9 +286,10 @@ public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(string
var request = new Request(id, method);
return await SendRequestInternal<TResponse>(requestUrl, request, cancellationToken);
}

/// <inheritdoc />
public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(IRpcId id, string method, CancellationToken cancellationToken) where TResponse : class
public async Task<ISingleJsonRpcResult<TResponse>> SendRequest<TResponse>(IRpcId id, string method, CancellationToken cancellationToken)
where TResponse : class
{
var request = new Request(id, method);
return await SendRequestInternal<TResponse>(null, request, cancellationToken);
Expand Down Expand Up @@ -348,7 +359,7 @@ internal virtual async Task<ISingleJsonRpcResult> SendRequestInternal<TParams>(s
throw new JsonRpcException(message, context);
}
}

// internal virtual for mocking in tests
internal virtual async Task<ISingleJsonRpcResult> SendRequestInternal(string? requestUrl, Request request, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -386,7 +397,7 @@ internal virtual async Task<ISingleJsonRpcResult<TResponse>> SendRequestInternal
throw new JsonRpcException(message, context);
}
}

// internal virtual for mocking in tests
internal virtual async Task<ISingleJsonRpcResult<TResponse>> SendRequestInternal<TResponse>(string? requestUrl, Request request, CancellationToken cancellationToken)
where TResponse : class
Expand All @@ -398,7 +409,8 @@ internal virtual async Task<ISingleJsonRpcResult<TResponse>> SendRequestInternal
case SingleResponseWrapper singleResponseWrapper:
context.WithSingleResponse(singleResponseWrapper.Response);
Log.LogTrace("Request id [{requestId}]: success", request.Id);
return new SingleJsonRpcResult<TResponse>(context, HeadersJsonSerializerOptions,
return new SingleJsonRpcResult<TResponse>(context,
HeadersJsonSerializerOptions,
DataJsonSerializerOptions);
default:
var message = $"Expected single response, got [{responseWrapper}]";
Expand Down
Loading

0 comments on commit 18a1975

Please sign in to comment.