PureCloud.Client API Migration Guide
Modernize legacy async client methods into /src/PureCloud.Client/Apis/, preserving functionality and aligning with current conventions.
Source & Destination
- From:
/src/PureCloud.Client/OldApis/
- To:
/src/PureCloud.Client/Apis/
- Maintain one‑to‑one file mapping.
Core Guidelines
-
Async‑Only
- Migrate only methods already marked
async.
- Retain
async and add a CancellationToken parameter.
-
Single Representative Method
- Migrate one method per API; omit overloads or variations.
-
Method Naming
- Prefix methods with:
Get…, Create…, Update…, or Delete….
-
Reference Pattern
- Structure & DI match
/src/PureCloud.Client/Apis/FlowsApi.cs.
- Target
- Source:
/src/PureCloud.Client/OldApis/WorkforceManagementApi.cs
- Target:
/src/PureCloud.Client/Apis/WorkforceManagementApi.cs
Code Example: FlowsApi
/// <inheritdoc />
public sealed class FlowsApi : IFlowsApi
{
private readonly HttpClient _httpClient;
private readonly JsonSerializerOptions _options;
public FlowsApi(IHttpClientFactory httpClientFactory, IOptions<PureCloudJsonSerializerOptions> options)
{
_httpClient = httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);
_options = options.Value.JsonSerializerOptions;
}
/// <inheritdoc />
public async Task<FlowResponse[]> GetFlowsAsync(string conversationId, CancellationToken cancellationToken)
{
ArgumentException.ThrowIfNullOrEmpty(nameof(conversationId), conversationId);
var parameters = new NameValueCollection { { "conversationId", conversationId } };
var uri = UriHelper.GetUri("/api/v2/flows", parameters);
var response = await _httpClient.GetAsync(uri, cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<FlowResponse[]>(_options, cancellationToken);
}
}
Infrastructure & URI Handling
HTTP & JSON Helpers
-
GET: await client.GetAsync(uri, cancellationToken)
-
DELETE: await client.DeleteAsync(uri, cancellationToken)
-
POST: await client.PostAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken)
-
PUT: await client.PutAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken)
-
PATCH: await client.PatchAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken)
-
Deserialize:
return await response.Content.ReadFromJsonAsync<T>(_options, cancellationToken);
Code Style & Formatting
- 1 Seal all classes.
- 2 End each file with a single newline.
- 3 Document methods with
/// <inheritdoc /> and a blank line.
- 4 Use
IEnumerable<> instead of List<>.
- 5 Return arrays, never
List<>.
- 6 Single‑line method signatures (no stacked parameters).
- 7 Blank line before each
return.
- 8 Validate inputs with
ArgumentException.ThrowIfNullOrEmpty(...) (blank line after).
- 9 Remove all unnecessary comments.
Model include into solution
- 1 Convert all
partial classes to sealed classes.
- 2 Remove all
IEquatable<> implementations.
- 3 Extract enums into
<Base>.<Descriptor>.cs (e.g., HelloWorld.Status.cs), dropping “Enum”.
- 4 Remove
[JsonPropertyName], constructors, and overrides (ToString(), Equals(), GetHashCode()).
- 5 Replace
List<> properties with IEnumerable<>.
Include Models
- 1 Generate or migrate request/response models under
src/PureCloud.Client/Models/.
- 2 Never rename models—keep original class names.
- 3 Apply Model Cleanup rules.
- 4 Add each model to the
.csproj.
Model Cleanup Verification
After you output all files, include a “✅ Model Cleanup Checklist” section exactly like this:
1 Converted all partial classes to sealed
2 Removed all IEquatable<> implementations
3 Extracted enums into <Base>.<Descriptor>.cs
4 Removed [JsonPropertyName], constructors, and overrides (ToString(), Equals(), GetHashCode())
5 Replaced all List<> properties with IEnumerable<>
6 Only then change the title to completed + Name.
7 Include the model add to PureCloud.Client\Extensions\ServiceCollectionExtensions.cs
8 Include the model add to src\PureCloud.Client\PureCloud.Client.csproj
URL Coverage Validation include a “✅ when completed
- 1 Extract literal URLs from old code.
- 2 Confirm each appears in new methods via
UriHelper.GetUri.
- 3 If missing or altered, insert a
// TODO: Missing URL comment.
- 4 Expected AsyncWithHttpInfo Methods Converted 86 Check ** Importent ** for file WorkforceManagementApi.cs
Completion Summary
After generation, provide a summary that:
- Lists all API and model files created or modified.
- Confirms adherence to Core Guidelines, Code Style, and Model Cleanup rules.
- Verifies URL coverage.
- Notes any special cases or manual interventions.
include a “✅ when completed Include the model add to PureCloud.Client\Extensions\ServiceCollectionExtensions.cs
include a “✅ when completed Include the model add to src\PureCloud.Client\PureCloud.Client.csproj
Do not include extra explanations—output only the final C# files ready to drop into
/src/PureCloud.Client/Apis/ and src/PureCloud.Client/Models/.
Once Finish Change the Title to completed + Name
PureCloud.Client API Migration Guide
Modernize legacy async client methods into
/src/PureCloud.Client/Apis/, preserving functionality and aligning with current conventions.Source & Destination
/src/PureCloud.Client/OldApis//src/PureCloud.Client/Apis/Core Guidelines
Async‑Only
async.asyncand add aCancellationTokenparameter.Single Representative Method
Method Naming
Get…,Create…,Update…, orDelete….Reference Pattern
/src/PureCloud.Client/Apis/FlowsApi.cs./src/PureCloud.Client/OldApis/WorkforceManagementApi.cs/src/PureCloud.Client/Apis/WorkforceManagementApi.csCode Example: FlowsApi
Infrastructure & URI Handling
HttpClient:
URI builder:
Query params: use
NameValueCollection; omit (passnull) when none are required.HTTP & JSON Helpers
GET:
await client.GetAsync(uri, cancellationToken)DELETE:
await client.DeleteAsync(uri, cancellationToken)POST:
await client.PostAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken)PUT:
await client.PutAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken)PATCH:
await client.PatchAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken)Deserialize:
Code Style & Formatting
/// <inheritdoc />and a blank line.IEnumerable<>instead ofList<>.List<>.return.ArgumentException.ThrowIfNullOrEmpty(...)(blank line after).Model include into solution
partialclasses to sealed classes.IEquatable<>implementations.<Base>.<Descriptor>.cs(e.g.,HelloWorld.Status.cs), dropping “Enum”.[JsonPropertyName], constructors, and overrides (ToString(),Equals(),GetHashCode()).List<>properties withIEnumerable<>.Include Models
src/PureCloud.Client/Models/..csproj.Model Cleanup Verification
After you output all files, include a “✅ Model Cleanup Checklist” section exactly like this:
1 Converted all
partialclasses tosealed2 Removed all
IEquatable<>implementations3 Extracted enums into
<Base>.<Descriptor>.cs4 Removed
[JsonPropertyName], constructors, and overrides (ToString(),Equals(),GetHashCode())5 Replaced all
List<>properties withIEnumerable<>6 Only then change the title to
completed + Name.7 Include the model add to PureCloud.Client\Extensions\ServiceCollectionExtensions.cs
8 Include the model add to src\PureCloud.Client\PureCloud.Client.csproj
URL Coverage Validation include a “✅ when completed
UriHelper.GetUri.// TODO: Missing URLcomment.Completion Summary
After generation, provide a summary that:
include a “✅ when completed Include the model add to PureCloud.Client\Extensions\ServiceCollectionExtensions.cs
include a “✅ when completed Include the model add to src\PureCloud.Client\PureCloud.Client.csproj
Do not include extra explanations—output only the final C# files ready to drop into
/src/PureCloud.Client/Apis/andsrc/PureCloud.Client/Models/.Once Finish Change the Title to completed + Name