microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Api/Clients/ApiClient.cs
91lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Common.Http; |
| 5 | |
| 6 | namespace Microsoft.Teams.Api.Clients; |
| 7 | |
| 8 | public class ApiClient : Client |
| 9 | { |
| 10 | public virtual string ServiceUrl { get; } |
| 11 | public virtual BotClient Bots { get; } |
| 12 | public virtual ConversationClient Conversations { get; } |
| 13 | public virtual UserClient Users { get; } |
| 14 | public virtual TeamClient Teams { get; } |
| 15 | public virtual MeetingClient Meetings { get; } |
| 16 | |
| 17 | /// <summary> |
| 18 | /// Gets the underlying <see cref="IHttpClient"/> instance used by this <see cref="ApiClient"/> |
| 19 | /// and its sub-clients to perform HTTP requests. |
| 20 | /// </summary> |
| 21 | /// <remarks> |
| 22 | /// This property is provided for advanced scenarios where you need to issue custom HTTP |
| 23 | /// calls that are not yet covered by the strongly-typed clients exposed by <see cref="ApiClient"/>. |
| 24 | /// Prefer using the typed clients (<see cref="Bots"/>, <see cref="Conversations"/>, |
| 25 | /// <see cref="Users"/>, <see cref="Teams"/>, <see cref="Meetings"/>) whenever possible. |
| 26 | /// Relying on this property may couple your code to the current HTTP implementation and |
| 27 | /// could limit future refactoring of the underlying client. |
| 28 | /// </remarks> |
| 29 | public IHttpClient Client { get => base._http; } |
| 30 | |
| 31 | public ApiClient(string serviceUrl, CancellationToken cancellationToken = default) : base(cancellationToken) |
| 32 | { |
| 33 | ServiceUrl = serviceUrl; |
| 34 | Bots = new BotClient(_http, cancellationToken); |
| 35 | Conversations = new ConversationClient(serviceUrl, _http, cancellationToken); |
| 36 | Users = new UserClient(_http, cancellationToken); |
| 37 | Teams = new TeamClient(serviceUrl, _http, cancellationToken); |
| 38 | Meetings = new MeetingClient(serviceUrl, _http, cancellationToken); |
| 39 | } |
| 40 | |
| 41 | public ApiClient(string serviceUrl, IHttpClient client, CancellationToken cancellationToken = default) : base(client, cancellationToken) |
| 42 | { |
| 43 | ServiceUrl = serviceUrl; |
| 44 | Bots = new BotClient(_http, cancellationToken); |
| 45 | Conversations = new ConversationClient(serviceUrl, _http, cancellationToken); |
| 46 | Users = new UserClient(_http, cancellationToken); |
| 47 | Teams = new TeamClient(serviceUrl, _http, cancellationToken); |
| 48 | Meetings = new MeetingClient(serviceUrl, _http, cancellationToken); |
| 49 | } |
| 50 | |
| 51 | public ApiClient(string serviceUrl, IHttpClientOptions options, CancellationToken cancellationToken = default) : base(options, cancellationToken) |
| 52 | { |
| 53 | ServiceUrl = serviceUrl; |
| 54 | Bots = new BotClient(_http, cancellationToken); |
| 55 | Conversations = new ConversationClient(serviceUrl, _http, cancellationToken); |
| 56 | Users = new UserClient(_http, cancellationToken); |
| 57 | Teams = new TeamClient(serviceUrl, _http, cancellationToken); |
| 58 | Meetings = new MeetingClient(serviceUrl, _http, cancellationToken); |
| 59 | } |
| 60 | |
| 61 | public ApiClient(string serviceUrl, IHttpClientFactory factory, CancellationToken cancellationToken = default) : base(factory, cancellationToken) |
| 62 | { |
| 63 | ServiceUrl = serviceUrl; |
| 64 | Bots = new BotClient(_http, cancellationToken); |
| 65 | Conversations = new ConversationClient(serviceUrl, _http, cancellationToken); |
| 66 | Users = new UserClient(_http, cancellationToken); |
| 67 | Teams = new TeamClient(serviceUrl, _http, cancellationToken); |
| 68 | Meetings = new MeetingClient(serviceUrl, _http, cancellationToken); |
| 69 | } |
| 70 | |
| 71 | public ApiClient(ApiClient client) : base() |
| 72 | { |
| 73 | ServiceUrl = client.ServiceUrl; |
| 74 | Bots = client.Bots; |
| 75 | Conversations = client.Conversations; |
| 76 | Users = client.Users; |
| 77 | Teams = client.Teams; |
| 78 | Meetings = client.Meetings; |
| 79 | _cancellationToken = client._cancellationToken; |
| 80 | } |
| 81 | |
| 82 | public ApiClient(ApiClient client, CancellationToken cancellationToken) : base(client._http, cancellationToken) |
| 83 | { |
| 84 | ServiceUrl = client.ServiceUrl; |
| 85 | Bots = new BotClient(_http, cancellationToken); |
| 86 | Conversations = new ConversationClient(ServiceUrl, _http, cancellationToken); |
| 87 | Users = new UserClient(_http, cancellationToken); |
| 88 | Teams = new TeamClient(ServiceUrl, _http, cancellationToken); |
| 89 | Meetings = new MeetingClient(ServiceUrl, _http, cancellationToken); |
| 90 | } |
| 91 | } |