|
| 1 | +// -------------------------------------------------------------------------------------------------------------------- |
| 2 | +// <copyright company="Aspose Pty Ltd" file="LicenseApi.cs"> |
| 3 | +// Copyright (c) 2003-2021 Aspose Pty Ltd |
| 4 | +// </copyright> |
| 5 | +// <summary> |
| 6 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +// of this software and associated documentation files (the "Software"), to deal |
| 8 | +// in the Software without restriction, including without limitation the rights |
| 9 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +// copies of the Software, and to permit persons to whom the Software is |
| 11 | +// furnished to do so, subject to the following conditions: |
| 12 | +// |
| 13 | +// The above copyright notice and this permission notice shall be included in all |
| 14 | +// copies or substantial portions of the Software. |
| 15 | +// |
| 16 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +// SOFTWARE. |
| 23 | +// </summary> |
| 24 | +// -------------------------------------------------------------------------------------------------------------------- |
| 25 | + |
| 26 | +namespace GroupDocs.Conversion.Cloud.Sdk.Api |
| 27 | +{ |
| 28 | + using System.IO; |
| 29 | + using System.Collections.Generic; |
| 30 | + using System.Text.RegularExpressions; |
| 31 | + using GroupDocs.Conversion.Cloud.Sdk.Client; |
| 32 | + using GroupDocs.Conversion.Cloud.Sdk.Client.RequestHandlers; |
| 33 | + using GroupDocs.Conversion.Cloud.Sdk.Model; |
| 34 | + using GroupDocs.Conversion.Cloud.Sdk.Model.Requests; |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// GroupDocs.Conversion Cloud API. |
| 38 | + /// </summary> |
| 39 | + public class LicenseApi |
| 40 | + { |
| 41 | + private readonly ApiInvoker apiInvoker; |
| 42 | + private readonly Configuration configuration; |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Initializes a new instance of the <see cref="LicenseApi"/> class. |
| 46 | + /// </summary> |
| 47 | + /// <param name="appSid">Application identifier (App SID)</param> |
| 48 | + /// <param name="appKey">Application private key (App Key)</param> |
| 49 | + public LicenseApi(string appSid, string appKey) |
| 50 | + : this(new Configuration(appSid, appKey)) |
| 51 | + { |
| 52 | + } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Initializes a new instance of the <see cref="LicenseApi"/> class. |
| 56 | + /// </summary> |
| 57 | + /// <param name="configuration">Configuration settings</param> |
| 58 | + public LicenseApi(Configuration configuration) |
| 59 | + { |
| 60 | + this.configuration = configuration; |
| 61 | + |
| 62 | + var requestHandlers = new List<IRequestHandler>(); |
| 63 | + requestHandlers.Add(new AuthRequestHandler(this.configuration)); |
| 64 | + requestHandlers.Add(new DebugLogRequestHandler(this.configuration)); |
| 65 | + requestHandlers.Add(new ApiExceptionRequestHandler()); |
| 66 | + this.apiInvoker = new ApiInvoker(requestHandlers, this.configuration.Timeout); |
| 67 | + } |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Get license consumption |
| 71 | + /// </summary> |
| 72 | + /// <returns><see cref="ConsumptionResult"/></returns> |
| 73 | + public ConsumptionResult GetConsumptionCredit() |
| 74 | + { |
| 75 | + // create path and map variables |
| 76 | + var resourcePath = this.configuration.GetServerUrl() + "/conversion/consumption"; |
| 77 | + resourcePath = Regex |
| 78 | + .Replace(resourcePath, "\\*", string.Empty) |
| 79 | + .Replace("&", "&") |
| 80 | + .Replace("/?", "?"); |
| 81 | + |
| 82 | + var response = this.apiInvoker.InvokeApi( |
| 83 | + resourcePath, |
| 84 | + "GET", |
| 85 | + null, |
| 86 | + null, |
| 87 | + null); |
| 88 | + |
| 89 | + if (response != null) |
| 90 | + { |
| 91 | + return (ConsumptionResult)SerializationHelper.Deserialize(response, typeof(ConsumptionResult)); |
| 92 | + } |
| 93 | + |
| 94 | + return null; |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments