Пример #1
0
        public async Task <IAuthedResult <LicenseResponse> > GenerateLicenseAsync(LicenseInformation licenseInformation)
        {
            licenseInformation.GuardAgainstNull();
            licenseInformation.Time.MustBePositive();
            licenseInformation.Level.GuardAgainstRange(-1, 31);
            licenseInformation.Amount.GuardAgainstRange(0, 51);

            using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, "generate/license"))
            {
                requestMessage.Content = new FormUrlEncodedContent(new Dictionary <string, string>
                {
                    { "secret", licenseInformation.ApplicationSecret },
                    { "prefix", licenseInformation.LicensePrefix },
                    { "level", licenseInformation.Level.ToString() },
                    { "time", licenseInformation.Time.ToString() },
                    { "amount", licenseInformation.Amount.ToString() }
                });

                requestMessage.Headers.Add("Session", licenseInformation.Session);

                return(await _requester.SendRequestAsync <LicenseResponse>(requestMessage).ConfigureAwait(false));
            }
        }