Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the messagestream parameter to all stats calls #109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Postmark.Tests/ClientStatisticsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
T alltimeStats, T allstatsThroughLastMonth, T windowFromLastMonth, T windowFromLastMonthWithTag, Func<T, int> statGetter)
T alltimeStats, T allstatsThroughLastMonth, T windowFromLastMonth, T windowFromLastMonthWithTag, T outboundStatsForStream, Func<T, int> 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));
Expand All @@ -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));
Expand Down Expand Up @@ -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),
Expand Down
50 changes: 31 additions & 19 deletions src/Postmark/PostmarkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public async Task<PostmarkServer> EditServerAsync(String name = null, string col
/// <param name="toDate"></param>
/// <returns></returns>
private IDictionary<string, object>
ConstructSentStatsFilter(string tag, DateTime? fromDate, DateTime? toDate)
ConstructSentStatsFilter(string tag, DateTime? fromDate, DateTime? toDate, string messageStream)
{
var parameters = new Dictionary<string, object>();
if (!string.IsNullOrWhiteSpace(tag))
Expand All @@ -349,6 +349,10 @@ private IDictionary<string, object>
{
parameters["todate"] = toDate.Value.ToString(DATE_FORMAT);
}
if (!string.IsNullOrWhiteSpace(messageStream))
{
parameters["messagestream"] = messageStream;
}
return parameters;
}

Expand Down Expand Up @@ -488,11 +492,12 @@ public async Task<PostmarkClicksList> GetClickEventsForMessageAsync(
/// <param name="tag"></param>
/// <param name="fromDate"></param>
/// <param name="toDate"></param>
/// <param name="messageStream"></param>
/// <returns></returns>
public async Task<PostmarkOutboundOverviewStats> 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<PostmarkOutboundOverviewStats>
("/stats/outbound", parameters);
}
Expand All @@ -503,11 +508,12 @@ public async Task<PostmarkOutboundOverviewStats> GetOutboundOverviewStatsAsync(
/// <param name="tag"></param>
/// <param name="fromDate"></param>
/// <param name="toDate"></param>
/// <param name="messageStream"></param>
/// <returns></returns>
public async Task<PostmarkOutboundSentStats>
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<PostmarkOutboundSentStats>
("/stats/outbound/sends", parameters);
}
Expand All @@ -518,11 +524,12 @@ public async Task<PostmarkOutboundSentStats>
/// <param name="tag"></param>
/// <param name="fromDate"></param>
/// <param name="toDate"></param>
/// <param name="messageStream"></param>
/// <returns></returns>
public async Task<PostmarkOutboundBounceStats>
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<PostmarkOutboundBounceStats>
("/stats/outbound/bounces", parameters);
}
Expand All @@ -533,10 +540,11 @@ public async Task<PostmarkOutboundBounceStats>
/// <param name="tag"></param>
/// <param name="fromDate"></param>
/// <param name="toDate"></param>
/// <param name="messageStream"></param>
/// <returns></returns>
public async Task<PostmarkOutboundSpamComplaintStats> GetOutboundSpamComplaintCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null)
public async Task<PostmarkOutboundSpamComplaintStats> 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<PostmarkOutboundSpamComplaintStats>
("/stats/outbound/spam", parameters);
}
Expand All @@ -547,10 +555,11 @@ public async Task<PostmarkOutboundSpamComplaintStats> GetOutboundSpamComplaintCo
/// <param name="tag"></param>
/// <param name="fromDate"></param>
/// <param name="toDate"></param>
/// <param name="messageStream"></param>
/// <returns></returns>
public async Task<PostmarkOutboundTrackedStats> GetOutboundTrackingCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null)
public async Task<PostmarkOutboundTrackedStats> 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<PostmarkOutboundTrackedStats>
("/stats/outbound/tracked", parameters);
}
Expand All @@ -561,10 +570,11 @@ public async Task<PostmarkOutboundTrackedStats> GetOutboundTrackingCountsAsync(s
/// <param name="tag"></param>
/// <param name="fromDate"></param>
/// <param name="toDate"></param>
/// <param name="messageStream"></param>
/// <returns></returns>
public async Task<PostmarkOutboundOpenStats> GetOutboundOpenCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null)
public async Task<PostmarkOutboundOpenStats> 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<PostmarkOutboundOpenStats>
("/stats/outbound/opens", parameters);
}
Expand All @@ -575,10 +585,11 @@ public async Task<PostmarkOutboundOpenStats> GetOutboundOpenCountsAsync(string t
/// <param name="tag"></param>
/// <param name="fromDate"></param>
/// <param name="toDate"></param>
/// <param name="messageStream"></param>
/// <returns></returns>
public async Task<PostmarkOutboundPlatformStats> GetOutboundPlatformCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null)
public async Task<PostmarkOutboundPlatformStats> 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<PostmarkOutboundPlatformStats>
("/stats/outbound/opens/platforms", parameters);
}
Expand All @@ -589,10 +600,11 @@ public async Task<PostmarkOutboundPlatformStats> GetOutboundPlatformCountsAsync(
/// <param name="tag"></param>
/// <param name="fromDate"></param>
/// <param name="toDate"></param>
/// <param name="messageStream"></param>
/// <returns></returns>
public async Task<PostmarkOutboundClientStats> GetOutboundClientUsageCountsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null)
public async Task<PostmarkOutboundClientStats> 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<Dictionary<string, object>>("/stats/outbound/opens/emailclients", parameters);

var retval = new PostmarkOutboundClientStats();
Expand Down Expand Up @@ -637,9 +649,9 @@ public async Task<PostmarkOutboundClientStats> GetOutboundClientUsageCountsAsync
/// <param name="fromDate"></param>
/// <param name="toDate"></param>
/// <returns></returns>
public async Task<PostmarkOutboundReadStats> GetOutboundReadtimeStatsAsync(string tag = null, DateTime? fromDate = null, DateTime? toDate = null)
public async Task<PostmarkOutboundReadStats> 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<Dictionary<string, object>>("/stats/outbound/opens/readtimes", parameters);

var retval = new PostmarkOutboundReadStats();
Expand Down