Esempio n. 1
0
        public async Task <ZsSubscription> CreateAsync(string apiBaseUrl, string authToken, string organizationId, ZsSubscriptionCreate createInput)
        {
            apiBaseUrl.CheckConfigApiBaseUrl();
            authToken.CheckConfigAuthToken();
            organizationId.CheckConfigOrganizationId();

            if (createInput == null)
            {
                throw new ArgumentNullException("createInput");
            }

            //var validationResult = createInput.Validate();
            //if (!string.IsNullOrWhiteSpace(validationResult))
            //{
            //    throw new ArgumentException(validationResult);
            //}

            using (var httpClient = new HttpClient())
            {
                httpClient.Configure(apiBaseUrl, organizationId, authToken);
                var content = new StringContent(
                    JsonConvert.SerializeObject(
                        createInput,
                        Formatting.None,
                        new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                }),
                    Encoding.UTF8,
                    "application/json");
                var response = await httpClient.PostAsync(ApiResources.ZsPostSubscription, content);

                var processResult = await response.ProcessResponse <ZsSubscriptionJson>();

                if (null != processResult.Error)
                {
                    throw processResult.Error;
                }

                return(processResult.Data.Subscription);
            }
        }
Esempio n. 2
0
 public async Task <ZsSubscription> CreateAsync(ZsSubscriptionCreate createInput)
 {
     this.client.Configuration.CheckConfig();
     return(await this.CreateAsync(this.client.Configuration.ApiBaseUrl, this.client.Configuration.AuthToken, this.client.Configuration.OrganizationId, createInput));
 }