using RestSharp; using System; using System.Collections.Generic; using UptimeSharp.Models; namespace UptimeSharp { /// /// UptimeClient /// public partial class UptimeClient { /// /// Retrieves alerts from UptimeRobot /// /// Retrieve specified alert contacts by supplying IDs for them. /// public List GetAlerts(string[] alertIDs = null) { Parameter alerts = Parameter("alertcontacts", alertIDs != null ? string.Join("-", alertIDs) : null); return Get("getAlertContacts", alerts).Items; } /// /// Retrieves an alert from UptimeRobot /// /// The alertID. /// public Alert GetAlert(string alertID) { List alerts = GetAlerts(new string[] { alertID }); return alerts.ToArray().Length > 0 ? alerts[0] : null; } /// /// Adds an alert. /// mobile/SMS alert contacts are not supported yet, see: http://www.uptimerobot.com/api.asp#methods /// /// The type. /// The value. /// public bool AddAlert(AlertType type, string value) { if (type == AlertType.SMS || type == AlertType.Twitter) { throw new UptimeSharpException("AlertType.SMS and AlertType.Twitter are not supported by the UptimeRobot API"); } return Get("newAlertContact", Parameter("alertContactType", (int)type), Parameter("alertContactValue", value) ).Status; } /// /// Adds an alert. /// mobile/SMS alert contacts are not supported yet, see: http://www.uptimerobot.com/api.asp#methods /// /// The alert. /// public bool AddAlert(Alert alert) { return AddAlert(alert.Type, alert.Value); } /// /// Removes an alert. /// /// The alert ID. /// public bool DeleteAlert(string alertID) { return Get("deleteAlertContact", Parameter("alertContactID", alertID)).Status; } /// /// Removes an alert. /// /// The alert. /// public bool DeleteAlert(Alert alert) { return DeleteAlert(alert.ID); } } }