diff --git a/src/ReC.Client/Api/CommonApi.cs b/src/ReC.Client/Api/CommonApi.cs new file mode 100644 index 0000000..941c9e0 --- /dev/null +++ b/src/ReC.Client/Api/CommonApi.cs @@ -0,0 +1,59 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace ReC.Client.Api +{ + /// + /// Provides access to common object endpoints. + /// + public class CommonApi + { + private readonly HttpClient _http; + + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client used for requests. + public CommonApi(HttpClient http) + { + _http = http; + } + + /// + /// Creates an object. + /// + /// The payload type. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task CreateObjectAsync(T procedure, CancellationToken cancel = default) + => _http.PostAsync("api/Common", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Updates an object. + /// + /// The payload type. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task UpdateObjectAsync(T procedure, CancellationToken cancel = default) + => _http.PutAsync("api/Common", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Deletes objects. + /// + /// The payload type containing identifiers. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task DeleteObjectAsync(T procedure, CancellationToken cancel = default) + { + var request = new HttpRequestMessage(HttpMethod.Delete, "api/Common") + { + Content = ReCClientHelpers.ToJsonContent(procedure) + }; + return _http.SendAsync(request, cancel); + } + } +}