Refactor API classes to use BaseCrudApi for CRUD ops
Introduce BaseCrudApi to encapsulate common CRUD logic for API resource classes. Refactor CommonApi, EndpointAuthApi, EndpointParamsApi, EndpointsApi, ProfileApi, RecActionApi, and ResultApi to inherit from BaseCrudApi, removing duplicated CRUD methods and constructors. This centralizes CRUD operations, reduces code duplication, and improves maintainability.
This commit is contained in:
71
src/ReC.Client/Api/BaseCrudApi.cs
Normal file
71
src/ReC.Client/Api/BaseCrudApi.cs
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ReC.Client.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides shared CRUD operations for API resources.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class BaseCrudApi
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The HTTP client used to send requests.
|
||||||
|
/// </summary>
|
||||||
|
protected readonly HttpClient Http;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The base resource path for the API endpoint.
|
||||||
|
/// </summary>
|
||||||
|
protected readonly string ResourcePath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="BaseCrudApi"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
|
/// <param name="resourcePath">The base resource path for the API endpoint.</param>
|
||||||
|
protected BaseCrudApi(HttpClient http, string resourcePath)
|
||||||
|
{
|
||||||
|
Http = http ?? throw new ArgumentNullException(nameof(http));
|
||||||
|
ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a resource.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The payload type.</typeparam>
|
||||||
|
/// <param name="payload">The payload to send.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>The HTTP response message.</returns>
|
||||||
|
public Task<HttpResponseMessage> CreateAsync<T>(T payload, CancellationToken cancel = default)
|
||||||
|
=> Http.PostAsync(ResourcePath, ReCClientHelpers.ToJsonContent(payload), cancel);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a resource by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The payload type.</typeparam>
|
||||||
|
/// <param name="id">The resource identifier.</param>
|
||||||
|
/// <param name="payload">The payload to send.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>The HTTP response message.</returns>
|
||||||
|
public Task<HttpResponseMessage> UpdateAsync<T>(long id, T payload, CancellationToken cancel = default)
|
||||||
|
=> Http.PutAsync($"{ResourcePath}/{id}", ReCClientHelpers.ToJsonContent(payload), cancel);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes resources with identifiers supplied in the payload.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
||||||
|
/// <param name="payload">The payload to send.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>The HTTP response message.</returns>
|
||||||
|
public Task<HttpResponseMessage> DeleteAsync<T>(T payload, CancellationToken cancel = default)
|
||||||
|
{
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Delete, ResourcePath)
|
||||||
|
{
|
||||||
|
Content = ReCClientHelpers.ToJsonContent(payload)
|
||||||
|
};
|
||||||
|
return Http.SendAsync(request, cancel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,53 +7,14 @@ namespace ReC.Client.Api
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to common object endpoints.
|
/// Provides access to common object endpoints.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CommonApi
|
public class CommonApi : BaseCrudApi
|
||||||
{
|
{
|
||||||
private readonly HttpClient _http;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="CommonApi"/> class.
|
/// Initializes a new instance of the <see cref="CommonApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
public CommonApi(HttpClient http)
|
public CommonApi(HttpClient http) : base(http, "api/Common")
|
||||||
{
|
{
|
||||||
_http = http;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an object.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> CreateAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PostAsync("api/Common", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates an object.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> UpdateAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PutAsync("api/Common", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes objects.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> DeleteAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
{
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Delete, "api/Common")
|
|
||||||
{
|
|
||||||
Content = ReCClientHelpers.ToJsonContent(procedure)
|
|
||||||
};
|
|
||||||
return _http.SendAsync(request, cancel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,54 +7,14 @@ namespace ReC.Client.Api
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to endpoint authentication endpoints.
|
/// Provides access to endpoint authentication endpoints.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EndpointAuthApi
|
public class EndpointAuthApi : BaseCrudApi
|
||||||
{
|
{
|
||||||
private readonly HttpClient _http;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="EndpointAuthApi"/> class.
|
/// Initializes a new instance of the <see cref="EndpointAuthApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
public EndpointAuthApi(HttpClient http)
|
public EndpointAuthApi(HttpClient http) : base(http, "api/EndpointAuth")
|
||||||
{
|
{
|
||||||
_http = http;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates endpoint authentication configuration.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> CreateAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PostAsync("api/EndpointAuth", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates endpoint authentication configuration.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="id">The authentication identifier.</param>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> UpdateAsync<T>(long id, T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PutAsync($"api/EndpointAuth/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes endpoint authentications.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> DeleteAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
{
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Delete, "api/EndpointAuth")
|
|
||||||
{
|
|
||||||
Content = ReCClientHelpers.ToJsonContent(procedure)
|
|
||||||
};
|
|
||||||
return _http.SendAsync(request, cancel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,54 +7,14 @@ namespace ReC.Client.Api
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to endpoint parameter endpoints.
|
/// Provides access to endpoint parameter endpoints.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EndpointParamsApi
|
public class EndpointParamsApi : BaseCrudApi
|
||||||
{
|
{
|
||||||
private readonly HttpClient _http;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="EndpointParamsApi"/> class.
|
/// Initializes a new instance of the <see cref="EndpointParamsApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
public EndpointParamsApi(HttpClient http)
|
public EndpointParamsApi(HttpClient http) : base(http, "api/EndpointParams")
|
||||||
{
|
{
|
||||||
_http = http;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates endpoint parameters.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> CreateAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PostAsync("api/EndpointParams", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates endpoint parameters.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="id">The parameter identifier.</param>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> UpdateAsync<T>(long id, T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PutAsync($"api/EndpointParams/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes endpoint parameters.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> DeleteAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
{
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Delete, "api/EndpointParams")
|
|
||||||
{
|
|
||||||
Content = ReCClientHelpers.ToJsonContent(procedure)
|
|
||||||
};
|
|
||||||
return _http.SendAsync(request, cancel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,54 +7,14 @@ namespace ReC.Client.Api
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to endpoint definitions.
|
/// Provides access to endpoint definitions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EndpointsApi
|
public class EndpointsApi : BaseCrudApi
|
||||||
{
|
{
|
||||||
private readonly HttpClient _http;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="EndpointsApi"/> class.
|
/// Initializes a new instance of the <see cref="EndpointsApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
public EndpointsApi(HttpClient http)
|
public EndpointsApi(HttpClient http) : base(http, "api/Endpoints")
|
||||||
{
|
{
|
||||||
_http = http;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an endpoint.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> CreateAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PostAsync("api/Endpoints", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates an endpoint.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="id">The endpoint identifier.</param>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> UpdateAsync<T>(long id, T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PutAsync($"api/Endpoints/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes endpoints.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> DeleteAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
{
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Delete, "api/Endpoints")
|
|
||||||
{
|
|
||||||
Content = ReCClientHelpers.ToJsonContent(procedure)
|
|
||||||
};
|
|
||||||
return _http.SendAsync(request, cancel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,14 @@ namespace ReC.Client.Api
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to profile endpoints.
|
/// Provides access to profile endpoints.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProfileApi
|
public class ProfileApi : BaseCrudApi
|
||||||
{
|
{
|
||||||
private readonly HttpClient _http;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ProfileApi"/> class.
|
/// Initializes a new instance of the <see cref="ProfileApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
public ProfileApi(HttpClient http)
|
public ProfileApi(HttpClient http) : base(http, "api/Profile")
|
||||||
{
|
{
|
||||||
_http = http;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -30,44 +27,7 @@ namespace ReC.Client.Api
|
|||||||
public Task<HttpResponseMessage> GetAsync(long id, bool includeActions = false, CancellationToken cancel = default)
|
public Task<HttpResponseMessage> GetAsync(long id, bool includeActions = false, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
var query = ReCClientHelpers.BuildQuery(("Id", id), ("IncludeActions", includeActions));
|
var query = ReCClientHelpers.BuildQuery(("Id", id), ("IncludeActions", includeActions));
|
||||||
return _http.GetAsync($"api/Profile{query}", cancel);
|
return Http.GetAsync($"{ResourcePath}{query}", cancel);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a profile.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> CreateAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PostAsync("api/Profile", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates a profile.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="id">The profile identifier.</param>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> UpdateAsync<T>(long id, T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PutAsync($"api/Profile/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes profiles.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> DeleteAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
{
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Delete, "api/Profile")
|
|
||||||
{
|
|
||||||
Content = ReCClientHelpers.ToJsonContent(procedure)
|
|
||||||
};
|
|
||||||
return _http.SendAsync(request, cancel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,14 @@ namespace ReC.Client.Api
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to RecAction endpoints.
|
/// Provides access to RecAction endpoints.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RecActionApi
|
public class RecActionApi : BaseCrudApi
|
||||||
{
|
{
|
||||||
private readonly HttpClient _http;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RecActionApi"/> class.
|
/// Initializes a new instance of the <see cref="RecActionApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
public RecActionApi(HttpClient http)
|
public RecActionApi(HttpClient http) : base(http, "api/RecAction")
|
||||||
{
|
{
|
||||||
_http = http;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -28,7 +25,7 @@ namespace ReC.Client.Api
|
|||||||
/// <returns><see langword="true"/> if the request succeeds; otherwise, <see langword="false"/>.</returns>
|
/// <returns><see langword="true"/> if the request succeeds; otherwise, <see langword="false"/>.</returns>
|
||||||
public async Task<bool> InvokeAsync(int profileId, CancellationToken cancellationToken = default)
|
public async Task<bool> InvokeAsync(int profileId, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var resp = await _http.PostAsync($"api/RecAction/invoke/{profileId}", content: null, cancellationToken);
|
var resp = await Http.PostAsync($"{ResourcePath}/invoke/{profileId}", content: null, cancellationToken);
|
||||||
return resp.IsSuccessStatusCode;
|
return resp.IsSuccessStatusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,44 +39,7 @@ namespace ReC.Client.Api
|
|||||||
public Task<HttpResponseMessage> GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
|
public Task<HttpResponseMessage> GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
var query = ReCClientHelpers.BuildQuery(("ProfileId", profileId), ("Invoked", invoked));
|
var query = ReCClientHelpers.BuildQuery(("ProfileId", profileId), ("Invoked", invoked));
|
||||||
return _http.GetAsync($"api/RecAction{query}", cancel);
|
return Http.GetAsync($"{ResourcePath}{query}", cancel);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a Rec action.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> CreateAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PostAsync("api/RecAction", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates a Rec action.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="id">The action identifier.</param>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> UpdateAsync<T>(long id, T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PutAsync($"api/RecAction/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes Rec actions.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> DeleteAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
{
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Delete, "api/RecAction")
|
|
||||||
{
|
|
||||||
Content = ReCClientHelpers.ToJsonContent(procedure)
|
|
||||||
};
|
|
||||||
return _http.SendAsync(request, cancel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,14 @@ namespace ReC.Client.Api
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to output result endpoints.
|
/// Provides access to output result endpoints.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ResultApi
|
public class ResultApi : BaseCrudApi
|
||||||
{
|
{
|
||||||
private readonly HttpClient _http;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ResultApi"/> class.
|
/// Initializes a new instance of the <see cref="ResultApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
public ResultApi(HttpClient http)
|
public ResultApi(HttpClient http) : base(http, "api/Result")
|
||||||
{
|
{
|
||||||
_http = http;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -31,44 +28,7 @@ namespace ReC.Client.Api
|
|||||||
public Task<HttpResponseMessage> GetAsync(long? id = null, long? actionId = null, long? profileId = null, CancellationToken cancel = default)
|
public Task<HttpResponseMessage> GetAsync(long? id = null, long? actionId = null, long? profileId = null, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
var query = ReCClientHelpers.BuildQuery(("Id", id), ("ActionId", actionId), ("ProfileId", profileId));
|
var query = ReCClientHelpers.BuildQuery(("Id", id), ("ActionId", actionId), ("ProfileId", profileId));
|
||||||
return _http.GetAsync($"api/Result{query}", cancel);
|
return Http.GetAsync($"{ResourcePath}{query}", cancel);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a result.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> CreateAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PostAsync("api/Result", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates a result.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type.</typeparam>
|
|
||||||
/// <param name="id">The result identifier.</param>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> UpdateAsync<T>(long id, T procedure, CancellationToken cancel = default)
|
|
||||||
=> _http.PutAsync($"api/Result/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes results.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
|
||||||
/// <param name="procedure">The payload to send.</param>
|
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
|
||||||
/// <returns>The HTTP response message.</returns>
|
|
||||||
public Task<HttpResponseMessage> DeleteAsync<T>(T procedure, CancellationToken cancel = default)
|
|
||||||
{
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Delete, "api/Result")
|
|
||||||
{
|
|
||||||
Content = ReCClientHelpers.ToJsonContent(procedure)
|
|
||||||
};
|
|
||||||
return _http.SendAsync(request, cancel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user