/// <summary> /// Get a list of all supported top level domains (TLDs) /// </summary> /// <param name="bearerToken">The Azure bearer token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <returns>List of supported TLDs or empty list</returns> public static async Task <IList <TopLevelDomain> > GetSupportedTopLevelDomains(string bearerToken, Guid subscription) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } RestApiResponse response = await RestApiClient.GET( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/providers/Microsoft.DomainRegistration/topLevelDomains", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <TopLevelDomain>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <TopLevelDomain> >(response.Body).Values); }
/// <summary> /// Get a list of available application stacks /// </summary> /// <param name="bearerToken">Azure Bearer Token</param> /// <param name="operatingSystem">Operating system to fetch the stacks for</param> /// <returns>List of application stacks for the operating system specified, or an empty list</returns> public static async Task <IList <ApplicationStack> > GetApplicationStacks(string bearerToken, OSTypeNamesEnum operatingSystem) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (!Enum.IsDefined(typeof(OSTypeNamesEnum), operatingSystem)) { throw new ArgumentOutOfRangeException(nameof(operatingSystem)); } RestApiResponse response = await RestApiClient.GETWithContinuations <ApplicationStack>( bearerToken, $"https://management.azure.com/providers/Microsoft.Web/availableStacks?osTypeSelected={Enum.GetName(typeof(OSTypeNamesEnum), operatingSystem)}", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <ApplicationStack>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <ApplicationStack> >(response.Body).Values); }
/// <summary> /// List existing App Service Domains /// </summary> /// <param name="bearerToken">The Azure bearer token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="resourceGroupName">(Optional) Name of the Azure resource group the Azure App Service Domains are homed in. /// If not provided (NULL), lists all domains in the subscription</param> /// <returns>List of App Service Domain metadata, or empty list if not found</returns> public static async Task <IList <AppServiceDomain> > List(string bearerToken, Guid subscription, string?resourceGroupName = null) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } StringBuilder requestUri = new StringBuilder(); requestUri.Append($"https://management.azure.com/subscriptions/{subscription:d}"); if (!string.IsNullOrWhiteSpace(resourceGroupName)) { requestUri.Append($"/resourceGroups/{resourceGroupName}"); } requestUri.Append("/providers/Microsoft.DomainRegistration/domains"); RestApiResponse response = await RestApiClient.GETWithContinuations <AppServiceDomain>( bearerToken, requestUri.ToString(), CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <AppServiceDomain>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <AppServiceDomain> >(response.Body).Values); }
/// <summary> /// Create a new website app /// </summary> /// <param name="bearerToken">Azure bearer token</param> /// <param name="subscription">Subscription Guid for authorization</param> /// <param name="resourceGroupName">Name of the resource group the app is to be created in</param> /// <param name="app">The app</param> /// <returns>Metadata about the app in creation, or NULL</returns> /// <remarks> /// Web Apps have **so many** ifs and buts in their configuration that we don't want to have a thousand overloaded /// methods. Instead, let the caller pass in a preconfigured App instance and we just pass it on to the API. /// </remarks> public static async Task <AppServiceWebApp?> CreateOrUpdate(string bearerToken, Guid subscription, string resourceGroupName, AppServiceWebApp app) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(resourceGroupName)) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (app == null) { throw new ArgumentNullException(nameof(app)); } RestApiResponse response = await RestApiClient.PUT( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{app.Name}", CLIENT_API_VERSION, null, app, new int[] { 204 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(null); } return(JsonConvert.DeserializeObject <AppServiceWebApp>(response.Body)); }
/// <summary> /// Delete the web app /// </summary> /// <param name="bearerToken">Azure bearer token</param> /// <param name="appUri">ResourceUri to the web app</param> /// <param name="alsoDeleteMetrics">Set TRUE to also delete the web app metrics</param> /// <param name="alsoDeleteAppServicePlanIfEmpty">Set TRUE to also delete the App Service Plan if there are no more apps left in the plan</param> /// <returns>True if the app was accepted for deletion, false if it failed validation/etc, NULL if there was an exception</returns> public static async Task <bool?> Delete(string bearerToken, ResourceUri appUri, bool alsoDeleteMetrics = false, bool alsoDeleteAppServicePlanIfEmpty = false) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } RestApiResponse response = await RestApiClient.DELETE( bearerToken, $"https://management.azure.com/{appUri.ToAbsoluteAzureRMEndpointUri()}", CLIENT_API_VERSION, new Dictionary <string, string>() { { "deleteMetrics", (alsoDeleteMetrics ? "true" : "false") }, { "deleteEmptyServerFarm", (alsoDeleteAppServicePlanIfEmpty ? "true" : "false") } }, new int[] { 200, 204, 404 } ); if ((!response.IsExpectedSuccess) || response.WasException) { return(null); } return(response.IsExpectedSuccess); }
/// <summary> /// Get an instance of a web app /// </summary> /// <param name="bearerToken">Azure bearer token</param> /// <param name="appServiceUri">Resource Uri to the app service</param> /// <param name="slotName">(Optional) Name of the slot to fetch</param> /// <returns>App service or NULL</returns> public static async Task <AppServiceWebApp?> Get(string bearerToken, ResourceUri appServiceUri, string?slotName = null) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if ((!appServiceUri.IsValid) || (!appServiceUri.Is(ResourceUriCompareLevel.Provider, "Microsoft.Web")) || (!appServiceUri.Is(ResourceUriCompareLevel.Type, "sites"))) { throw new ArgumentException(nameof(appServiceUri)); } string endpoint = string.Empty; if (!string.IsNullOrWhiteSpace(slotName)) { endpoint = $"slots/{slotName}"; } RestApiResponse response = await RestApiClient.GET( bearerToken, appServiceUri.ToAbsoluteAzureRMEndpointUri(endpoint), CLIENT_API_VERSION, null, null, new int[] { 200, 404 } ); if ((!response.IsExpectedSuccess) || (response.HttpStatus == 404) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(null); } return(JsonConvert.DeserializeObject <AppServiceWebApp>(response.Body)); }
/// <summary> /// Stop a web app, or optionally a specific slot of the app /// </summary> /// <param name="bearerToken">Azure bearer token</param> /// <param name="appServiceUri">Resource Uri to the app service</param> /// <param name="slotName">(Optional) Name of the slot to stop -- if unspecified, the entire app is stopped</param> /// <returns>True if the operation was accepted, FALSE if not, NULL if there was a problem</returns> public static async Task <bool?> Stop(string bearerToken, ResourceUri appServiceUri, string?slotName = null) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if ((!appServiceUri.IsValid) || (!appServiceUri.Is(ResourceUriCompareLevel.Provider, "Microsoft.Web")) || (!appServiceUri.Is(ResourceUriCompareLevel.Type, "sites"))) { throw new ArgumentException(nameof(appServiceUri)); } string endpoint = "stop"; if (!string.IsNullOrWhiteSpace(slotName)) { endpoint = $"slots/{slotName}/stop"; } RestApiResponse response = await RestApiClient.POST( bearerToken, appServiceUri.ToAbsoluteAzureRMEndpointUri(endpoint), CLIENT_API_VERSION, null, null, new int[] { 200 } ); if (response.WasException) { return(null); } return(response.IsExpectedSuccess); }
public MarketController(RestApiClient restApiClient, ILoggerFactory logFactory) { _restApiClient = restApiClient; restApiClient.ConfigureHttpRequstMessage = RestApiClientExtensions.ApplyAcceptEncodingSettingGZip; _logFactory = logFactory; _logInfo = _logFactory?.CreateLogger(Assembly.GetExecutingAssembly().GetName().Name); }
/// <summary> /// Rename a subscription /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="id">Guid of the subscription</param> /// <param name="newName">New name for the subscription</param> public static async Task Rename(string bearerToken, Guid id, string newName) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if ((id == Guid.Empty) || (id == default)) { throw new ArgumentNullException(nameof(id)); } if (string.IsNullOrWhiteSpace(newName)) { throw new ArgumentNullException(nameof(newName)); } RestApiResponse response = await RestApiClient.POST( bearerToken, $"https://management.azure.com/subscriptions/{id:d}/providers/Microsoft.Subscription/rename", "2019-03-01-preview", null, new SubscriptionRenameStructure() { SubscriptionName = newName }, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { await Task.FromException(new Exception(response.ExceptionMessage)); } await Task.CompletedTask; }
/// <summary> /// Get a list of all disk images in the subscription /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="subscription">Guid of the subscription</param> /// <param name="resourceGroupName">(Optional) Set only if you wish to filter by resource group</param> /// <returns>List of disk images. Empty list if there are none or there was a problem</returns> public static async Task <List <DiskImage> > List(string bearerToken, Guid subscription, string?resourceGroupName = null) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if ((subscription == Guid.Empty) || (subscription == default)) { throw new ArgumentNullException(nameof(subscription)); } RestApiResponse response = await RestApiClient.GETWithContinuations <DiskImage>( bearerToken, $"https://management.azure.com/subscriptions/{subscription.ToString("d")}{(string.IsNullOrWhiteSpace(resourceGroupName) ? "" : "/resourceGroups/" + resourceGroupName)}/providers/Microsoft.Compute/images", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <DiskImage>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <DiskImage> >(response.Body).Values); }
/// <summary> /// Get all geographic locations (Azure Data Centers) that are accessible to a particular subscription /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="id">Guid of the subscription</param> /// <returns>List of locations. Empty list if there was a problem</returns> public static async Task <List <SubscriptionLocation> > ListLocations(string bearerToken, Guid id) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if ((id == Guid.Empty) || (id == default)) { throw new ArgumentNullException(nameof(id)); } RestApiResponse response = await RestApiClient.GETWithContinuations <SubscriptionLocation>( bearerToken, $"https://management.azure.com/subscriptions/{id:d}/locations", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <SubscriptionLocation>()); } return(JsonConvert.DeserializeObject <List <SubscriptionLocation> >(response.Body)); }
public void TestingGetBeersByName() { RestApiClient api = new RestApiClient(); Beer data = api.getBeerPage(api.key + "&name=Beer"); Assert.AreEqual(data.data[0].name, "Beer"); }
/// <summary> /// Get an existing App Service Domain /// </summary> /// <param name="bearerToken">The Azure bearer token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="resourceGroupName">Name of the Azure resource group the Azure App Service Domain is homed in</param> /// <param name="domainName">App Service Domain name</param> /// <returns>App Service Domain metadata, or NULL if not found</returns> public static async Task <AppServiceDomain?> Get(string bearerToken, Guid subscription, string resourceGroupName, string domainName) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(resourceGroupName)) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (string.IsNullOrWhiteSpace(domainName)) { throw new ArgumentNullException(nameof(domainName)); } RestApiResponse response = await RestApiClient.GET( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/resourceGroups/{resourceGroupName}/providers/Microsoft.DomainRegistration/domains/{domainName}", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(null); } return(JsonConvert.DeserializeObject <AppServiceDomain>(response.Body)); }
public void TestingGetBeersSortOrder() { RestApiClient api = new RestApiClient(); Beer data = api.getBeerPage(api.key + "&order=name&sort=DESC"); Assert.IsNotNull(data); }
public async Task GetAsync_Should_Return_DeserializedObject() { var sampleData = new SampleData() { Owner = "Fatma", SampleCount = 5, CreateDate = TimeProvider.Current.UtcNow }; string stringContent = JsonConvert.SerializeObject(sampleData); var httpMessageHandler = new Mock <HttpMessageHandler>(MockBehavior.Strict); httpMessageHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(stringContent) }) .Verifiable(); HttpClient httpClient = MockData.GetMockHttpClient(httpMessageHandler); var restApiClient = new RestApiClient(httpClient); SampleData statisticResult = await restApiClient.GetAsync <SampleData>("statistic"); httpMessageHandler.Protected() .Verify("SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(message => message.Method == HttpMethod.Get && message.RequestUri.ToString().Contains("statistic")), ItExpr.IsAny <CancellationToken>()); Assert.NotNull(statisticResult); Assert.Equal(sampleData.SampleCount, statisticResult.SampleCount); Assert.Equal(sampleData.CreateDate, statisticResult.CreateDate); Assert.Equal(sampleData.Owner, statisticResult.Owner); }
/// <summary> /// Get certificates associated with the given certificate order /// </summary> /// <param name="bearerToken">The Azure bearer token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="resourceGroupName">Name of the resource group the certificate exists in</param> /// <param name="orderNickname">A nickname for the order, specified during order creation</param> /// <returns>List of certificates or empty list</returns> public static async Task <IList <IssuedCertificate> > GetCertificates(string bearerToken, Guid subscription, string resourceGroupName, string orderNickname) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(resourceGroupName)) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (string.IsNullOrWhiteSpace(orderNickname)) { throw new ArgumentNullException(nameof(orderNickname)); } RestApiResponse response = await RestApiClient.GETWithContinuations <IssuedCertificate>( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{orderNickname}/certificates", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <IssuedCertificate>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <IssuedCertificate> >(response.Body).Values); }
/// <summary> /// Delete a certificate associated with the given certificate order /// </summary> /// <param name="bearerToken">The Azure bearer token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="resourceGroupName">Name of the resource group the certificate exists in</param> /// <param name="orderNickname">A nickname for the order, specified during order creation</param> /// <param name="certificateName">Name of the certificate (usually the same as the order nickname)</param> /// <returns>Certificates or NULL</returns> public static async Task <bool?> DeleteCertificate(string bearerToken, Guid subscription, string resourceGroupName, string orderNickname, string certificateName) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(resourceGroupName)) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (string.IsNullOrWhiteSpace(orderNickname)) { throw new ArgumentNullException(nameof(orderNickname)); } if (string.IsNullOrWhiteSpace(certificateName)) { throw new ArgumentNullException(nameof(certificateName)); } RestApiResponse response = await RestApiClient.DELETE( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/resourceGroups/{resourceGroupName}/providers/Microsoft.CertificateRegistration/certificateOrders/{orderNickname}/certificates/{certificateName}", CLIENT_API_VERSION, null, new int[] { 200, 204 } ); return(response.WasException ? (bool?)null : response.IsExpectedSuccess); }
/// <summary> /// Get the VM sizes available by name of the virtual machine. These are the sizes that particular VM may be resized to. /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="subscription">Subscription Guid</param> /// <param name="resourceGroupName">Resource group the VM resides in</param> /// <param name="virtualMachineName">Name of the virtual machine</param> /// <returns>List of available sizes or empty list</returns> public static async Task <List <VirtualMachineSize> > GetAvailableSizesByVM(string bearerToken, Guid subscription, string resourceGroupName, string virtualMachineName) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(resourceGroupName)) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (string.IsNullOrWhiteSpace(virtualMachineName)) { throw new ArgumentNullException(nameof(virtualMachineName)); } RestApiResponse response = await RestApiClient.GET( bearerToken, $"https://management.azure.com/subscriptions/{subscription.ToString("d")}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{virtualMachineName}/vmSizes", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <VirtualMachineSize>()); } return(JsonConvert.DeserializeObject <List <VirtualMachineSize> >(response.Body)); }
private async Task <HtmlDocument> LoadHtmlDocument(string baseAddress, string requestUri) { try { var document = new HtmlDocument(); using (var restApi = new RestApiClient(baseAddress)) { restApi.SetCustomHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") .SetCustomHeader("Accept-Encoding", "gzip, deflate") .SetCustomHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36") .SetCustomHeader("accept-language", "en-US,en;q=0.9"); var content = await restApi.GetContentAsStringAsync(requestUri); document.LoadHtml(content); } return(document); } catch (Exception e) { Console.WriteLine(e); throw; } }
/// <summary> /// Sets the value of a tag. Tag must already exist (this method does not check for it). /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="subscription">Guid of the subscription</param> /// <param name="tagName">Name of the tag</param> /// <param name="value">Value to set</param> /// <returns>The updated tag. NULL if there was a problem</returns> public static async Task <Tag?> SetValue(string bearerToken, Guid subscription, string tagName, string value) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if ((subscription == Guid.Empty) || (subscription == default)) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(tagName)) { throw new ArgumentNullException(nameof(tagName)); } if (string.IsNullOrWhiteSpace(value)) { throw new ArgumentNullException(nameof(value)); } RestApiResponse response = await RestApiClient.PUT( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/tagNames/{tagName}/{value}", CLIENT_API_VERSION, null, null, new int[] { 200, 201 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(null); } return(JsonConvert.DeserializeObject <Tag>(response.Body)); }
/// <summary> /// Create a tag. This method does not check for existence of the tag. /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="subscription">Guid of the subscription</param> /// <param name="tagName">Name of the tag</param> /// <returns>The created tag. NULL if there was a problem</returns> public static async Task <Tag?> Create(string bearerToken, Guid subscription, string tagName) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if ((subscription == Guid.Empty) || (subscription == default)) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(tagName)) { throw new ArgumentNullException(nameof(tagName)); } if ((tagName.Length > 512) || tagName.StartsWith("microsoft", StringComparison.InvariantCultureIgnoreCase) || tagName.StartsWith("azure", StringComparison.InvariantCultureIgnoreCase) || tagName.StartsWith("windows", StringComparison.InvariantCultureIgnoreCase)) { throw new ArgumentException("tagName must be <= 512 characters and not start with 'microsoft', 'azure' or 'windows'."); } RestApiResponse response = await RestApiClient.PUT( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/tagNames/{tagName}", CLIENT_API_VERSION, null, null, new int[] { 200, 201 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(null); } return(JsonConvert.DeserializeObject <Tag>(response.Body)); }
public Form1() { InitializeComponent(); this.inifile = System.Windows.Forms.Application.StartupPath + "\\keys.ini"; Console.WriteLine(inifile); this.ini = new iniOperate(); this.apiServer = ini.ReadIniData("keys", "apiServer", "", inifile); this.apiKey = ini.ReadIniData("keys", "apiKey", "", inifile); this.secretKey = ini.ReadIniData("keys", "secretKey", "", inifile); this.tradePwd = ini.ReadIniData("keys", "tradePwd", "", inifile); this.txtApiServer.Text = this.apiServer; this.txtApiKey.Text = this.apiKey; this.txtSecretKey.Text = this.secretKey; this.txtTradePwd.Text = this.tradePwd; // this.restClient = new RestApiClient(this.apiKey, this.secretKey, this.tradePwd); if (this.txtApiServer.Text.Equals("")) { MessageBox.Show("Api Server Url Empty. Please setting first!"); } this.restClient.setServerUrl(this.txtApiServer.Text); }
/// <summary> /// Get metadata about a single web app that has been deleted /// </summary> /// <param name="bearerToken">Azure Bearer Token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="locationCode">(Optional) The location code (eg: "westus") where the app was hosted</param> /// <param name="siteId">Numeric Id of the web app</param> /// <returns>Metadata about the deleted web app or NULL</returns> public static async Task <DeletedWebApp?> GetDeletedWebApp(string bearerToken, Guid subscription, string locationCode, int siteId) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(locationCode)) { throw new ArgumentNullException(nameof(locationCode)); } if (siteId < 0) { throw new ArgumentOutOfRangeException(nameof(siteId)); } RestApiResponse response = await RestApiClient.GET( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/providers/Microsoft.Web/locations/{locationCode}/deletedSites/{siteId}", CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(null); } return(JsonConvert.DeserializeObject <DeletedWebApp>(response.Body)); }
/// <summary> /// Delete a domain registration. The domain registration must be available in the specified Azure subscription. /// </summary> /// <param name="bearerToken">The Azure bearer token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="resourceGroupName">Name of the Azure resource group the Azure App Service Domain is homed in</param> /// <param name="domainName">Domain registration to delete</param> /// <param name="forceDelete">If set, deletes immediately. Otherwise will delete after 24 hours</param> /// <returns>True if request was accepted, False if not, NULL if there was an exception</returns> public static async Task <bool?> Delete(string bearerToken, Guid subscription, string resourceGroupName, string domainName, bool forceDelete = false) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(domainName)) { throw new ArgumentNullException(nameof(domainName)); } if (string.IsNullOrWhiteSpace(resourceGroupName)) { throw new ArgumentNullException(nameof(resourceGroupName)); } RestApiResponse response = await RestApiClient.DELETE( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/resourceGroups/{resourceGroupName}/providers/Microsoft.DomainRegistration/domains/{domainName}", CLIENT_API_VERSION, new Dictionary <string, string>() { { "forceHardDeleteDomain", (forceDelete ? "true" : "false") } } , new int[] { 200, 204 } ); return(response.WasException ? (bool?)null : response.IsExpectedSuccess); }
/// <summary> /// 删除数据 /// </summary> /// <param name="theData">删除的数据</param> public async Task <ActionResult> DeleteArticelFile(int attachmentId, string path) { PageActionResult operateResult = new PageActionResult(); int result = 0; if (attachmentId > 0) { result = _attachmentBusiness.Delete(m => m.Id == attachmentId); if (result > 0) { RestApiClient restApiClient = new RestApiClient(Vars.FILESTORE_SITE); await restApiClient.AddAuthorization(Vars.IDENTITYSERVER_SITE + "/connect/token"); operateResult = restApiClient.Post <PageActionResult>("/api/FileHandler/DeleteArticelFile", new { savePath = path }); } } else { RestApiClient restApiClient = new RestApiClient(Vars.FILESTORE_SITE); await restApiClient.AddAuthorization(Vars.IDENTITYSERVER_SITE + "/connect/token"); operateResult = restApiClient.Post <PageActionResult>("/api/FileHandler/DeleteArticelFile", new { savePath = path }); } if (operateResult != null) { if (operateResult.Result == PageActionResultType.Failed) { return(Error(operateResult.Message)); } } return(Success(operateResult.Data)); }
/// <summary> /// Forcibly renew a domain registration (eg: before it is due to be renewed) /// </summary> /// <param name="bearerToken">The Azure bearer token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="resourceGroupName">Name of the Azure resource group the Azure App Service Domain is homed in</param> /// <param name="domainName">Domain registration to renew</param> /// <returns>True if request was accepted, False if not, NULL if there was an exception</returns> public static async Task <bool?> ForceRenew(string bearerToken, Guid subscription, string resourceGroupName, string domainName) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(resourceGroupName)) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (string.IsNullOrWhiteSpace(domainName)) { throw new ArgumentNullException(nameof(domainName)); } RestApiResponse response = await RestApiClient.POST( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/resourceGroups/{resourceGroupName}/providers/Microsoft.DomainRegistration/domains/{domainName}/renew", CLIENT_API_VERSION, null, null, new int[] { 200, 202, 204 } ); return(response.WasException ? (bool?)null : response.IsExpectedSuccess); }
public override void AuthenticateRequest(RestApiClient apiClient, Uri uri, HttpMethod method, Dictionary <string, object> providedParameters, bool auth, ArrayParametersSerialization arraySerialization, HttpMethodParameterPosition parameterPosition, out SortedDictionary <string, object> uriParameters, out SortedDictionary <string, object> bodyParameters, out Dictionary <string, string> headers) { var uriParam = new SortedDictionary <string, object>(); bodyParameters = new(); uriParameters = new(); headers = new(); if (parameterPosition == HttpMethodParameterPosition.InBody && method == HttpMethod.Post) { bodyParameters = new SortedDictionary <string, object>(providedParameters); } if (parameterPosition == HttpMethodParameterPosition.InUri && method == HttpMethod.Get) { uriParam = new SortedDictionary <string, object>(providedParameters); } if (auth) { if (uri.PathAndQuery.Contains("v3")) { headers = AddAuthenticationToHeaders(uri.ToString(), method, providedParameters, auth, parameterPosition, arraySerialization); } else { var uriAuthParam = AddAuthenticationToParameters(uri.ToString(), method, providedParameters, auth, parameterPosition, arraySerialization); foreach (var p in uriAuthParam) { uriParam.Add(p.Key, p.Value); } } } uriParameters = uriParam; }
/// <summary> /// Check if a domain name is available /// </summary> /// <param name="bearerToken">The Azure bearer token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="domainName">Domain name to check for availability. Note that the Azure App Service Domain only supports /// checking and purchase of selected domain TLDs.</param> /// <returns>True if available, False if not, NULL if there was an error.</returns> public static async Task <bool?> IsAvailable(string bearerToken, Guid subscription, string domainName) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } // this will cause validation of the domainName and will throw! AvailabilityRequest request = new AvailabilityRequest(domainName); RestApiResponse response = await RestApiClient.POST( bearerToken, $"https://management.azure.com/subscriptions/{subscription:d}/providers/Microsoft.DomainRegistration/checkDomainAvailability", CLIENT_API_VERSION, null, request, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(null); } AvailabilityResult result = JsonConvert.DeserializeObject <AvailabilityResult>(response.Body); return(result.IsAvailable); }
public void TestingGetBeersByPage() { RestApiClient api = new RestApiClient(); Beer data = api.getBeerPage(api.key + "&p=2"); Assert.IsNotNull(data); }
/// <summary> /// Get a list of web apps that have been deleted /// </summary> /// <param name="bearerToken">Azure Bearer Token</param> /// <param name="subscription">Subscription Id for authorization</param> /// <param name="locationCode">(Optional) The location code (eg: "westus") where the app was hosted</param> /// <returns>List of deleted applications or empty list</returns> public static async Task <IList <DeletedWebApp> > GetDeletedWebApps(string bearerToken, Guid subscription, string?locationCode = null) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } StringBuilder requestUri = new StringBuilder(); requestUri.Append($"https://management.azure.com/subscriptions/{subscription:d}/providers/Microsoft.Web"); if (!string.IsNullOrWhiteSpace(locationCode)) { requestUri.Append($"/locations/{locationCode}"); } requestUri.Append("/deletedSites"); RestApiResponse response = await RestApiClient.GETWithContinuations <DeletedWebAppProperties>( bearerToken, requestUri.ToString(), CLIENT_API_VERSION, null, null, new int[] { 200 } ); if ((!response.IsExpectedSuccess) || response.WasException || string.IsNullOrWhiteSpace(response.Body)) { return(new List <DeletedWebApp>()); } return(JsonConvert.DeserializeObject <ListResultWithContinuations <DeletedWebApp> >(response.Body).Values); }
public CallfireClient(string username, string password) { RestApiClient = new RestApiClient(new HttpBasicAuthenticator(username, password)); _MeApi = new Lazy<MeApi>(() => new MeApi(RestApiClient)); _OrdersApi = new Lazy<OrdersApi>(() => new OrdersApi(RestApiClient)); _BatchesApi = new Lazy<BatchesApi>(() => new BatchesApi(RestApiClient)); _CampaignSoundsApi = new Lazy<CampaignSoundsApi>(() => new CampaignSoundsApi(RestApiClient)); _ContactsApi = new Lazy<ContactsApi>(() => new ContactsApi(RestApiClient)); _ContactListsApi = new Lazy<ContactListsApi>(() => new ContactListsApi(RestApiClient)); _NumbersApi = new Lazy<NumbersApi>(() => new NumbersApi(RestApiClient)); _NumberLeasesApi = new Lazy<NumberLeasesApi>(() => new NumberLeasesApi(RestApiClient)); _SubscriptionsApi = new Lazy<SubscriptionsApi>(() => new SubscriptionsApi(RestApiClient)); _WebhooksApi = new Lazy<WebhooksApi>(() => new WebhooksApi(RestApiClient)); _KeywordsApi = new Lazy<KeywordsApi>(() => new KeywordsApi(RestApiClient)); _KeywordLeasesApi = new Lazy<KeywordLeasesApi>(() => new KeywordLeasesApi(RestApiClient)); _DncApi = new Lazy<DncApi>(() => new DncApi(RestApiClient)); _CallsApi = new Lazy<CallsApi>(() => new CallsApi(RestApiClient)); _TextsApi = new Lazy<TextsApi>(() => new TextsApi(RestApiClient)); _TextAutoRepliesApi = new Lazy<TextAutoRepliesApi>(() => new TextAutoRepliesApi(RestApiClient)); _TextBroadcastsApi = new Lazy<TextBroadcastsApi>(() => new TextBroadcastsApi(RestApiClient)); _CallBroadcastsApi = new Lazy<CallBroadcastsApi>(() => new CallBroadcastsApi(RestApiClient)); _MediaApi = new Lazy<MediaApi>(() => new MediaApi(RestApiClient)); }
internal KeywordLeasesApi(RestApiClient client) { Client = client; }
internal OrdersApi(RestApiClient client) { Client = client; }
internal WebhooksApi(RestApiClient client) { Client = client; }
internal CampaignSoundsApi(RestApiClient client) { Client = client; }
internal CallsApi(RestApiClient client) { Client = client; }
internal MediaApi(RestApiClient client) { Client = client; }
internal SubscriptionsApi(RestApiClient client) { Client = client; }
internal DncApi(RestApiClient client) { Client = client; }
internal TextsApi(RestApiClient client) { Client = client; }
internal NumbersApi(RestApiClient client) { Client = client; }
internal TextAutoRepliesApi(RestApiClient client) { Client = client; }
internal CallBroadcastsApi(RestApiClient client) { Client = client; }
internal BatchesApi(RestApiClient client) { Client = client; }
internal TextBroadcastsApi(RestApiClient client) { Client = client; }