|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using System.Threading; |
| 7 | +using Azure.Communication.Pipeline; |
| 8 | +using Azure.Core; |
| 9 | +using Azure.Core.Pipeline; |
| 10 | + |
| 11 | +namespace Azure.Communication.Messages |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// The Azure Communication Services Conversation Adminstration client. |
| 15 | + /// </summary> |
| 16 | + |
| 17 | + public partial class ConversationAdministrationClient |
| 18 | + { |
| 19 | + #region public constructors |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Initializes a new instance of <see cref="ConversationAdministrationClient"/>. |
| 23 | + /// </summary> |
| 24 | + /// <param name="connectionString">Connection string acquired from the Azure Communication Services resource.</param> |
| 25 | + public ConversationAdministrationClient(string connectionString) |
| 26 | + : this( |
| 27 | + ConnectionString.Parse(Argument.CheckNotNullOrEmpty(connectionString, nameof(connectionString))), |
| 28 | + new CommunicationMessagesClientOptions()) |
| 29 | + { |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> Initializes a new instance of <see cref="ConversationAdministrationClient"/>.</summary> |
| 33 | + /// <param name="connectionString">Connection string acquired from the Azure Communication Services resource.</param> |
| 34 | + /// <param name="options">Client options exposing <see cref="ClientOptions.Diagnostics"/>, <see cref="ClientOptions.Retry"/>, <see cref="ClientOptions.Transport"/>, etc.</param> |
| 35 | + public ConversationAdministrationClient(string connectionString, CommunicationMessagesClientOptions options) |
| 36 | + : this( |
| 37 | + ConnectionString.Parse(Argument.CheckNotNullOrEmpty(connectionString, nameof(connectionString))), |
| 38 | + options ?? new CommunicationMessagesClientOptions()) |
| 39 | + { |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> Initializes a new instance of <see cref="ConversationAdministrationClient"/>.</summary> |
| 43 | + /// <param name="endpoint">The URI of the Azure Communication Services resource.</param> |
| 44 | + /// <param name="credential">The <see cref="AzureKeyCredential"/> used to authenticate requests.</param> |
| 45 | + /// <param name="options">Client options exposing <see cref="ClientOptions.Diagnostics"/>, <see cref="ClientOptions.Retry"/>, <see cref="ClientOptions.Transport"/>, etc.</param> |
| 46 | + public ConversationAdministrationClient(Uri endpoint, AzureKeyCredential credential, CommunicationMessagesClientOptions options = default) |
| 47 | + : this( |
| 48 | + Argument.CheckNotNull(endpoint, nameof(endpoint)).AbsoluteUri, |
| 49 | + Argument.CheckNotNull(credential, nameof(credential)), |
| 50 | + options ?? new CommunicationMessagesClientOptions()) |
| 51 | + { |
| 52 | + _keyCredential = credential; |
| 53 | + } |
| 54 | + |
| 55 | + /// <summary> Initializes a new instance of ConversationManagementClient. </summary> |
| 56 | + /// <param name="endpoint"> The communication resource, for example https://my-resource.communication.azure.com. </param> |
| 57 | + /// <param name="credential"> A credential used to authenticate to an Azure Service. </param> |
| 58 | + /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> or <paramref name="credential"/> is null. </exception> |
| 59 | + public ConversationAdministrationClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new CommunicationMessagesClientOptions()) |
| 60 | + { |
| 61 | + } |
| 62 | + |
| 63 | + /// <summary> Initializes a new instance of ConversationManagementClient. </summary> |
| 64 | + /// <param name="endpoint"> The communication resource, for example https://my-resource.communication.azure.com. </param> |
| 65 | + /// <param name="credential"> A credential used to authenticate to an Azure Service. </param> |
| 66 | + /// <param name="options"> The options for configuring the client. </param> |
| 67 | + /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> or <paramref name="credential"/> is null. </exception> |
| 68 | + public ConversationAdministrationClient(Uri endpoint, TokenCredential credential, CommunicationMessagesClientOptions options) |
| 69 | + { |
| 70 | + Argument.AssertNotNull(endpoint, nameof(endpoint)); |
| 71 | + Argument.AssertNotNull(credential, nameof(credential)); |
| 72 | + options ??= new CommunicationMessagesClientOptions(); |
| 73 | + |
| 74 | + ClientDiagnostics = new ClientDiagnostics(options, true); |
| 75 | + _tokenCredential = credential; |
| 76 | + _pipeline = HttpPipelineBuilder.Build(options, Array.Empty<HttpPipelinePolicy>(), new HttpPipelinePolicy[] { new BearerTokenAuthenticationPolicy(_tokenCredential, AuthorizationScopes) }, new ResponseClassifier()); |
| 77 | + _endpoint = endpoint; |
| 78 | + _apiVersion = options.Version; |
| 79 | + } |
| 80 | + |
| 81 | + #endregion |
| 82 | + |
| 83 | + #region private constructors |
| 84 | + private ConversationAdministrationClient(ConnectionString connectionString, CommunicationMessagesClientOptions options) |
| 85 | + : this(new Uri(connectionString.GetRequired("endpoint")), options.BuildHttpPipeline(connectionString), options) |
| 86 | + { } |
| 87 | + |
| 88 | + private ConversationAdministrationClient(string endpoint, AzureKeyCredential keyCredential, CommunicationMessagesClientOptions options) |
| 89 | + : this(new Uri(endpoint), options.BuildHttpPipeline(keyCredential), options) |
| 90 | + { } |
| 91 | + |
| 92 | + private ConversationAdministrationClient(Uri endpoint, HttpPipeline httpPipeline, CommunicationMessagesClientOptions options) |
| 93 | + { |
| 94 | + ClientDiagnostics = new ClientDiagnostics(options); |
| 95 | + _pipeline = httpPipeline; |
| 96 | + _endpoint = endpoint; |
| 97 | + _apiVersion = options.Version; |
| 98 | + } |
| 99 | + |
| 100 | + #endregion |
| 101 | + |
| 102 | + /// <summary> Initializes a new instance of ConversationManagementClient. </summary> |
| 103 | + /// <param name="endpoint"> The communication resource, for example https://my-resource.communication.azure.com. </param> |
| 104 | + /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> is null. </exception> |
| 105 | + internal ConversationAdministrationClient(Uri endpoint) : this(endpoint, new CommunicationMessagesClientOptions()) |
| 106 | + { |
| 107 | + } |
| 108 | + |
| 109 | + /// <summary> Initializes a new instance of ConversationManagementClient. </summary> |
| 110 | + /// <param name="endpoint"> The communication resource, for example https://my-resource.communication.azure.com. </param> |
| 111 | + /// <param name="options"> The options for configuring the client. </param> |
| 112 | + /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> is null. </exception> |
| 113 | + internal ConversationAdministrationClient(Uri endpoint, CommunicationMessagesClientOptions options) |
| 114 | + { |
| 115 | + Argument.AssertNotNull(endpoint, nameof(endpoint)); |
| 116 | + options ??= new CommunicationMessagesClientOptions(); |
| 117 | + |
| 118 | + ClientDiagnostics = new ClientDiagnostics(options, true); |
| 119 | + _pipeline = HttpPipelineBuilder.Build(options, Array.Empty<HttpPipelinePolicy>(), Array.Empty<HttpPipelinePolicy>(), new ResponseClassifier()); |
| 120 | + _endpoint = endpoint; |
| 121 | + _apiVersion = options.Version; |
| 122 | + } |
| 123 | + |
| 124 | + /// <summary>Initializes a new instance of <see cref="ConversationAdministrationClient"/> for mocking.</summary> |
| 125 | + protected ConversationAdministrationClient() |
| 126 | + { |
| 127 | + ClientDiagnostics = null!; |
| 128 | + } |
| 129 | + } |
| 130 | +} |
0 commit comments