예제 #1
0
        /// <summary>
        /// Gets email statistics by browser
        /// See: https://sendgrid.com/docs/API_Reference/Web_API_v3/Stats/advanced.html.
        /// </summary>
        /// <param name="browsers">The browsers 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>
        /// <param name="onBehalfOf">The user to impersonate.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// An array of <see cref="Statistic" />.
        /// </returns>
        public Task <Statistic[]> GetBrowsersStatisticsAsync(IEnumerable <string> browsers, DateTime startDate, DateTime?endDate = null, AggregateBy aggregatedBy = AggregateBy.None, string onBehalfOf = null, CancellationToken cancellationToken = default)
        {
            var request = _client
                          .GetAsync($"browsers/{_endpoint}")
                          .OnBehalfOf(onBehalfOf)
                          .WithArgument("start_date", startDate.ToString("yyyy-MM-dd"))
                          .WithCancellationToken(cancellationToken);

            if (endDate.HasValue)
            {
                request.WithArgument("end_date", endDate.Value.ToString("yyyy-MM-dd"));
            }
            if (aggregatedBy != AggregateBy.None)
            {
                request.WithArgument("aggregated_by", aggregatedBy.ToEnumString());
            }

            if (browsers != null && browsers.Any())
            {
                foreach (var browser in browsers)
                {
                    request.WithArgument("browsers", browser);
                }
            }

            return(request.AsObject <Statistic[]>());
        }
예제 #2
0
        /// <summary>
        /// Get statistics for Inbound Parse Webhook usage.
        /// </summary>
        /// <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>
        /// <param name="onBehalfOf">The user to impersonate.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// An array of <see cref="Statistic" />.
        /// </returns>
        public Task <Statistic[]> GetInboundParseUsageAsync(DateTime startDate, DateTime?endDate = null, AggregateBy aggregatedBy = AggregateBy.None, string onBehalfOf = null, CancellationToken cancellationToken = default)
        {
            var request = _client
                          .GetAsync(_endpoint)
                          .OnBehalfOf(onBehalfOf)
                          .WithArgument("start_date", startDate.ToString("yyyy-MM-dd"))
                          .WithCancellationToken(cancellationToken);

            if (endDate.HasValue)
            {
                request.WithArgument("end_date", endDate.Value.ToString("yyyy-MM-dd"));
            }
            if (aggregatedBy != AggregateBy.None)
            {
                request.WithArgument("aggregated_by", aggregatedBy.ToEnumString());
            }

            return(request.AsObject <Statistic[]>());
        }
예제 #3
0
        /// <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>
        /// <param name="onBehalfOf">The user to impersonate.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// An array of <see cref="Statistic" />.
        /// </returns>
        public Task <Statistic[]> GetCountryStatisticsAsync(string country, DateTime startDate, DateTime?endDate = null, AggregateBy aggregatedBy = AggregateBy.None, string onBehalfOf = null, CancellationToken cancellationToken = default)
        {
            var request = _client
                          .GetAsync($"geo/{_endpoint}")
                          .OnBehalfOf(onBehalfOf)
                          .WithArgument("start_date", startDate.ToString("yyyy-MM-dd"))
                          .WithCancellationToken(cancellationToken);

            if (endDate.HasValue)
            {
                request.WithArgument("end_date", endDate.Value.ToString("yyyy-MM-dd"));
            }
            if (aggregatedBy != AggregateBy.None)
            {
                request.WithArgument("aggregated_by", aggregatedBy.ToEnumString());
            }
            if (!string.IsNullOrEmpty(country))
            {
                request.WithArgument("country", country);
            }

            return(request.AsObject <Statistic[]>());
        }