Files

93 lines
2.5 KiB
C#
Raw Permalink Normal View History

2013-08-18 21:51:04 +02:00
using RestSharp;
using System;
2013-08-18 21:51:04 +02:00
using System.Collections.Generic;
using UptimeSharp.Models;
namespace UptimeSharp
{
/// <summary>
/// UptimeClient
/// </summary>
public partial class UptimeClient
{
/// <summary>
/// Retrieves alerts from UptimeRobot
/// </summary>
/// <param name="alertIDs">Retrieve specified alert contacts by supplying IDs for them.</param>
2013-08-18 21:51:04 +02:00
/// <returns></returns>
public List<Alert> GetAlerts(string[] alertIDs = null)
2013-08-18 21:51:04 +02:00
{
Parameter alerts = Parameter("alertcontacts", alertIDs != null ? string.Join("-", alertIDs) : null);
return Get<AlertResponse>("getAlertContacts", alerts).Items;
2013-08-18 21:51:04 +02:00
}
2013-08-25 16:24:52 +02:00
/// <summary>
/// Retrieves an alert from UptimeRobot
/// </summary>
/// <param name="alertID">The alertID.</param>
/// <returns></returns>
public Alert GetAlert(string alertID)
2013-08-25 16:24:52 +02:00
{
List<Alert> alerts = GetAlerts(new string[] { alertID });
2013-08-25 16:24:52 +02:00
return alerts.ToArray().Length > 0 ? alerts[0] : null;
}
2013-08-18 21:51:04 +02:00
/// <summary>
/// Adds an alert.
/// mobile/SMS alert contacts are not supported yet, see: http://www.uptimerobot.com/api.asp#methods
/// </summary>
/// <param name="type">The type.</param>
/// <param name="value">The value.</param>
/// <returns></returns>
public bool AddAlert(AlertType type, string value)
{
if (type == AlertType.SMS || type == AlertType.Twitter)
2013-08-18 21:51:04 +02:00
{
2013-08-28 00:09:55 +02:00
throw new UptimeSharpException("AlertType.SMS and AlertType.Twitter are not supported by the UptimeRobot API");
}
2013-08-18 21:51:04 +02:00
return Get<DefaultResponse>("newAlertContact",
Parameter("alertContactType", (int)type),
Parameter("alertContactValue", value)
).Status;
2013-08-18 21:51:04 +02:00
}
2013-08-19 21:03:11 +02:00
/// <summary>
/// Adds an alert.
/// mobile/SMS alert contacts are not supported yet, see: http://www.uptimerobot.com/api.asp#methods
/// </summary>
/// <param name="alert">The alert.</param>
/// <returns></returns>
public bool AddAlert(Alert alert)
{
return AddAlert(alert.Type, alert.Value);
2013-08-19 21:03:11 +02:00
}
2013-08-18 21:51:04 +02:00
/// <summary>
/// Removes an alert.
/// </summary>
2013-08-24 01:52:14 +02:00
/// <param name="alertID">The alert ID.</param>
2013-08-18 21:51:04 +02:00
/// <returns></returns>
public bool DeleteAlert(string alertID)
2013-08-18 21:51:04 +02:00
{
return Get<DefaultResponse>("deleteAlertContact", Parameter("alertContactID", alertID)).Status;
2013-08-18 21:51:04 +02:00
}
2013-08-18 21:58:16 +02:00
/// <summary>
/// Removes an alert.
/// </summary>
/// <param name="alert">The alert.</param>
/// <returns></returns>
public bool DeleteAlert(Alert alert)
{
return DeleteAlert(alert.ID);
2013-08-18 21:58:16 +02:00
}
2013-08-18 21:51:04 +02:00
}
}