コード例 #1
0
 public async Task <ZsHostedPage> CreateSubscriptionAsync(ZsHostedPageCreateSubscriptionInput hostedPageCreateSubscription)
 {
     this.client.Configuration.CheckConfig();
     return(await this.CreateSubscriptionAsync(this.client.Configuration.ApiBaseUrl, this.client.Configuration.AuthToken, this.client.Configuration.OrganizationId, hostedPageCreateSubscription));
 }
コード例 #2
0
        public async Task <ZsHostedPage> CreateSubscriptionAsync(string apiBaseUrl, string authToken, string organizationId, ZsHostedPageCreateSubscriptionInput hostedPageCreateSubscription)
        {
            apiBaseUrl.CheckConfigApiBaseUrl();
            authToken.CheckConfigAuthToken();
            organizationId.CheckConfigOrganizationId();

            var validationResult = hostedPageCreateSubscription.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(
                        hostedPageCreateSubscription,
                        Formatting.None,
                        new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                }),
                    Encoding.UTF8,
                    "application/json");
                var response = await httpClient.PostAsync(ApiResources.ZsPostHostedPageCreateSubscription, content);

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

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

                return(processResult.Data.HostedPage);
            }
        }