-
Notifications
You must be signed in to change notification settings - Fork 0
Ready for Review WebDeploymentsApi #110
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 5 commits
a8161f7
1baa3c8
2adb5ad
2456cab
3d7e5d8
f025e45
427564a
616296b
e813682
5fd5856
663ac54
ae8d512
fa2ebca
9d637e3
9b4a0da
a0e18e6
2e84b67
aae698b
17d8b57
891a3ca
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,353 @@ | ||
| using System.Collections.Specialized; | ||
| using System.Net.Http.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 WebDeploymentsApi : IWebDeploymentsApi | ||
| { | ||
| private readonly HttpClient _httpClient; | ||
| private readonly PureCloudJsonSerializerOptions _options; | ||
|
|
||
| public WebDeploymentsApi(IHttpClientFactory httpClientFactory, IOptions<PureCloudJsonSerializerOptions> options) | ||
| { | ||
| _httpClient = httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName); | ||
| _options = options.Value; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task DeleteWebdeploymentsConfigurationAsync(string configurationId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(configurationId); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/configurations/{configurationId}", null); | ||
|
|
||
| var response = await _httpClient.DeleteAsync(uri, cancellationToken); | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task DeleteWebdeploymentsDeploymentAsync(string deploymentId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(deploymentId); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/deployments/{deploymentId}", null); | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var response = await _httpClient.DeleteAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> DeleteWebdeploymentsDeploymentCobrowseSessionIdAsync(string deploymentId, string sessionId, CancellationToken cancellationToken = default) | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(deploymentId); | ||
| ArgumentException.ThrowIfNullOrEmpty(sessionId); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/deployments/{deploymentId}/cobrowse/{sessionId}", null); | ||
|
|
||
| var response = await _httpClient.DeleteAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task DeleteWebdeploymentsTokenRevokeAsync(string xJourneySessionId = null, string xJourneySessionType = null, CancellationToken cancellationToken = default) | ||
| { | ||
| var uri = UriHelper.GetUri("/api/v2/webdeployments/token/revoke", null); | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| using var request = new HttpRequestMessage(HttpMethod.Delete, uri); | ||
|
|
||
|
||
| if (!string.IsNullOrEmpty(xJourneySessionId)) | ||
| { | ||
| request.Headers.Add("X-Journey-Session-Id", xJourneySessionId); | ||
| } | ||
|
|
||
| if (!string.IsNullOrEmpty(xJourneySessionType)) | ||
| { | ||
| request.Headers.Add("X-Journey-Session-Type", xJourneySessionType); | ||
| } | ||
|
|
||
| var response = await _httpClient.SendAsync(request, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> GetWebdeploymentsConfigurationVersionAsync(string configurationId, string versionId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(configurationId); | ||
| ArgumentException.ThrowIfNullOrEmpty(versionId); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/configurations/{configurationId}/versions/{versionId}", null); | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> GetWebdeploymentsConfigurationVersionsAsync(string configurationId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(configurationId); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/configurations/{configurationId}/versions", null); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> GetWebdeploymentsConfigurationVersionsDraftAsync(string configurationId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(configurationId); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/configurations/{configurationId}/versions/draft", null); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> GetWebdeploymentsConfigurationsAsync(bool? showOnlyPublished = null, CancellationToken cancellationToken = default) | ||
| { | ||
| var parameters = new NameValueCollection(); | ||
|
|
||
| if (showOnlyPublished.HasValue) | ||
| { | ||
| parameters.Add("showOnlyPublished", showOnlyPublished.Value.ToString().ToLowerInvariant()); | ||
|
||
| } | ||
|
|
||
| var uri = UriHelper.GetUri("/api/v2/webdeployments/configurations", parameters); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> GetWebdeploymentsDeploymentAsync(string deploymentId, IEnumerable<string> expand = null, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(deploymentId); | ||
|
|
||
| var parameters = new NameValueCollection(); | ||
|
|
||
| if (expand != null) | ||
| { | ||
| parameters.Add("expand", string.Join(",", expand)); | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/deployments/{deploymentId}", parameters); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<CobrowseWebMessagingSession> GetWebdeploymentsDeploymentCobrowseSessionIdAsync(string deploymentId, string sessionId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(deploymentId); | ||
| ArgumentException.ThrowIfNullOrEmpty(sessionId); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/deployments/{deploymentId}/cobrowse/{sessionId}", null); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<CobrowseWebMessagingSession>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> GetWebdeploymentsDeploymentConfigurationsAsync(string deploymentId, string type = null, IEnumerable<string> expand = null, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(deploymentId); | ||
|
|
||
| var parameters = new NameValueCollection(); | ||
|
|
||
| if (!string.IsNullOrEmpty(type)) | ||
| { | ||
| parameters.Add("type", type); | ||
| } | ||
|
|
||
| if (expand != null) | ||
| { | ||
| parameters.Add("expand", string.Join(",", expand)); | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/deployments/{deploymentId}/configurations", parameters); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<IdentityResolutionConfig> GetWebdeploymentsDeploymentIdentityresolutionAsync(string deploymentId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(deploymentId); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/deployments/{deploymentId}/identityresolution", null); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<IdentityResolutionConfig>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> GetWebdeploymentsDeploymentsAsync(IEnumerable<string> expand = null, CancellationToken cancellationToken = default) | ||
| { | ||
| var parameters = new NameValueCollection(); | ||
|
|
||
| if (expand != null) | ||
MikeAlhayek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| parameters.Add("expand", string.Join(",", expand)); | ||
| } | ||
|
|
||
| var uri = UriHelper.GetUri("/api/v2/webdeployments/deployments", parameters); | ||
|
|
||
| var response = await _httpClient.GetAsync(uri, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> CreateWebdeploymentsConfigurationVersionsDraftPublishAsync(string configurationId, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(configurationId); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/configurations/{configurationId}/versions/draft/publish", null); | ||
|
|
||
| var response = await _httpClient.PostAsync(uri, null, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> CreateWebdeploymentsConfigurationsAsync(object configurationVersion, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(configurationVersion); | ||
|
|
||
| var uri = UriHelper.GetUri("/api/v2/webdeployments/configurations", null); | ||
|
|
||
| var response = await _httpClient.PostAsJsonAsync(uri, configurationVersion, _options.JsonSerializerOptions, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> CreateWebdeploymentsDeploymentsAsync(object deployment, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(deployment); | ||
|
|
||
| var uri = UriHelper.GetUri("/api/v2/webdeployments/deployments", null); | ||
|
|
||
| var response = await _httpClient.PostAsJsonAsync(uri, deployment, _options.JsonSerializerOptions, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<WebDeploymentsAuthorizationResponse> CreateWebdeploymentsTokenOauthcodegrantjwtexchangeAsync(WebDeploymentsOAuthExchangeRequest body, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(body); | ||
|
|
||
| var uri = UriHelper.GetUri("/api/v2/webdeployments/token/oauthcodegrantjwtexchange", null); | ||
|
|
||
| var response = await _httpClient.PostAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<WebDeploymentsAuthorizationResponse>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<SignedData> CreateWebdeploymentsTokenRefreshAsync(WebDeploymentsRefreshJWTRequest body = null, CancellationToken cancellationToken = default) | ||
| { | ||
| var uri = UriHelper.GetUri("/api/v2/webdeployments/token/refresh", null); | ||
|
|
||
| var response = await _httpClient.PostAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<SignedData>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> UpdateWebdeploymentsConfigurationVersionsDraftAsync(string configurationId, object configurationVersion, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(configurationId); | ||
| ArgumentNullException.ThrowIfNull(configurationVersion); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/configurations/{configurationId}/versions/draft", null); | ||
|
|
||
| var response = await _httpClient.PutAsJsonAsync(uri, configurationVersion, _options.JsonSerializerOptions, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<object> UpdateWebdeploymentsDeploymentAsync(string deploymentId, object deployment, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(deploymentId); | ||
| ArgumentNullException.ThrowIfNull(deployment); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/deployments/{deploymentId}", null); | ||
|
|
||
| var response = await _httpClient.PutAsJsonAsync(uri, deployment, _options.JsonSerializerOptions, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<object>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<IdentityResolutionConfig> UpdateWebdeploymentsDeploymentIdentityresolutionAsync(string deploymentId, IdentityResolutionConfig body, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(deploymentId); | ||
| ArgumentNullException.ThrowIfNull(body); | ||
|
|
||
| var uri = UriHelper.GetUri($"/api/v2/webdeployments/deployments/{deploymentId}/identityresolution", null); | ||
|
|
||
| var response = await _httpClient.PutAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken); | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<IdentityResolutionConfig>(_options.JsonSerializerOptions, cancellationToken); | ||
| } | ||
| } | ||
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.
Keep a global copy of the factory and create instance is every method instead
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 from storing HttpClient instance to storing IHttpClientFactory and creating client in each method following the FlowsApi pattern. Commit a0e18e6