return alert after adding contact

This commit is contained in:
2014-02-02 11:27:44 +01:00
parent 29ffceb920
commit 42e5a9ef39
2 changed files with 18 additions and 8 deletions
+3 -3
View File
@@ -35,7 +35,7 @@ namespace UptimeSharp.Tests
{
string email = "example@ceecore.com";
Assert.True(await client.AddAlert(AlertType.Email, email));
Assert.NotNull(await client.AddAlert(AlertType.Email, email));
Alert origin = await GetOriginAlert(email);
@@ -53,8 +53,8 @@ namespace UptimeSharp.Tests
[Fact]
public async Task AddAndRetrieveSpecificAlerts()
{
Assert.True(await client.AddAlert(AlertType.Email, "example1@ceecore.com"));
Assert.True(await client.AddAlert(AlertType.Boxcar, "example2@ceecore.com"));
Assert.NotNull(await client.AddAlert(AlertType.Email, "example1@ceecore.com"));
Assert.NotNull(await client.AddAlert(AlertType.Boxcar, "example2@ceecore.com"));
List<Alert> alerts = await client.GetAlerts();
+15 -5
View File
@@ -51,19 +51,29 @@ namespace UptimeSharp
/// <param name="value">The value.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="UptimeSharpException"></exception>
public async Task<bool> AddAlert(AlertType type, string value, CancellationToken cancellationToken = default(CancellationToken))
/// <exception cref="UptimeSharpException">AlertType.SMS and AlertType.Twitter are not supported by the UptimeRobot API</exception>
public async Task<Alert> AddAlert(AlertType type, string value, CancellationToken cancellationToken = default(CancellationToken))
{
if (type == AlertType.SMS || type == AlertType.Twitter)
{
throw new UptimeSharpException("AlertType.SMS and AlertType.Twitter are not supported by the UptimeRobot API");
}
return (await Request<DefaultResponse>("newAlertContact", cancellationToken, new Dictionary<string, string>()
AddAlertResponse response = await Request<AddAlertResponse>("newAlertContact", cancellationToken, new Dictionary<string, string>()
{
{ "alertContactType", ((int)type).ToString() },
{ "alertContactValue", value }
})).Success;
});
Alert alert = response.Alert;
if (alert != null)
{
alert.Type = type;
alert.Value = value;
}
return alert;
}
@@ -75,7 +85,7 @@ namespace UptimeSharp
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="UptimeSharpException"></exception>
public async Task<bool> AddAlert(Alert alert, CancellationToken cancellationToken = default(CancellationToken))
public async Task<Alert> AddAlert(Alert alert, CancellationToken cancellationToken = default(CancellationToken))
{
return await AddAlert(alert.Type, alert.Value, cancellationToken);
}