return alert after adding contact
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user