diff --git a/src/Postmark.Tests/ClientStatisticsTests.cs b/src/Postmark.Tests/ClientStatisticsTests.cs index d13671d..bca624c 100644 --- a/src/Postmark.Tests/ClientStatisticsTests.cs +++ b/src/Postmark.Tests/ClientStatisticsTests.cs @@ -43,17 +43,19 @@ public async void Client_CanGetOutboundStatisticsOverviewWithTimeWindowOrTagFilt var allStatsThroughLastMonth = await Client.GetOutboundOverviewStatsAsync(null, _lastMonth); var windowFromLastMonth = await Client.GetOutboundOverviewStatsAsync(null, WindowStartDate, _lastMonth); var windowFromLastMonthWithTag = await Client.GetOutboundOverviewStatsAsync("test_tag", WindowStartDate, _lastMonth); + var outboundStatsForStream = await Client.GetOutboundOverviewStatsAsync(null, null, null, "test_stream"); - AssertStats(allOutboundStats, allStatsThroughLastMonth, windowFromLastMonth, windowFromLastMonthWithTag, f => f.Sent); + AssertStats(allOutboundStats, allStatsThroughLastMonth, windowFromLastMonth, windowFromLastMonthWithTag, outboundStatsForStream, f => f.Sent); } private void AssertStats( - T alltimeStats, T allstatsThroughLastMonth, T windowFromLastMonth, T windowFromLastMonthWithTag, Func statGetter) + T alltimeStats, T allstatsThroughLastMonth, T windowFromLastMonth, T windowFromLastMonthWithTag, T outboundStatsForStream, Func statGetter) { Assert.True(statGetter(alltimeStats) > 0, "Stat should be greater than 0"); Assert.True(statGetter(allstatsThroughLastMonth) > 0, "All Last Month Stat should be greater than 0"); Assert.True(statGetter(windowFromLastMonth) > 0, "Window from Last Month Stat should be greater than 0"); Assert.True(statGetter(windowFromLastMonthWithTag) > 0, "Window from Last Month with Tag Stat should be greater than 0"); + Assert.True(statGetter(outboundStatsForStream) > 0, "Stat for stream should be greater than 0"); Assert.True(statGetter(alltimeStats) > statGetter(allstatsThroughLastMonth)); Assert.True(statGetter(allstatsThroughLastMonth) > statGetter(windowFromLastMonth)); @@ -68,8 +70,9 @@ public async void Client_CanGetOutboundStatisticsSentCounts() var allStatsThroughLastMonth = await Client.GetOutboundSentCountsAsync(null, _lastMonth); var windowFromLastMonth = await Client.GetOutboundSentCountsAsync(null, WindowStartDate, _lastMonth); var windowFromLastMonthWithTag = await Client.GetOutboundSentCountsAsync("test_tag", WindowStartDate, _lastMonth); + var outboundStatsForStream = await Client.GetOutboundSentCountsAsync(null, null, null, "test_stream"); - AssertStats(allOutboundStats, allStatsThroughLastMonth, windowFromLastMonth, windowFromLastMonthWithTag, f => f.Sent); + AssertStats(allOutboundStats, allStatsThroughLastMonth, windowFromLastMonth, windowFromLastMonthWithTag, outboundStatsForStream, f => f.Sent); Assert.True(allOutboundStats.Days.Count() > 0); Assert.Equal(allOutboundStats.Sent, allOutboundStats.Days.Sum(k => k.Sent)); @@ -123,9 +126,10 @@ public async void Client_CanGetOutboundStatisticsClientCounts() var allStatsThroughLastMonth = await Client.GetOutboundClientUsageCountsAsync(null, _lastMonth); var windowFromLastMonth = await Client.GetOutboundClientUsageCountsAsync(null, WindowStartDate, _lastMonth); var windowFromLastMonthWithTag = await Client.GetOutboundClientUsageCountsAsync("test_tag", WindowStartDate, _lastMonth); + var outboundStatsForStream = await Client.GetOutboundClientUsageCountsAsync(null, null, null, "test_stream"); AssertStats(allOutboundStats, allStatsThroughLastMonth, windowFromLastMonth, - windowFromLastMonthWithTag, f => f.ClientCounts.Sum(k => k.Value)); + windowFromLastMonthWithTag, outboundStatsForStream, f => f.ClientCounts.Sum(k => k.Value)); Assert.True(allOutboundStats.Days.Count() > 0); Assert.Equal(allOutboundStats.ClientCounts.Sum(k => k.Value), diff --git a/src/Postmark/PostmarkClient.cs b/src/Postmark/PostmarkClient.cs index 820b42d..5f71666 100644 --- a/src/Postmark/PostmarkClient.cs +++ b/src/Postmark/PostmarkClient.cs @@ -334,7 +334,7 @@ public async Task EditServerAsync(String name = null, string col /// /// private IDictionary - ConstructSentStatsFilter(string tag, DateTime? fromDate, DateTime? toDate) + ConstructSentStatsFilter(string tag, DateTime? fromDate, DateTime? toDate, string messageStream) { var parameters = new Dictionary(); if (!string.IsNullOrWhiteSpace(tag)) @@ -349,6 +349,10 @@ private IDictionary { parameters["todate"] = toDate.Value.ToString(DATE_FORMAT); } + if (!string.IsNullOrWhiteSpace(messageStream)) + { + parameters["messagestream"] = messageStream; + } return parameters; } @@ -488,11 +492,12 @@ public async Task GetClickEventsForMessageAsync( /// /// /// + /// /// public async Task GetOutboundOverviewStatsAsync( - string tag = null, DateTime? fromDate = null, DateTime? toDate = null) + string tag = null, DateTime? fromDate = null, DateTime? toDate = null, string messageStream = null) { - var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); + var parameters = ConstructSentStatsFilter(tag, fromDate, toDate, messageStream); return await this.ProcessNoBodyRequestAsync ("/stats/outbound", parameters); } @@ -503,11 +508,12 @@ public async Task GetOutboundOverviewStatsAsync( /// /// /// + /// /// public async Task - GetOutboundSentCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null) + GetOutboundSentCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null, string messageStream = null) { - var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); + var parameters = ConstructSentStatsFilter(tag, fromDate, toDate, messageStream); return await this.ProcessNoBodyRequestAsync ("/stats/outbound/sends", parameters); } @@ -518,11 +524,12 @@ public async Task /// /// /// + /// /// public async Task - GetOutboundBounceCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null) + GetOutboundBounceCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null, string messageStream = null) { - var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); + var parameters = ConstructSentStatsFilter(tag, fromDate, toDate, messageStream); return await this.ProcessNoBodyRequestAsync ("/stats/outbound/bounces", parameters); } @@ -533,10 +540,11 @@ public async Task /// /// /// + /// /// - public async Task GetOutboundSpamComplaintCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null) + public async Task GetOutboundSpamComplaintCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null, string messageStream = null) { - var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); + var parameters = ConstructSentStatsFilter(tag, fromDate, toDate, messageStream); return await this.ProcessNoBodyRequestAsync ("/stats/outbound/spam", parameters); } @@ -547,10 +555,11 @@ public async Task GetOutboundSpamComplaintCo /// /// /// + /// /// - public async Task GetOutboundTrackingCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null) + public async Task GetOutboundTrackingCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null, string messageStream = null) { - var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); + var parameters = ConstructSentStatsFilter(tag, fromDate, toDate, messageStream); return await this.ProcessNoBodyRequestAsync ("/stats/outbound/tracked", parameters); } @@ -561,10 +570,11 @@ public async Task GetOutboundTrackingCountsAsync(s /// /// /// + /// /// - public async Task GetOutboundOpenCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null) + public async Task GetOutboundOpenCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null, string messageStream = null) { - var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); + var parameters = ConstructSentStatsFilter(tag, fromDate, toDate, messageStream); return await this.ProcessNoBodyRequestAsync ("/stats/outbound/opens", parameters); } @@ -575,10 +585,11 @@ public async Task GetOutboundOpenCountsAsync(string t /// /// /// + /// /// - public async Task GetOutboundPlatformCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null) + public async Task GetOutboundPlatformCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null, string messageStream = null) { - var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); + var parameters = ConstructSentStatsFilter(tag, fromDate, toDate, messageStream); return await this.ProcessNoBodyRequestAsync ("/stats/outbound/opens/platforms", parameters); } @@ -589,10 +600,11 @@ public async Task GetOutboundPlatformCountsAsync( /// /// /// + /// /// - public async Task GetOutboundClientUsageCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null) + public async Task GetOutboundClientUsageCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null, string messageStream = null) { - var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); + var parameters = ConstructSentStatsFilter(tag, fromDate, toDate, messageStream); var result = await this.ProcessNoBodyRequestAsync>("/stats/outbound/opens/emailclients", parameters); var retval = new PostmarkOutboundClientStats(); @@ -637,9 +649,9 @@ public async Task GetOutboundClientUsageCountsAsync /// /// /// - public async Task GetOutboundReadtimeStatsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null) + public async Task GetOutboundReadtimeStatsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null, string messageStream = null) { - var parameters = ConstructSentStatsFilter(tag, fromDate, toDate); + var parameters = ConstructSentStatsFilter(tag, fromDate, toDate, messageStream); var result = await this.ProcessNoBodyRequestAsync>("/stats/outbound/opens/readtimes", parameters); var retval = new PostmarkOutboundReadStats();