Skip to content

JT - Migrate OutboundApi.cs #133

@JackTelford

Description

@JackTelford

PureCloud.Client API Migration Guide

Modernize legacy async client methods into /src/PureCloud.Client/Apis/, preserving functionality and aligning with current conventions.

IMPORTANT Provide a complete, full-expanded migration of async methods

Methods

  • ExpectedCount: 168 ← set this to the total AsyncWithHttpInfo methods you expect in the source file

Core Guidelines

  1. Async‑Only

    • Migrate only methods already marked async. Example: AsyncWithHttpInfo
    • Retain async and add a CancellationToken parameter.
  2. Single Representative Method

    • Migrate one method per API; omit overloads or variations.
  3. Method Naming

    • Prefix methods with: Get…, Create…, Update…, or Delete….
  4. Reference Pattern

    • Structure & DI match /src/PureCloud.Client/Apis/FlowsApi.cs.
    • Target
      • Source: /src/PureCloud.Client/OldApis/OutboundApi.cs
      • Target: /src/PureCloud.Client/Apis/OutboundApi.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<FlowActivityResponse> CreateAnalyticsFlowsActivityQueryAsync(FlowActivityQuery body, int? pageSize = null, int? pageNumber = null, CancellationToken cancellationToken = default)
    {
        ArgumentNullException.ThrowIfNull(body);

        var parameters = new NameValueCollection();

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

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

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

        var uri = UriHelper.GetUri($"api/v2/analytics/flows/activity/query", parameters);

        var response = await client.PostAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken);

        response.EnsureSuccessStatusCode();

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

Infrastructure & URI Handling

  • HttpClient:

    var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);
  • URI builder:

    var uri = UriHelper.GetUri("api/v2/webchat/settings", Parameters);
  • Query params:
    use NameValueCollection;.
    If no parameters then do not use UriHelper

All Delete Methods should return a Bool

add this as a Parameters when needed Uri.EscapeDataString()

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.
  • 10 always add a new line before file End ** Importent

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 ** Importent **
  • 5 Verify that Expected AsyncWithHttpInfo Methods Converted ** Importent **

Completion Summary

After generation, provide a summary that:

  1. Lists all API and model files created or modified.
  2. Confirms adherence to Core Guidelines, Code Style, and Model Cleanup rules.
  3. Verifies URL coverage.
  4. 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/.


** Importent Validation Just before Completetion run an audit comparing these methods to the methods in the old code. It's important to ensure we migrate every endpoint and also ensure the parameters validation is the same as the old code.


* Naming: 1 * Any parameter that is a collection should use plural. Expand to expands. Also in the foreach, name the variable for the current item the single version of the variable. For example expand in expands. 2 * don't glue multiple value using string, instead add multiple values to the parameters collection. Collection parameters should always be in a plural form. In a foresch the variable should always be the singular form of the collection. Don't add new line between null checks. Always using the ParamterString helper to convert values before adding them into the parameters collection. 3 * Also just do null check without calling Any()

Once Finish Change the Title to completed + Name

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions