diff --git a/src/ReC.Client/Api/ProfileApi.cs b/src/ReC.Client/Api/ProfileApi.cs new file mode 100644 index 0000000..2c3cc19 --- /dev/null +++ b/src/ReC.Client/Api/ProfileApi.cs @@ -0,0 +1,73 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace ReC.Client.Api +{ + /// + /// Provides access to profile endpoints. + /// + public class ProfileApi + { + private readonly HttpClient _http; + + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client used for requests. + public ProfileApi(HttpClient http) + { + _http = http; + } + + /// + /// Retrieves a profile by identifier. + /// + /// The profile identifier. + /// Whether to include related actions. + /// A token to cancel the operation. + /// The HTTP response message. + public Task GetProfileAsync(long id, bool includeActions = false, CancellationToken cancel = default) + { + var query = ReCClientHelpers.BuildQuery(("Id", id), ("IncludeActions", includeActions)); + return _http.GetAsync($"api/Profile{query}", cancel); + } + + /// + /// Creates a profile. + /// + /// The payload type. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task CreateProfileAsync(T procedure, CancellationToken cancel = default) + => _http.PostAsync("api/Profile", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Updates a profile. + /// + /// The payload type. + /// The profile identifier. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task UpdateProfileAsync(long id, T procedure, CancellationToken cancel = default) + => _http.PutAsync($"api/Profile/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Deletes profiles. + /// + /// The payload type containing identifiers. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task DeleteProfilesAsync(T procedure, CancellationToken cancel = default) + { + var request = new HttpRequestMessage(HttpMethod.Delete, "api/Profile") + { + Content = ReCClientHelpers.ToJsonContent(procedure) + }; + return _http.SendAsync(request, cancel); + } + } +}