-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
345 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Mandrill.Model; | ||
|
||
namespace Mandrill | ||
{ | ||
public interface IMandrillSubaccountsApi | ||
{ | ||
Task<IList<MandrillSubaccountResponse>> ListAsync(string q = null); | ||
Task<MandrillSubaccountResponse> AddAsync(string id, string name = null, string notes = null, int? customQuota = null); | ||
Task<MandrillSubaccountInfo> InfoAsync(string id); | ||
Task<MandrillSubaccountResponse> UpdateAsync(string id, string name = null, string notes = null, int? customQuota = null); | ||
Task<MandrillSubaccountResponse> DeleteAsync(string id); | ||
Task<MandrillSubaccountResponse> PauseAsync(string id); | ||
Task<MandrillSubaccountResponse> ResumeAsync(string id); | ||
} | ||
|
||
public static class MandrillSubaccountsApiSynchronousExtensions | ||
{ | ||
public static IList<MandrillSubaccountResponse> List(this IMandrillSubaccountsApi subaccounts, string q = null) | ||
{ | ||
return AsyncHelper.InvokeSync(subaccounts, api => api.ListAsync(q)); | ||
} | ||
|
||
public static MandrillSubaccountResponse Add(this IMandrillSubaccountsApi subaccounts, string id, string name = null, string notes = null, int? customQuota = null) | ||
{ | ||
return AsyncHelper.InvokeSync(subaccounts, api => api.AddAsync(id, name, notes, customQuota)); | ||
} | ||
|
||
public static MandrillSubaccountInfo Info(this IMandrillSubaccountsApi subaccounts, string id) | ||
{ | ||
return AsyncHelper.InvokeSync(subaccounts, api => api.InfoAsync(id)); | ||
} | ||
|
||
public static MandrillSubaccountResponse Update(this IMandrillSubaccountsApi subaccounts, string id, string name = null, string notes = null, int? customQuota = null) | ||
{ | ||
return AsyncHelper.InvokeSync(subaccounts, api => api.UpdateAsync(id, name, notes, customQuota)); | ||
} | ||
|
||
public static MandrillSubaccountResponse Delete(this IMandrillSubaccountsApi subaccounts, string id) | ||
{ | ||
return AsyncHelper.InvokeSync(subaccounts, api => api.DeleteAsync(id)); | ||
} | ||
|
||
public static MandrillSubaccountResponse Pause(this IMandrillSubaccountsApi subaccounts, string id) | ||
{ | ||
return AsyncHelper.InvokeSync(subaccounts, api => api.PauseAsync(id)); | ||
} | ||
|
||
public static MandrillSubaccountResponse Resume(this IMandrillSubaccountsApi subaccounts, string id) | ||
{ | ||
return AsyncHelper.InvokeSync(subaccounts, api => api.ResumeAsync(id)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Mandrill.Model; | ||
|
||
namespace Mandrill | ||
{ | ||
internal class MandrillSubaccountsApi : IMandrillSubaccountsApi | ||
{ | ||
public MandrillApi MandrillApi { get; set; } | ||
|
||
public MandrillSubaccountsApi(MandrillApi mandrillApi) | ||
{ | ||
MandrillApi = mandrillApi; | ||
} | ||
|
||
public async Task<IList<MandrillSubaccountResponse>> ListAsync(string q = null) | ||
{ | ||
return await MandrillApi.PostAsync<MandrillSubaccountsRequest, IList<MandrillSubaccountResponse>>("subaccounts/list.json", new MandrillSubaccountsRequest() | ||
{ | ||
Q = q | ||
}); | ||
} | ||
|
||
public async Task<MandrillSubaccountResponse> AddAsync(string id, string name = null, string notes = null, int? customQuota = null) | ||
{ | ||
return await MandrillApi.PostAsync<MandrillSubaccountsRequest, MandrillSubaccountResponse>("subaccounts/add.json", new MandrillSubaccountsRequest() | ||
{ | ||
Id = id, | ||
Name = name, | ||
Notes = notes, | ||
CustomQuota = customQuota | ||
}); | ||
} | ||
|
||
public async Task<MandrillSubaccountInfo> InfoAsync(string id) | ||
{ | ||
return await MandrillApi.PostAsync<MandrillSubaccountsRequest, MandrillSubaccountInfo>("subaccounts/info.json", new MandrillSubaccountsRequest() | ||
{ | ||
Id = id, | ||
}); | ||
} | ||
|
||
public async Task<MandrillSubaccountResponse> UpdateAsync(string id, string name = null, string notes = null, int? customQuota = null) | ||
{ | ||
return await MandrillApi.PostAsync<MandrillSubaccountsRequest, MandrillSubaccountResponse>("subaccounts/update.json", new MandrillSubaccountsRequest() | ||
{ | ||
Id = id, | ||
Name = name, | ||
Notes = notes, | ||
CustomQuota = customQuota | ||
}); | ||
} | ||
|
||
public async Task<MandrillSubaccountResponse> DeleteAsync(string id) | ||
{ | ||
return await MandrillApi.PostAsync<MandrillSubaccountsRequest, MandrillSubaccountInfo>("subaccounts/delete.json", new MandrillSubaccountsRequest() | ||
{ | ||
Id = id, | ||
}); | ||
} | ||
|
||
public async Task<MandrillSubaccountResponse> PauseAsync(string id) | ||
{ | ||
return await MandrillApi.PostAsync<MandrillSubaccountsRequest, MandrillSubaccountInfo>("subaccounts/pause.json", new MandrillSubaccountsRequest() | ||
{ | ||
Id = id, | ||
}); | ||
} | ||
|
||
public async Task<MandrillSubaccountResponse> ResumeAsync(string id) | ||
{ | ||
return await MandrillApi.PostAsync<MandrillSubaccountsRequest, MandrillSubaccountInfo>("subaccounts/resume.json", new MandrillSubaccountsRequest() | ||
{ | ||
Id = id, | ||
}); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Mandrill.net/Model/Subaccounts/MandrillSubaccountInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Mandrill.Model | ||
{ | ||
public class MandrillSubaccountInfo : MandrillSubaccountResponse | ||
{ | ||
[JsonProperty("last_30_days")] | ||
public MandrillSubaccountStats Last30Days { get; set; } | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Mandrill.net/Model/Subaccounts/MandrillSubaccountResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace Mandrill.Model | ||
{ | ||
public class MandrillSubaccountResponse | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public int CustomQuota { get; set; } | ||
|
||
public MandrillSubaccountStatus Status { get; set; } | ||
|
||
public int Reputation { get; set; } | ||
|
||
[JsonConverter(typeof (IsoDateTimeConverter))] | ||
public DateTime CreatedAt { get; set; } | ||
|
||
[JsonConverter(typeof (IsoDateTimeConverter))] | ||
public string FirstSentAt { get; set; } | ||
|
||
public int SentWeekly { get; set; } | ||
|
||
public int SentMonthly { get; set; } | ||
|
||
public int SentTotal { get; set; } | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Mandrill.net/Model/Subaccounts/MandrillSubaccountStats.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Mandrill.Model | ||
{ | ||
public class MandrillSubaccountStats : MandrillAggregateStatisticsBase | ||
{ | ||
|
||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Mandrill.net/Model/Subaccounts/MandrillSubaccountStatus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Mandrill.Model | ||
{ | ||
public enum MandrillSubaccountStatus | ||
{ | ||
Active, | ||
Paused | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Mandrill.net/Model/Subaccounts/MandrillSubaccountsRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Mandrill.Model | ||
{ | ||
internal class MandrillSubaccountsRequest : MandrillRequestBase | ||
{ | ||
public string Id { get; set; } | ||
public string Name { get; set; } | ||
public string Notes { get; set; } | ||
public int? CustomQuota { get; set; } | ||
public string Q { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Mandrill.Model; | ||
using NUnit.Framework; | ||
using Mandrill; | ||
|
||
namespace Tests | ||
{ | ||
[Category("subaccounts")] | ||
internal class Subaccounts : IntegrationTest | ||
{ | ||
[Category("subaccounts/add.json")] | ||
private class Add : Subaccounts | ||
{ | ||
[Test] | ||
public void Can_add_subaccount() | ||
{ | ||
var id = Guid.NewGuid().ToString("N"); | ||
var notes = "created by test at " + DateTime.UtcNow.ToString("s"); | ||
var result = Api.Subaccounts.Add(id, name: "test", notes: notes, customQuota: null); | ||
result.Id.Should().Be(id); | ||
} | ||
} | ||
|
||
[Category("subaccounts/list.json")] | ||
private class List : Subaccounts | ||
{ | ||
[Test] | ||
public void Can_list_subaccount() | ||
{ | ||
var results = Api.Subaccounts.List(q:null); | ||
results.Count.Should().BeGreaterOrEqualTo(0); | ||
} | ||
[Test] | ||
public void Can_filter_subaccount() | ||
{ | ||
var results = Api.Subaccounts.List(q: Guid.NewGuid().ToString("N")); | ||
results.Count.Should().Be(0); | ||
} | ||
} | ||
|
||
[Category("subaccounts/update.json")] | ||
private class Update : Subaccounts | ||
{ | ||
[Test] | ||
public void Can_update_subaccount() | ||
{ | ||
var id = Guid.NewGuid().ToString("N"); | ||
var notes = "created by test at " + DateTime.UtcNow.ToString("s"); | ||
Api.Subaccounts.Add(id, name: "test", notes: notes, customQuota: null); | ||
|
||
var result = Api.Subaccounts.Update(id, name: "test", notes: "update", customQuota: 5000); | ||
result.CustomQuota.Should().Be(5000); | ||
} | ||
|
||
} | ||
|
||
[Category("subaccounts/pause.json")] | ||
private class Pause : Subaccounts | ||
{ | ||
[Test] | ||
public void Can_pause_subaccount() | ||
{ | ||
var id = Guid.NewGuid().ToString("N"); | ||
var notes = "created by test at " + DateTime.UtcNow.ToString("s"); | ||
Api.Subaccounts.Add(id, name: "test", notes: notes, customQuota: null); | ||
|
||
var result = Api.Subaccounts.Pause(id); | ||
result.Status.Should().Be(MandrillSubaccountStatus.Paused); | ||
} | ||
|
||
} | ||
|
||
[Category("subaccounts/resume.json")] | ||
private class Resume : Subaccounts | ||
{ | ||
[Test] | ||
public void Can_resume_subaccount() | ||
{ | ||
var id = Guid.NewGuid().ToString("N"); | ||
var notes = "created by test at " + DateTime.UtcNow.ToString("s"); | ||
Api.Subaccounts.Add(id, name: "test", notes: notes, customQuota: null); | ||
|
||
var result = Api.Subaccounts.Pause(id); | ||
result.Status.Should().Be(MandrillSubaccountStatus.Paused); | ||
|
||
result = Api.Subaccounts.Resume(id); | ||
result.Status.Should().Be(MandrillSubaccountStatus.Active); | ||
} | ||
|
||
} | ||
|
||
[Category("subaccounts/delete.json")] | ||
private class Delete : Subaccounts | ||
{ | ||
[Test] | ||
public void Can_delete_subaccount() | ||
{ | ||
var id = Guid.NewGuid().ToString("N"); | ||
var notes = "created by test at " + DateTime.UtcNow.ToString("s"); | ||
Api.Subaccounts.Add(id, name: "test", notes: notes, customQuota: null); | ||
|
||
var result = Api.Subaccounts.Delete(id); | ||
result.Id.Should().Be(id); | ||
} | ||
|
||
} | ||
|
||
[Category("subaccounts/info.json")] | ||
private class Info : Subaccounts | ||
{ | ||
[Test] | ||
public void Can_get_info_subaccount() | ||
{ | ||
var id = Guid.NewGuid().ToString("N"); | ||
var notes = "created by test at " + DateTime.UtcNow.ToString("s"); | ||
Api.Subaccounts.Add(id, name: "test", notes: notes, customQuota: null); | ||
|
||
var result = Api.Subaccounts.Info(id); | ||
result.Id.Should().Be(id); | ||
result.Last30Days.Clicks.Should().Be(0); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters