Exemplo n.º 1
0
        public async Task<Webhook> CreateAsync(string shopUrl, string accessToken, string address, WebhookTopic topic, WebhookFormat format = WebhookFormat.Json)
        {
            shopUrl.PerCallShopUrlContract();
            accessToken.PerCallAccessTokenContract();

            using (var httpClient = new HttpClient())
            {
                httpClient.Configure(shopUrl, accessToken);
                var webhookCreate = new WebhookCreateWrapJson
                {
                    Webhook = new WebhookCreateJson
                    {
                        Topic = topic.Convert(),
                        Address = address,
                        Format = format.ToString().ToLowerInvariant()
                    }
                };
                var content = new StringContent(JsonConvert.SerializeObject(webhookCreate), Encoding.UTF8, "application/json");
                var response = await httpClient.PostAsync(ApiRequestResources.PostWebhookCreate, content);
                if (!response.IsSuccessStatusCode)
                {
                    return null;
                }

                var rawResponseContent = await response.Content.ReadAsStringAsync();
                var webhookJson = JsonConvert.DeserializeObject<WebhookJson>(rawResponseContent);
                return webhookJson.Webhook;
            }
        }
Exemplo n.º 2
0
 public async Task<Webhook> CreateAsync(string address, WebhookTopic topic, WebhookFormat format = WebhookFormat.Json)
 {
     this.client.Configuration.SingleShopContract();
     return await this.CreateAsync(this.client.Configuration.ShopDomain, this.client.Configuration.AccessToken, address, topic, format);
 }