-
Notifications
You must be signed in to change notification settings - Fork 0
Ready for Review WorkforceManagementApi #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
501e1cd
627f731
c65085e
f488b65
124382f
9f153c0
1aa0968
66bcc38
49bd2f0
5cb01bb
65363ab
a89a6bc
0d13aa7
238993a
599e7d8
8ace08a
e03986e
de502b0
c860b22
3f445a1
deac552
3584356
b551fc0
d8b51fb
1f97ab8
ad6d7d0
1674c14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,245 @@ | ||
| using System.Collections.Specialized; | ||
| using System.Net.Http.Json; | ||
| using System.Text.Json; | ||
| using Microsoft.Extensions.Options; | ||
| using PureCloud.Client.Contracts; | ||
| using PureCloud.Client.Http; | ||
| using PureCloud.Client.Json; | ||
| using PureCloud.Client.Models; | ||
|
|
||
| namespace PureCloud.Client.Apis; | ||
|
|
||
| /// <inheritdoc /> | ||
| public sealed class WorkforceManagementApi : IWorkforceManagementApi | ||
| { | ||
| private readonly HttpClient _httpClient; | ||
| private readonly JsonSerializerOptions _options; | ||
|
|
||
| public WorkforceManagementApi(IHttpClientFactory httpClientFactory, IOptions<PureCloudJsonSerializerOptions> options) | ||
| { | ||
| _httpClient = httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName); | ||
| _options = options.Value.JsonSerializerOptions; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<BusinessUnitListing> GetBusinessUnitsAsync(string feature = null, string divisionId = null, CancellationToken cancellationToken = default) | ||
| { | ||
| var parameters = new NameValueCollection(); | ||
|
|
||
| if (!string.IsNullOrEmpty(feature)) | ||
| { | ||
| parameters.Add("feature", UriHelper.ParameterToString(feature)); | ||
| } | ||
|
|
||
| if (!string.IsNullOrEmpty(divisionId)) | ||
| { | ||
| parameters.Add("divisionId", UriHelper.ParameterToString(divisionId)); | ||
| } | ||
|
|
||
| var uri = UriHelper.GetUri("api/v2/workforcemanagement/businessunits", parameters); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<BusinessUnitListing>(_options, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<BusinessUnitResponse> GetBusinessUnitAsync(string businessUnitId, List<string> expand = null, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(businessUnitId); | ||
|
|
||
| var parameters = new NameValueCollection(); | ||
|
|
||
| if (expand != null && expand.Any()) | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| foreach (var item in expand) | ||
| { | ||
| parameters.Add("expand", item); | ||
| } | ||
| } | ||
|
|
||
| var uri = UriHelper.GetUri($"api/v2/workforcemanagement/businessunits/{Uri.EscapeDataString(businessUnitId)}", parameters); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<BusinessUnitResponse>(_options, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<bool> DeleteBusinessUnitAsync(string businessUnitId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(businessUnitId); | ||
|
|
||
| var uri = $"api/v2/workforcemanagement/businessunits/{Uri.EscapeDataString(businessUnitId)}"; | ||
|
|
||
| var response = await _httpClient.DeleteAsync(uri, cancellationToken); | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return response.IsSuccessStatusCode; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<bool> DeleteManagementUnitAsync(string managementUnitId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(managementUnitId); | ||
|
|
||
| var uri = $"api/v2/workforcemanagement/managementunits/{Uri.EscapeDataString(managementUnitId)}"; | ||
|
|
||
| var response = await _httpClient.DeleteAsync(uri, cancellationToken); | ||
|
|
||
| return response.IsSuccessStatusCode; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<ActivityCodeContainer> GetActivityCodesAsync(string businessUnitId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(businessUnitId); | ||
|
|
||
| var uri = $"api/v2/workforcemanagement/businessunits/{Uri.EscapeDataString(businessUnitId)}/activitycodes"; | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<ActivityCodeContainer>(_options, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<ActivityCode> CreateActivityCodeAsync(string businessUnitId, CreateActivityCodeRequest body, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(businessUnitId); | ||
| ArgumentNullException.ThrowIfNull(body); | ||
|
|
||
MikeAlhayek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var uri = $"api/v2/workforcemanagement/businessunits/{Uri.EscapeDataString(businessUnitId)}/activitycodes"; | ||
|
|
||
| var response = await _httpClient.PostAsJsonAsync(uri, body, _options, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<ActivityCode>(_options, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<bool> DeleteActivityCodeAsync(string businessUnitId, string activityCodeId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(businessUnitId); | ||
| ArgumentException.ThrowIfNullOrEmpty(activityCodeId); | ||
|
|
||
| var uri = $"api/v2/workforcemanagement/businessunits/{Uri.EscapeDataString(businessUnitId)}/activitycodes/{Uri.EscapeDataString(activityCodeId)}"; | ||
|
|
||
| var response = await _httpClient.DeleteAsync(uri, cancellationToken); | ||
|
|
||
| return response.IsSuccessStatusCode; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<string> GetSchedulesAsync(string businessUnitId, string weekId, bool? includeOnlyPublished = null, string expand = null, CancellationToken cancellationToken = default) | ||
|
||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(businessUnitId); | ||
| ArgumentException.ThrowIfNullOrEmpty(weekId); | ||
|
|
||
| var parameters = new NameValueCollection(); | ||
|
|
||
| if (includeOnlyPublished.HasValue) | ||
| { | ||
| parameters.Add("includeOnlyPublished", UriHelper.ParameterToString(includeOnlyPublished.Value)); | ||
| } | ||
|
|
||
| if (!string.IsNullOrEmpty(expand)) | ||
| { | ||
| parameters.Add("expand", UriHelper.ParameterToString(expand)); | ||
| } | ||
|
|
||
| var uri = UriHelper.GetUri($"api/v2/workforcemanagement/businessunits/{Uri.EscapeDataString(businessUnitId)}/weeks/{Uri.EscapeDataString(weekId)}/schedules", parameters); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadAsStringAsync(cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<string> GetScheduleAsync(string businessUnitId, string weekId, string scheduleId, string expand = null, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(businessUnitId); | ||
| ArgumentException.ThrowIfNullOrEmpty(weekId); | ||
| ArgumentException.ThrowIfNullOrEmpty(scheduleId); | ||
|
|
||
| var parameters = new NameValueCollection(); | ||
|
|
||
| if (!string.IsNullOrEmpty(expand)) | ||
|
||
| { | ||
| parameters.Add("expand", UriHelper.ParameterToString(expand)); | ||
| } | ||
|
|
||
| var uri = UriHelper.GetUri($"api/v2/workforcemanagement/businessunits/{Uri.EscapeDataString(businessUnitId)}/weeks/{Uri.EscapeDataString(weekId)}/schedules/{Uri.EscapeDataString(scheduleId)}", parameters); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadAsStringAsync(cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<bool> DeleteScheduleAsync(string businessUnitId, string weekId, string scheduleId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(businessUnitId); | ||
| ArgumentException.ThrowIfNullOrEmpty(weekId); | ||
| ArgumentException.ThrowIfNullOrEmpty(scheduleId); | ||
|
|
||
| var uri = $"api/v2/workforcemanagement/businessunits/{Uri.EscapeDataString(businessUnitId)}/weeks/{Uri.EscapeDataString(weekId)}/schedules/{Uri.EscapeDataString(scheduleId)}"; | ||
|
|
||
| var response = await _httpClient.DeleteAsync(uri, cancellationToken); | ||
|
|
||
| return response.IsSuccessStatusCode; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<string> GetForecastsAsync(string businessUnitId, string weekDateId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(businessUnitId); | ||
| ArgumentException.ThrowIfNullOrEmpty(weekDateId); | ||
|
|
||
| var uri = $"api/v2/workforcemanagement/businessunits/{Uri.EscapeDataString(businessUnitId)}/weeks/{Uri.EscapeDataString(weekDateId)}/shorttermforecasts"; | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadAsStringAsync(cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<bool> DeleteForecastAsync(string businessUnitId, string weekDateId, string forecastId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(businessUnitId); | ||
| ArgumentException.ThrowIfNullOrEmpty(weekDateId); | ||
| ArgumentException.ThrowIfNullOrEmpty(forecastId); | ||
|
|
||
| var uri = $"api/v2/workforcemanagement/businessunits/{Uri.EscapeDataString(businessUnitId)}/weeks/{Uri.EscapeDataString(weekDateId)}/shorttermforecasts/{Uri.EscapeDataString(forecastId)}"; | ||
|
|
||
| var response = await _httpClient.DeleteAsync(uri, cancellationToken); | ||
|
|
||
| return response.IsSuccessStatusCode; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<string> CreateTimeOffRequestAsync(string managementUnitId, CreateAdminTimeOffRequest body, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(managementUnitId); | ||
| ArgumentNullException.ThrowIfNull(body); | ||
|
|
||
| var uri = $"api/v2/workforcemanagement/managementunits/{Uri.EscapeDataString(managementUnitId)}/timeoffrequests"; | ||
|
|
||
| var response = await _httpClient.PostAsJsonAsync(uri, body, _options, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadAsStringAsync(cancellationToken); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| using PureCloud.Client.Models; | ||
|
|
||
| namespace PureCloud.Client.Contracts; | ||
|
|
||
| /// <summary> | ||
| /// Workforce Management API operations | ||
| /// </summary> | ||
| public interface IWorkforceManagementApi | ||
| { | ||
| /// <summary> | ||
| /// Get business units | ||
| /// </summary> | ||
MikeAlhayek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <param name="feature">The feature to filter by</param> | ||
| /// <param name="divisionId">The division ID to filter by</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>Business unit listing</returns> | ||
| Task<BusinessUnitListing> GetBusinessUnitsAsync(string feature = null, string divisionId = null, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Get a business unit | ||
| /// </summary> | ||
| /// <param name="businessUnitId">The ID of the business unit</param> | ||
| /// <param name="expand">Include to access additional data on the business unit</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>Business unit response</returns> | ||
| Task<BusinessUnitResponse> GetBusinessUnitAsync(string businessUnitId, List<string> expand = null, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Delete a business unit | ||
| /// </summary> | ||
| /// <param name="businessUnitId">The ID of the business unit</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>True if deletion was successful</returns> | ||
| Task<bool> DeleteBusinessUnitAsync(string businessUnitId, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Delete a management unit | ||
| /// </summary> | ||
| /// <param name="managementUnitId">The ID of the management unit</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>True if deletion was successful</returns> | ||
| Task<bool> DeleteManagementUnitAsync(string managementUnitId, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Get activity codes | ||
| /// </summary> | ||
| /// <param name="businessUnitId">The ID of the business unit</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>Activity code container</returns> | ||
| Task<ActivityCodeContainer> GetActivityCodesAsync(string businessUnitId, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Create an activity code | ||
| /// </summary> | ||
| /// <param name="businessUnitId">The ID of the business unit</param> | ||
| /// <param name="body">The activity code request</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>Created activity code</returns> | ||
| Task<ActivityCode> CreateActivityCodeAsync(string businessUnitId, CreateActivityCodeRequest body, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Delete an activity code | ||
| /// </summary> | ||
| /// <param name="businessUnitId">The ID of the business unit</param> | ||
| /// <param name="activityCodeId">The ID of the activity code to delete</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>True if deletion was successful</returns> | ||
| Task<bool> DeleteActivityCodeAsync(string businessUnitId, string activityCodeId, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Get schedules for a week - simplified return type | ||
| /// </summary> | ||
| /// <param name="businessUnitId">The ID of the business unit</param> | ||
| /// <param name="weekId">The week ID</param> | ||
| /// <param name="includeOnlyPublished">Include only published schedules</param> | ||
| /// <param name="expand">Expand parameter</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>Schedules as JSON string</returns> | ||
| Task<string> GetSchedulesAsync(string businessUnitId, string weekId, bool? includeOnlyPublished = null, string expand = null, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Get a schedule - simplified return type | ||
| /// </summary> | ||
| /// <param name="businessUnitId">The ID of the business unit</param> | ||
| /// <param name="weekId">The week ID</param> | ||
| /// <param name="scheduleId">The schedule ID</param> | ||
| /// <param name="expand">Expand parameter</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>Schedule as JSON string</returns> | ||
| Task<string> GetScheduleAsync(string businessUnitId, string weekId, string scheduleId, string expand = null, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Delete a schedule | ||
| /// </summary> | ||
| /// <param name="businessUnitId">The ID of the business unit</param> | ||
| /// <param name="weekId">The week ID</param> | ||
| /// <param name="scheduleId">The schedule ID</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>True if deletion was successful</returns> | ||
| Task<bool> DeleteScheduleAsync(string businessUnitId, string weekId, string scheduleId, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Get short term forecasts - simplified return type | ||
| /// </summary> | ||
| /// <param name="businessUnitId">The ID of the business unit</param> | ||
| /// <param name="weekDateId">The week date ID</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>Forecasts as JSON string</returns> | ||
| Task<string> GetForecastsAsync(string businessUnitId, string weekDateId, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Delete a short term forecast | ||
| /// </summary> | ||
| /// <param name="businessUnitId">The ID of the business unit</param> | ||
| /// <param name="weekDateId">The week date ID</param> | ||
| /// <param name="forecastId">The forecast ID</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>True if deletion was successful</returns> | ||
| Task<bool> DeleteForecastAsync(string businessUnitId, string weekDateId, string forecastId, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Create a time off request | ||
| /// </summary> | ||
| /// <param name="managementUnitId">The ID of the management unit</param> | ||
| /// <param name="body">The time off request</param> | ||
| /// <param name="cancellationToken">Cancellation token</param> | ||
| /// <returns>Created time off request (temporarily simplified as string)</returns> | ||
| Task<string> CreateTimeOffRequestAsync(string managementUnitId, CreateAdminTimeOffRequest body, CancellationToken cancellationToken = default); | ||
| } | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expands should be IEnumerable and it should be renamed to expands. In the foreach loop it would be expand in expands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed - changed expand parameter to expands with IEnumerable<string> type and updated foreach loop pattern. Commit a89a6bc