public async Task<IList<Webhook>> GetAllAsync( string address = "", DateTime createdBefore = default(DateTime), DateTime createdAfter = default(DateTime), WebhookField fields = WebhookField.None, int limit = 50, int page = 1, int idGreaterThan = 0, WebhookTopic topic = WebhookTopic.None, DateTime updatedBefore = default(DateTime), DateTime updatedAfter = default(DateTime)) { this.client.Configuration.SingleShopContract(); return await this.GetAllAsync(this.client.Configuration.ShopDomain, this.client.Configuration.AccessToken, address, createdBefore, createdAfter, fields, limit, page, idGreaterThan, topic, updatedBefore, updatedAfter); }
public async Task <IList <Webhook> > GetAllAsync( string address = "", DateTime createdBefore = default(DateTime), DateTime createdAfter = default(DateTime), WebhookField fields = WebhookField.None, int limit = 50, int page = 1, int idGreaterThan = 0, WebhookTopic topic = WebhookTopic.None, DateTime updatedBefore = default(DateTime), DateTime updatedAfter = default(DateTime)) { this.client.Configuration.SingleShopContract(); return(await this.GetAllAsync(this.client.Configuration.ShopDomain, this.client.Configuration.AccessToken, address, createdBefore, createdAfter, fields, limit, page, idGreaterThan, topic, updatedBefore, updatedAfter)); }
public async Task<IList<Webhook>> GetAllAsync( string shopUrl, string accessToken, string address = "", DateTime createdBefore = default(DateTime), DateTime createdAfter = default(DateTime), WebhookField fields = WebhookField.None, int limit = 50, int page = 1, int idGreaterThan = 0, WebhookTopic topic = WebhookTopic.None, DateTime updatedBefore = default(DateTime), DateTime updatedAfter = default(DateTime)) { //// Default contracts shopUrl.PerCallShopUrlContract(); accessToken.PerCallAccessTokenContract(); //// Optional parameter validation if (!string.IsNullOrWhiteSpace(address) && !address.IsValidUrlAddress()) { throw new ArgumentException("Address parameter is not a well formed URL"); } if (250 < limit) { throw new ArgumentException("Limit value cannot be more than 250, default is 50 if not specified"); } if (0 == page) { throw new ArgumentException("Page value cannot be zero"); } //// Build query string var queryStringBuilder = new QueryStringBuilder(); if (!string.IsNullOrWhiteSpace(address)) { queryStringBuilder.Add("address", address); } if (default(DateTime) != createdBefore) { queryStringBuilder.Add("created_at_max", createdBefore.ToString("yyyy-MM-dd HH:mm")); } if (default(DateTime) != createdAfter) { queryStringBuilder.Add("created_at_min", createdAfter.ToString("yyyy-MM-dd HH:mm")); } if (WebhookField.None != fields) { queryStringBuilder.Add("fields", fields.BuildWebhookFieldFilter()); } if (0 != limit) { queryStringBuilder.Add("limit", limit.ToString(CultureInfo.InvariantCulture)); } if (0 != page) { queryStringBuilder.Add("page", page.ToString(CultureInfo.InvariantCulture)); } if (0 != idGreaterThan) { queryStringBuilder.Add("since_id", idGreaterThan.ToString(CultureInfo.InvariantCulture)); } if (WebhookTopic.None != topic) { queryStringBuilder.Add("topic", topic.Convert()); } if (default(DateTime) != updatedBefore) { queryStringBuilder.Add("updated_at_min", updatedBefore.ToString("yyyy-MM-dd HH:mm")); } if (default(DateTime) != updatedAfter) { queryStringBuilder.Add("updated_at_max", updatedAfter.ToString("yyyy-MM-dd HH:mm")); } //// Perform HTTP GET call to API using (var httpClient = new HttpClient()) { httpClient.Configure(shopUrl, accessToken); var queryStringParameters = queryStringBuilder.ToString(); var response = await httpClient.GetAsync(string.Format(CultureInfo.InvariantCulture, "{0}{1}", ApiRequestResources.GetWebhooksAll, string.IsNullOrWhiteSpace(queryStringParameters) ? string.Empty : queryStringParameters)); if (!response.IsSuccessStatusCode) { return null; } var rawResponseContent = await response.Content.ReadAsStringAsync(); var webhooks = JsonConvert.DeserializeObject<WebhooksJson>(rawResponseContent); return webhooks.Hooks; } }
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; } }
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); }
public async Task<int> CountAsync(string shopUrl, string accessToken, string address = "", WebhookTopic topic = WebhookTopic.None) { shopUrl.PerCallShopUrlContract(); accessToken.PerCallAccessTokenContract(); if (!string.IsNullOrWhiteSpace(address) && !address.IsValidUrlAddress()) { throw new ArgumentException("Address parameter is not a well formed URL"); } var queryStringBuilder = new QueryStringBuilder(); if (!string.IsNullOrWhiteSpace(address)) { queryStringBuilder.Add("address", address); } if (WebhookTopic.None != topic) { queryStringBuilder.Add("topic", topic.Convert()); } using (var httpClient = new HttpClient()) { httpClient.Configure(shopUrl, accessToken); var queryStringParameters = queryStringBuilder.ToString(); var response = await httpClient.GetAsync(string.Format(CultureInfo.InvariantCulture, "{0}{1}", ApiRequestResources.GetWebhooksAllCount, string.IsNullOrWhiteSpace(queryStringParameters) ? string.Empty : queryStringParameters)); if (!response.IsSuccessStatusCode) { return 0; } var rawResponseContent = await response.Content.ReadAsStringAsync(); var webhooksCount = JsonConvert.DeserializeObject<WebhooksCountJson>(rawResponseContent); return webhooksCount.Count; } }
public async Task<int> CountAsync(string address = "", WebhookTopic topic = WebhookTopic.None) { this.client.Configuration.SingleShopContract(); return await this.CountAsync(this.client.Configuration.ShopDomain, this.client.Configuration.AccessToken, address, topic); }
internal static string Convert(this WebhookTopic topic) { switch (topic) { case WebhookTopic.OrdersCreate: return("orders/create"); case WebhookTopic.OrdersDelete: return("orders/delete"); case WebhookTopic.OrdersUpdated: return("orders/updated"); case WebhookTopic.OrdersPaid: return("orders/paid"); case WebhookTopic.OrdersCancelled: return("orders/cancelled"); case WebhookTopic.OrdersFulfilled: return("orders/fulfilled"); case WebhookTopic.OrdersPartiallyFulfilled: return("orders/partially_fulfilled"); case WebhookTopic.OrderTransactionsCreate: return("order_transactions/create"); case WebhookTopic.CartsCreate: return("carts/create"); case WebhookTopic.CartsUpdate: return("carts/update"); case WebhookTopic.CheckoutsCreate: return("checkouts/create"); case WebhookTopic.CheckoutsUpdate: return("checkouts/update"); case WebhookTopic.CheckoutsDelete: return("checkouts/delete"); case WebhookTopic.RefundsCreate: return("refunds/create"); case WebhookTopic.ProductsCreate: return("products/create"); case WebhookTopic.ProductsUpdate: return("products/update"); case WebhookTopic.ProductsDelete: return("products/delete"); case WebhookTopic.CollectionsCreate: return("collections/create"); case WebhookTopic.CollectionsUpdate: return("collections/update"); case WebhookTopic.CollectionsDelete: return("collections/delete"); case WebhookTopic.CustomerGroupsCreate: return("customer_groups/create"); case WebhookTopic.CustomerGroupsUpdate: return("customer_groups/update"); case WebhookTopic.CustomerGroupsDelete: return("customer_groups/delete"); case WebhookTopic.CustomersCreate: return("customers/create"); case WebhookTopic.CustomersEnable: return("customers/enable"); case WebhookTopic.CustomersDisable: return("customers/disable"); case WebhookTopic.CustomersUpdate: return("customers/update"); case WebhookTopic.CustomersDelete: return("customers/delete"); case WebhookTopic.FulfillmentsCreate: return("fulfillments/create"); case WebhookTopic.FulfillmentsUpdate: return("fulfillments/update"); case WebhookTopic.ShopUpdate: return("shop/update"); case WebhookTopic.DisputesCreate: return("disputes/create"); case WebhookTopic.DisputesUpdate: return("disputes/update"); case WebhookTopic.AppUninstalled: return("app/uninstalled"); default: throw new ArgumentOutOfRangeException("topic"); } }
public async Task <IList <Webhook> > GetAllAsync( string shopUrl, string accessToken, string address = "", DateTime createdBefore = default(DateTime), DateTime createdAfter = default(DateTime), WebhookField fields = WebhookField.None, int limit = 50, int page = 1, int idGreaterThan = 0, WebhookTopic topic = WebhookTopic.None, DateTime updatedBefore = default(DateTime), DateTime updatedAfter = default(DateTime)) { //// Default contracts shopUrl.PerCallShopUrlContract(); accessToken.PerCallAccessTokenContract(); //// Optional parameter validation if (!string.IsNullOrWhiteSpace(address) && !address.IsValidUrlAddress()) { throw new ArgumentException("Address parameter is not a well formed URL"); } if (250 < limit) { throw new ArgumentException("Limit value cannot be more than 250, default is 50 if not specified"); } if (0 == page) { throw new ArgumentException("Page value cannot be zero"); } //// Build query string var queryStringBuilder = new QueryStringBuilder(); if (!string.IsNullOrWhiteSpace(address)) { queryStringBuilder.Add("address", address); } if (default(DateTime) != createdBefore) { queryStringBuilder.Add("created_at_max", createdBefore.ToString("yyyy-MM-dd HH:mm")); } if (default(DateTime) != createdAfter) { queryStringBuilder.Add("created_at_min", createdAfter.ToString("yyyy-MM-dd HH:mm")); } if (WebhookField.None != fields) { queryStringBuilder.Add("fields", fields.BuildWebhookFieldFilter()); } if (0 != limit) { queryStringBuilder.Add("limit", limit.ToString(CultureInfo.InvariantCulture)); } if (0 != page) { queryStringBuilder.Add("page", page.ToString(CultureInfo.InvariantCulture)); } if (0 != idGreaterThan) { queryStringBuilder.Add("since_id", idGreaterThan.ToString(CultureInfo.InvariantCulture)); } if (WebhookTopic.None != topic) { queryStringBuilder.Add("topic", topic.Convert()); } if (default(DateTime) != updatedBefore) { queryStringBuilder.Add("updated_at_min", updatedBefore.ToString("yyyy-MM-dd HH:mm")); } if (default(DateTime) != updatedAfter) { queryStringBuilder.Add("updated_at_max", updatedAfter.ToString("yyyy-MM-dd HH:mm")); } //// Perform HTTP GET call to API using (var httpClient = new HttpClient()) { httpClient.Configure(shopUrl, accessToken); var queryStringParameters = queryStringBuilder.ToString(); var response = await httpClient.GetAsync(string.Format(CultureInfo.InvariantCulture, "{0}{1}", ApiRequestResources.GetWebhooksAll, string.IsNullOrWhiteSpace(queryStringParameters) ? string.Empty : queryStringParameters)); if (!response.IsSuccessStatusCode) { return(null); } var rawResponseContent = await response.Content.ReadAsStringAsync(); var webhooks = JsonConvert.DeserializeObject <WebhooksJson>(rawResponseContent); return(webhooks.Hooks); } }
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); } }
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)); }
public async Task <int> CountAsync(string shopUrl, string accessToken, string address = "", WebhookTopic topic = WebhookTopic.None) { shopUrl.PerCallShopUrlContract(); accessToken.PerCallAccessTokenContract(); if (!string.IsNullOrWhiteSpace(address) && !address.IsValidUrlAddress()) { throw new ArgumentException("Address parameter is not a well formed URL"); } var queryStringBuilder = new QueryStringBuilder(); if (!string.IsNullOrWhiteSpace(address)) { queryStringBuilder.Add("address", address); } if (WebhookTopic.None != topic) { queryStringBuilder.Add("topic", topic.Convert()); } using (var httpClient = new HttpClient()) { httpClient.Configure(shopUrl, accessToken); var queryStringParameters = queryStringBuilder.ToString(); var response = await httpClient.GetAsync(string.Format(CultureInfo.InvariantCulture, "{0}{1}", ApiRequestResources.GetWebhooksAllCount, string.IsNullOrWhiteSpace(queryStringParameters) ? string.Empty : queryStringParameters)); if (!response.IsSuccessStatusCode) { return(0); } var rawResponseContent = await response.Content.ReadAsStringAsync(); var webhooksCount = JsonConvert.DeserializeObject <WebhooksCountJson>(rawResponseContent); return(webhooksCount.Count); } }
public async Task <int> CountAsync(string address = "", WebhookTopic topic = WebhookTopic.None) { this.client.Configuration.SingleShopContract(); return(await this.CountAsync(this.client.Configuration.ShopDomain, this.client.Configuration.AccessToken, address, topic)); }