internal static string BuildWebhookFieldFilter(this WebhookField webhookField) { if (webhookField == WebhookField.None) { return(string.Empty); } var webhookFieldFilterStringBuilder = new StringBuilder(); foreach (var webhookFieldFilterItem in Enum.GetValues(typeof(WebhookField)).Cast <WebhookField>().Where(webhookFieldFilterItem => webhookFieldFilterItem != WebhookField.None).Where(webhookFieldFilterItem => (webhookField & webhookFieldFilterItem) == webhookFieldFilterItem)) { switch (webhookFieldFilterItem) { case WebhookField.Id: webhookFieldFilterStringBuilder.Append("id"); break; case WebhookField.Address: webhookFieldFilterStringBuilder.Append("address"); break; case WebhookField.Topic: webhookFieldFilterStringBuilder.Append("topic"); break; case WebhookField.CreatedAt: webhookFieldFilterStringBuilder.Append("created_at"); break; case WebhookField.UpdatedAt: webhookFieldFilterStringBuilder.Append("updated_at"); break; case WebhookField.Format: webhookFieldFilterStringBuilder.Append("format"); break; case WebhookField.Fields: webhookFieldFilterStringBuilder.Append("fields"); break; case WebhookField.MetafieldNamespace: webhookFieldFilterStringBuilder.Append("metafield_namespaces"); break; } webhookFieldFilterStringBuilder.Append(','); } if (webhookFieldFilterStringBuilder.Length > 0 && webhookFieldFilterStringBuilder[webhookFieldFilterStringBuilder.Length - 1] == ',') { return(webhookFieldFilterStringBuilder.ToString().Substring(0, webhookFieldFilterStringBuilder.Length - 1)); } return(webhookFieldFilterStringBuilder.ToString()); }
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> GetSingleAsync(string shopUrl, string accessToken, string id, WebhookField fields = WebhookField.None) { //// Default contracts shopUrl.PerCallShopUrlContract(); accessToken.PerCallAccessTokenContract(); //// Build query string var queryStringBuilder = new QueryStringBuilder(); if (WebhookField.None != fields) { queryStringBuilder.Add("fields", fields.BuildWebhookFieldFilter()); } //// 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}", string.Format(CultureInfo.InvariantCulture, ApiRequestResources.GetWebhookSingle, id), string.IsNullOrWhiteSpace(queryStringParameters) ? string.Empty : queryStringParameters)); if (!response.IsSuccessStatusCode) { return null; } var rawResponseContent = await response.Content.ReadAsStringAsync(); var webhookJson = JsonConvert.DeserializeObject<WebhookJson>(rawResponseContent); return webhookJson.Webhook; } }
public async Task<Webhook> GetSingleAsync(string id, WebhookField fields = WebhookField.None) { this.client.Configuration.SingleShopContract(); return await this.GetSingleAsync(this.client.Configuration.ShopDomain, this.client.Configuration.AccessToken, id, fields); }
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> GetSingleAsync(string shopUrl, string accessToken, string id, WebhookField fields = WebhookField.None) { //// Default contracts shopUrl.PerCallShopUrlContract(); accessToken.PerCallAccessTokenContract(); //// Build query string var queryStringBuilder = new QueryStringBuilder(); if (WebhookField.None != fields) { queryStringBuilder.Add("fields", fields.BuildWebhookFieldFilter()); } //// 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}", string.Format(CultureInfo.InvariantCulture, ApiRequestResources.GetWebhookSingle, id), string.IsNullOrWhiteSpace(queryStringParameters) ? string.Empty : queryStringParameters)); if (!response.IsSuccessStatusCode) { return(null); } var rawResponseContent = await response.Content.ReadAsStringAsync(); var webhookJson = JsonConvert.DeserializeObject <WebhookJson>(rawResponseContent); return(webhookJson.Webhook); } }
public async Task <Webhook> GetSingleAsync(string id, WebhookField fields = WebhookField.None) { this.client.Configuration.SingleShopContract(); return(await this.GetSingleAsync(this.client.Configuration.ShopDomain, this.client.Configuration.AccessToken, id, fields)); }