| | | 1 | | using System.Net.Http; |
| | | 2 | | using System.Threading.Tasks; |
| | | 3 | | |
| | | 4 | | namespace Livekit.Server.Sdk.Dotnet |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// A client for the Phone Number service, which searches, purchases and manages the phone |
| | | 8 | | /// numbers of a LiveKit project. Only available in LiveKit Cloud. Every call is signed with |
| | | 9 | | /// the SIP <see cref="SIPGrants.Admin"/> grant. |
| | | 10 | | /// </summary> |
| | | 11 | | public class PhoneNumberServiceClient : BaseService |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Creates the client. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="host">URL of the LiveKit server, <c>http(s)://</c> or <c>ws(s)://</c>; a subpath such as <c>htt |
| | | 17 | | /// <param name="apiKey">API key; the <c>LIVEKIT_API_KEY</c> environment variable when omitted.</param> |
| | | 18 | | /// <param name="apiSecret">API secret; the <c>LIVEKIT_API_SECRET</c> environment variable when omitted.</param> |
| | | 19 | | /// <param name="client">Optional <see cref="HttpClient"/> to send the requests with. The SDK never modifies it, |
| | | 20 | | public PhoneNumberServiceClient( |
| | | 21 | | string host, |
| | | 22 | | string apiKey = null, |
| | | 23 | | string apiSecret = null, |
| | | 24 | | HttpClient client = null |
| | | 25 | | ) |
| | 21 | 26 | | : base(host, apiKey, apiSecret, client) { } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Searches the inventory for phone numbers available to purchase. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="request">Country code (required), and optionally an area code, the maximum number of results (5 |
| | | 32 | | /// <returns>The available phone numbers and the token of the next page.</returns> |
| | | 33 | | public async Task<SearchPhoneNumbersResponse> SearchPhoneNumbers( |
| | | 34 | | SearchPhoneNumbersRequest request |
| | | 35 | | ) |
| | 1 | 36 | | { |
| | 1 | 37 | | return await SendAsync( |
| | 1 | 38 | | Twirp.Routes.PhoneNumberService.SearchPhoneNumbers, |
| | 1 | 39 | | request, |
| | 1 | 40 | | SearchPhoneNumbersResponse.Parser, |
| | 1 | 41 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 42 | | ) |
| | 1 | 43 | | .ConfigureAwait(false); |
| | 1 | 44 | | } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Purchases phone numbers from the inventory for the project. |
| | | 48 | | /// </summary> |
| | | 49 | | /// <param name="request">Phone numbers to purchase, in E.164 format, and optionally the SIP dispatch rule to ap |
| | | 50 | | /// <returns>The purchased phone numbers, with their ID, E.164 format and status.</returns> |
| | | 51 | | public async Task<PurchasePhoneNumberResponse> PurchasePhoneNumber( |
| | | 52 | | PurchasePhoneNumberRequest request |
| | | 53 | | ) |
| | 2 | 54 | | { |
| | 2 | 55 | | return await SendAsync( |
| | 2 | 56 | | Twirp.Routes.PhoneNumberService.PurchasePhoneNumber, |
| | 2 | 57 | | request, |
| | 2 | 58 | | PurchasePhoneNumberResponse.Parser, |
| | 2 | 59 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 2 | 60 | | ) |
| | 2 | 61 | | .ConfigureAwait(false); |
| | 2 | 62 | | } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// Lists the phone numbers of the project. |
| | | 66 | | /// </summary> |
| | | 67 | | /// <param name="request">Optional filters (statuses, SIP dispatch rule), the maximum number of results (50 by d |
| | | 68 | | /// <returns>The phone numbers, the token of the next page, and the total and offline counts.</returns> |
| | | 69 | | public async Task<ListPhoneNumbersResponse> ListPhoneNumbers( |
| | | 70 | | ListPhoneNumbersRequest request |
| | | 71 | | ) |
| | 1 | 72 | | { |
| | 1 | 73 | | return await SendAsync( |
| | 1 | 74 | | Twirp.Routes.PhoneNumberService.ListPhoneNumbers, |
| | 1 | 75 | | request, |
| | 1 | 76 | | ListPhoneNumbersResponse.Parser, |
| | 1 | 77 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 78 | | ) |
| | 1 | 79 | | .ConfigureAwait(false); |
| | 1 | 80 | | } |
| | | 81 | | |
| | | 82 | | /// <summary> |
| | | 83 | | /// Gets a phone number of the project. |
| | | 84 | | /// </summary> |
| | | 85 | | /// <param name="request">The phone number to get, by its ID or in E.164 format.</param> |
| | | 86 | | /// <returns>The phone number.</returns> |
| | | 87 | | public async Task<GetPhoneNumberResponse> GetPhoneNumber(GetPhoneNumberRequest request) |
| | 1 | 88 | | { |
| | 1 | 89 | | return await SendAsync( |
| | 1 | 90 | | Twirp.Routes.PhoneNumberService.GetPhoneNumber, |
| | 1 | 91 | | request, |
| | 1 | 92 | | GetPhoneNumberResponse.Parser, |
| | 1 | 93 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 94 | | ) |
| | 1 | 95 | | .ConfigureAwait(false); |
| | 1 | 96 | | } |
| | | 97 | | |
| | | 98 | | /// <summary> |
| | | 99 | | /// Updates a phone number of the project: its name or the SIP dispatch rule assigned to it. |
| | | 100 | | /// </summary> |
| | | 101 | | /// <param name="request">The phone number to update, by its ID or in E.164 format, and the new values.</param> |
| | | 102 | | /// <returns>The updated phone number.</returns> |
| | | 103 | | public async Task<UpdatePhoneNumberResponse> UpdatePhoneNumber( |
| | | 104 | | UpdatePhoneNumberRequest request |
| | | 105 | | ) |
| | 1 | 106 | | { |
| | 1 | 107 | | return await SendAsync( |
| | 1 | 108 | | Twirp.Routes.PhoneNumberService.UpdatePhoneNumber, |
| | 1 | 109 | | request, |
| | 1 | 110 | | UpdatePhoneNumberResponse.Parser, |
| | 1 | 111 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 112 | | ) |
| | 1 | 113 | | .ConfigureAwait(false); |
| | 1 | 114 | | } |
| | | 115 | | |
| | | 116 | | /// <summary> |
| | | 117 | | /// Releases phone numbers of the project. |
| | | 118 | | /// </summary> |
| | | 119 | | /// <param name="request">The phone numbers to release, by their IDs or in E.164 format.</param> |
| | | 120 | | /// <returns>Empty response.</returns> |
| | | 121 | | public async Task<ReleasePhoneNumbersResponse> ReleasePhoneNumbers( |
| | | 122 | | ReleasePhoneNumbersRequest request |
| | | 123 | | ) |
| | 1 | 124 | | { |
| | 1 | 125 | | return await SendAsync( |
| | 1 | 126 | | Twirp.Routes.PhoneNumberService.ReleasePhoneNumbers, |
| | 1 | 127 | | request, |
| | 1 | 128 | | ReleasePhoneNumbersResponse.Parser, |
| | 1 | 129 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 130 | | ) |
| | 1 | 131 | | .ConfigureAwait(false); |
| | 1 | 132 | | } |
| | | 133 | | } |
| | | 134 | | } |