Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 149 additions & 19 deletions src/PureCloud.Client/Apis/ObjectsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace PureCloud.Client.Apis;
/// <inheritdoc />
public sealed class ObjectsApi : IObjectsApi
{
private readonly HttpClient _httpClient;
private readonly IHttpClientFactory _httpClientFactory;
private readonly PureCloudJsonSerializerOptions _options;

public ObjectsApi(IHttpClientFactory httpClientFactory, IOptions<PureCloudJsonSerializerOptions> options)
{
_httpClient = httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);
_httpClientFactory = httpClientFactory;
_options = options.Value;
}

Expand All @@ -32,17 +32,19 @@ public async Task<AuthzDivision> GetAuthorizationDivisionAsync(string divisionId
parameters.Add("objectCount", UriHelper.ParameterToString(objectCount.Value));
}

var uri = UriHelper.GetUri($"api/v2/authorization/divisions/{divisionId}", parameters);
var uri = UriHelper.GetUri($"api/v2/authorization/divisions/{Uri.EscapeDataString(divisionId)}", parameters);

var response = await _httpClient.GetAsync(uri, cancellationToken);
var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await client.GetAsync(uri, cancellationToken);

response.EnsureSuccessStatusCode();

return await response.Content.ReadFromJsonAsync<AuthzDivision>(_options.JsonSerializerOptions, cancellationToken);
}

/// <inheritdoc />
public async Task<AuthzDivisionEntityListing> GetAuthorizationDivisionsAsync(int? pageSize = null, int? pageNumber = null, string sortBy = null, IEnumerable<string> expand = null, string nextPage = null, string previousPage = null, bool? objectCount = null, IEnumerable<string> id = null, string name = null, CancellationToken cancellationToken = default)
public async Task<AuthzDivisionEntityListing> GetAuthorizationDivisionsAsync(int? pageSize = null, int? pageNumber = null, string sortBy = null, IEnumerable<string> expands = null, string nextPage = null, string previousPage = null, bool? objectCount = null, IEnumerable<string> ids = null, string name = null, CancellationToken cancellationToken = default)
{
var parameters = new NameValueCollection();

Expand All @@ -61,11 +63,11 @@ public async Task<AuthzDivisionEntityListing> GetAuthorizationDivisionsAsync(int
parameters.Add("sortBy", UriHelper.ParameterToString(sortBy));
}

if (expand != null)
if (expands != null)
{
foreach (var item in expand)
foreach (var expand in expands)
{
parameters.Add("expand", UriHelper.ParameterToString(item));
parameters.Add("expand", UriHelper.ParameterToString(expand));
}
}

Expand All @@ -84,11 +86,11 @@ public async Task<AuthzDivisionEntityListing> GetAuthorizationDivisionsAsync(int
parameters.Add("objectCount", UriHelper.ParameterToString(objectCount.Value));
}

if (id != null)
if (ids != null)
{
foreach (var item in id)
foreach (var id in ids)
{
parameters.Add("id", UriHelper.ParameterToString(item));
parameters.Add("id", UriHelper.ParameterToString(id));
}
}

Expand All @@ -99,7 +101,9 @@ public async Task<AuthzDivisionEntityListing> GetAuthorizationDivisionsAsync(int

var uri = UriHelper.GetUri("api/v2/authorization/divisions", parameters);

var response = await _httpClient.GetAsync(uri, cancellationToken);
var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await client.GetAsync(uri, cancellationToken);

response.EnsureSuccessStatusCode();

Expand All @@ -111,9 +115,9 @@ public async Task<AuthzDivision> CreateAuthorizationDivisionAsync(AuthzDivision
{
ArgumentNullException.ThrowIfNull(body);

var uri = UriHelper.GetUri("api/v2/authorization/divisions", null);
var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await _httpClient.PostAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken);
var response = await client.PostAsJsonAsync("api/v2/authorization/divisions", body, _options.JsonSerializerOptions, cancellationToken);

response.EnsureSuccessStatusCode();

Expand All @@ -127,9 +131,9 @@ public async Task<AuthzDivision> UpdateAuthorizationDivisionAsync(string divisio

ArgumentNullException.ThrowIfNull(body);

var uri = UriHelper.GetUri($"api/v2/authorization/divisions/{divisionId}", null);
var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await _httpClient.PutAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken);
var response = await client.PutAsJsonAsync($"api/v2/authorization/divisions/{Uri.EscapeDataString(divisionId)}", body, _options.JsonSerializerOptions, cancellationToken);

response.EnsureSuccessStatusCode();

Expand All @@ -148,10 +152,136 @@ public async Task DeleteAuthorizationDivisionAsync(string divisionId, bool? forc
parameters.Add("force", UriHelper.ParameterToString(force.Value));
}

var uri = UriHelper.GetUri($"api/v2/authorization/divisions/{divisionId}", parameters);
var uri = UriHelper.GetUri($"api/v2/authorization/divisions/{Uri.EscapeDataString(divisionId)}", parameters);

var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await client.DeleteAsync(uri, cancellationToken);

response.EnsureSuccessStatusCode();
Comment thread
MikeAlhayek marked this conversation as resolved.
}

/// <inheritdoc />
public async Task<AuthzDivisionEntityListing> GetAuthorizationDivisionsDeletedAsync(int? pageNumber = null, int? pageSize = null, CancellationToken cancellationToken = default)
{
var parameters = new NameValueCollection();

if (pageNumber.HasValue)
{
parameters.Add("pageNumber", UriHelper.ParameterToString(pageNumber.Value));
}

if (pageSize.HasValue)
{
parameters.Add("pageSize", UriHelper.ParameterToString(pageSize.Value));
}

var uri = UriHelper.GetUri("api/v2/authorization/divisions/deleted", parameters);

var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await client.GetAsync(uri, cancellationToken);

var response = await _httpClient.DeleteAsync(uri, cancellationToken);
response.EnsureSuccessStatusCode();

return await response.Content.ReadFromJsonAsync<AuthzDivisionEntityListing>(_options.JsonSerializerOptions, cancellationToken);
}

/// <inheritdoc />
public async Task<AuthzDivision> GetAuthorizationDivisionsHomeAsync(CancellationToken cancellationToken = default)
{
var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await client.GetAsync("api/v2/authorization/divisions/home", cancellationToken);

response.EnsureSuccessStatusCode();

return await response.Content.ReadFromJsonAsync<AuthzDivision>(_options.JsonSerializerOptions, cancellationToken);
}

/// <inheritdoc />
public async Task<int?> GetAuthorizationDivisionsLimitAsync(CancellationToken cancellationToken = default)
Comment thread
MikeAlhayek marked this conversation as resolved.
{
var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await client.GetAsync("api/v2/authorization/divisions/limit", cancellationToken);

response.EnsureSuccessStatusCode();

return await response.Content.ReadFromJsonAsync<int?>(_options.JsonSerializerOptions, cancellationToken);
}

/// <inheritdoc />
public async Task CreateAuthorizationDivisionObjectsAsync(string divisionId, string objectType, IEnumerable<string> body, CancellationToken cancellationToken = default)
Comment thread
MikeAlhayek marked this conversation as resolved.
{
Comment thread
MikeAlhayek marked this conversation as resolved.
ArgumentException.ThrowIfNullOrEmpty(divisionId);
Comment thread
MikeAlhayek marked this conversation as resolved.
ArgumentException.ThrowIfNullOrEmpty(objectType);
ArgumentNullException.ThrowIfNull(body);

var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await client.PostAsJsonAsync($"api/v2/authorization/divisions/{Uri.EscapeDataString(divisionId)}/objects/{Uri.EscapeDataString(objectType)}", body, _options.JsonSerializerOptions, cancellationToken);

response.EnsureSuccessStatusCode();
}

/// <inheritdoc />
public async Task<AuthzDivisionCursorListing> GetAuthorizationDivisionsQueryAsync(string before = null, string after = null, string pageSize = null, IEnumerable<string> ids = null, string name = null, CancellationToken cancellationToken = default)
{
var parameters = new NameValueCollection();

if (!string.IsNullOrEmpty(before))
{
parameters.Add("before", UriHelper.ParameterToString(before));
}

if (!string.IsNullOrEmpty(after))
{
parameters.Add("after", UriHelper.ParameterToString(after));
}

if (!string.IsNullOrEmpty(pageSize))
{
parameters.Add("pageSize", UriHelper.ParameterToString(pageSize));
}

if (ids != null)
{
foreach (var id in ids)
{
parameters.Add("id", UriHelper.ParameterToString(id));
}
}

if (!string.IsNullOrEmpty(name))
{
parameters.Add("name", UriHelper.ParameterToString(name));
}

var uri = UriHelper.GetUri("api/v2/authorization/divisions/query", parameters);

var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await client.GetAsync(uri, cancellationToken);

response.EnsureSuccessStatusCode();

return await response.Content.ReadFromJsonAsync<AuthzDivisionCursorListing>(_options.JsonSerializerOptions, cancellationToken);
}

/// <inheritdoc />
public async Task<AuthzDivision> PostAuthorizationDivisionRestoreAsync(string divisionId, AuthzDivision body, CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrEmpty(divisionId);

ArgumentNullException.ThrowIfNull(body);

var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);

var response = await client.PostAsJsonAsync($"api/v2/authorization/divisions/{Uri.EscapeDataString(divisionId)}/restore", body, _options.JsonSerializerOptions, cancellationToken);

response.EnsureSuccessStatusCode();

return await response.Content.ReadFromJsonAsync<AuthzDivision>(_options.JsonSerializerOptions, cancellationToken);
}
Comment thread
MikeAlhayek marked this conversation as resolved.
}
}
84 changes: 82 additions & 2 deletions src/PureCloud.Client/Contracts/IObjectsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,105 @@ public interface IObjectsApi
/// <summary>
/// Get an authorization division by ID.
/// </summary>
/// <param name="divisionId">Division ID</param>
/// <param name="objectCount">Get count of objects in this division, defaults to false</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>AuthzDivision</returns>
Task<AuthzDivision> GetAuthorizationDivisionAsync(string divisionId, bool? objectCount = null, CancellationToken cancellationToken = default);

/// <summary>
/// Get a list of authorization divisions.
/// </summary>
Task<AuthzDivisionEntityListing> GetAuthorizationDivisionsAsync(int? pageSize = null, int? pageNumber = null, string sortBy = null, IEnumerable<string> expand = null, string nextPage = null, string previousPage = null, bool? objectCount = null, IEnumerable<string> id = null, string name = null, CancellationToken cancellationToken = default);
/// <param name="pageSize">The total page size requested</param>
/// <param name="pageNumber">The page number requested</param>
/// <param name="sortBy">variable name requested to sort by</param>
/// <param name="expands">variable name requested by expand list</param>
/// <param name="nextPage">next page token</param>
/// <param name="previousPage">Previous page token</param>
/// <param name="objectCount">Include the count of objects contained in the division</param>
/// <param name="ids">Optionally request specific divisions by their IDs</param>
/// <param name="name">Search term to filter by division name</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>AuthzDivisionEntityListing</returns>
Task<AuthzDivisionEntityListing> GetAuthorizationDivisionsAsync(int? pageSize = null, int? pageNumber = null, string sortBy = null, IEnumerable<string> expands = null, string nextPage = null, string previousPage = null, bool? objectCount = null, IEnumerable<string> ids = null, string name = null, CancellationToken cancellationToken = default);

/// <summary>
/// Create a new authorization division.
/// </summary>
/// <param name="body">Division</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>AuthzDivision</returns>
Task<AuthzDivision> CreateAuthorizationDivisionAsync(AuthzDivision body, CancellationToken cancellationToken = default);

/// <summary>
/// Update an authorization division.
/// </summary>
/// <param name="divisionId">Division ID</param>
/// <param name="body">Updated division data</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>AuthzDivision</returns>
Task<AuthzDivision> UpdateAuthorizationDivisionAsync(string divisionId, AuthzDivision body, CancellationToken cancellationToken = default);

/// <summary>
/// Delete an authorization division.
/// </summary>
/// <param name="divisionId">Division ID</param>
/// <param name="force">Force delete this division as well as the grants and objects associated with it</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>Task</returns>
Task DeleteAuthorizationDivisionAsync(string divisionId, bool? force = null, CancellationToken cancellationToken = default);
}

/// <summary>
/// Get a list of soft deleted divisions for the org.
Comment thread
MikeAlhayek marked this conversation as resolved.
/// </summary>
/// <param name="pageNumber">The page number requested</param>
/// <param name="pageSize">The total page size requested</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>AuthzDivisionEntityListing</returns>
Task<AuthzDivisionEntityListing> GetAuthorizationDivisionsDeletedAsync(int? pageNumber = null, int? pageSize = null, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve the home division for the organization.
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>AuthzDivision</returns>
Task<AuthzDivision> GetAuthorizationDivisionsHomeAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Returns the maximum allowed number of divisions.
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>int?</returns>
Task<int?> GetAuthorizationDivisionsLimitAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Assign a list of objects to a division.
/// </summary>
/// <param name="divisionId">Division ID</param>
/// <param name="objectType">The type of the objects. must be one of the valid object types</param>
/// <param name="body">Object Id List</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>Task</returns>
Task CreateAuthorizationDivisionObjectsAsync(string divisionId, string objectType, IEnumerable<string> body, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve a list of all divisions defined for the organization with cursor-based pagination.
/// </summary>
/// <param name="before">The cursor that points to the start of the set of entities that has been returned.</param>
/// <param name="after">The cursor that points to the end of the set of entities that has been returned.</param>
/// <param name="pageSize">Number of entities to return. Maximum of 100.</param>
/// <param name="ids">Optionally request specific divisions by their IDs</param>
/// <param name="name">Search term to filter by division name</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>AuthzDivisionCursorListing</returns>
Task<AuthzDivisionCursorListing> GetAuthorizationDivisionsQueryAsync(string before = null, string after = null, string pageSize = null, IEnumerable<string> ids = null, string name = null, CancellationToken cancellationToken = default);

/// <summary>
/// Recreate a previously deleted division.
/// </summary>
/// <param name="divisionId">Division ID</param>
/// <param name="body">Recreated division data</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>AuthzDivision</returns>
Task<AuthzDivision> PostAuthorizationDivisionRestoreAsync(string divisionId, AuthzDivision body, CancellationToken cancellationToken = default);
Comment thread
MikeAlhayek marked this conversation as resolved.
}
8 changes: 4 additions & 4 deletions src/PureCloud.Client/PureCloud.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4123,10 +4123,10 @@
<Compile Include="Models\ScreenshareState.cs" />
<Compile Include="Models\Script.cs" />
<Compile Include="Models\ScriptEntityListing.cs" />
<Compile Include="Models\ExportScriptRequest.cs" />
<Compile Include="Models\ExportScriptResponse.cs" />
<Compile Include="Models\ImportScriptStatusResponse.cs" />
<Compile Include="Models\PublishScriptRequestData.cs" />
<Compile Include="Models\ExportScriptRequest.cs" />
<Compile Include="Models\ExportScriptResponse.cs" />
<Compile Include="Models\ImportScriptStatusResponse.cs" />
<Compile Include="Models\PublishScriptRequestData.cs" />
<Compile Include="Models\SdkLibrary.cs" />
<Compile Include="Models\Section.cs" />
<Compile Include="Models\SecurityProfile.cs" />
Expand Down