/// <summary> /// Get email statistics for the given categories. If you don’t pass any parameters, the endpoint will return a sum for each category 10 at a time. /// See: https://sendgrid.com/docs/API_Reference/Web_API_v3/Stats/categories.html /// </summary> /// <param name="categories">The categories to get statistics for, up to 10</param> /// <param name="startDate">The starting date of the statistics to retrieve.</param> /// <param name="endDate">The end date of the statistics to retrieve. Defaults to today.</param> /// <param name="aggregatedBy">How to group the statistics, must be day|week|month</param> /// <returns></returns> public async Task <Statistic[]> GetCategoriesStatisticsAsync(IEnumerable <string> categories, DateTime startDate, DateTime?endDate = null, AggregateBy aggregatedBy = AggregateBy.None, CancellationToken cancellationToken = default(CancellationToken)) { var endpoint = string.Format("/categories{0}?start_date={1}", _endpoint, startDate.ToString("yyyy-MM-dd")); if (endDate.HasValue) { endpoint += "&end_date=" + endDate.Value.ToString("yyyy-MM-dd"); } if (aggregatedBy != AggregateBy.None) { endpoint += "&aggregated_by=" + aggregatedBy.GetDescription(); } if (categories != null && categories.Any()) { foreach (var category in categories) { endpoint += "&categories=" + category; } } var response = await _client.GetAsync(endpoint, cancellationToken).ConfigureAwait(false); response.EnsureSuccess(); var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var statistics = JArray.Parse(responseContent).ToObject <Statistic[]>(); return(statistics); }
/// <summary> /// Gets email statistics by country and state/province. Only supported for US and CA. /// See: https://sendgrid.com/docs/API_Reference/Web_API_v3/Stats/advanced.html /// </summary> /// <param name="country">US|CA</param> /// <param name="startDate">The starting date of the statistics to retrieve.</param> /// <param name="endDate">The end date of the statistics to retrieve. Defaults to today.</param> /// <param name="aggregatedBy">How to group the statistics, must be day|week|month</param> /// <returns></returns> public async Task <Statistic[]> GetCountryStatisticsAsync(string country, DateTime startDate, DateTime?endDate = null, AggregateBy aggregatedBy = AggregateBy.None, CancellationToken cancellationToken = default(CancellationToken)) { var endpoint = string.Format("/geo{0}?start_date={1}", _endpoint, startDate.ToString("yyyy-MM-dd")); if (endDate.HasValue) { endpoint += "&end_date=" + endDate.Value.ToString("yyyy-MM-dd"); } if (aggregatedBy != AggregateBy.None) { endpoint += "&aggregated_by=" + aggregatedBy.GetDescription(); } if (!string.IsNullOrEmpty(country)) { endpoint += "&country=" + country; } var response = await _client.GetAsync(endpoint, cancellationToken).ConfigureAwait(false); response.EnsureSuccess(); var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var statistics = JArray.Parse(responseContent).ToObject <Statistic[]>(); return(statistics); }