diff --git a/UptimeSharp/Components/Monitor.cs b/UptimeSharp/Components/Monitor.cs index 75fb432..9d3c259 100644 --- a/UptimeSharp/Components/Monitor.cs +++ b/UptimeSharp/Components/Monitor.cs @@ -9,27 +9,23 @@ namespace UptimeSharp /// public partial class UptimeClient { - /// - /// Retrieves all monitors from UptimeRobot - /// - /// parameters, which are mapped to the officials from http://www.uptimerobot.com/api.asp#methods - /// - public List Retrieve(RetrieveParameters parameters) - { - return Get("getMonitors", parameters.Convert()).Items; - } - /// - /// Retrieves all monitors from UptimeRobot + /// Retrieves specified monitors from UptimeRobot /// + /// monitor list /// - public List Retrieve() + public List Retrieve(int[] monitors = null, float[] customUptimeRatio = null, bool showLog = false, bool showAlerts = true) { - return Retrieve(new RetrieveParameters() + RetrieveParameters parameters = new RetrieveParameters() { - ShowAlerts = true - }); + Monitors = monitors, + CustomUptimeRatio = customUptimeRatio, + ShowAlerts = showAlerts, + ShowLog = showLog + }; + + return Get("getMonitors", parameters.Convert()).Items; } @@ -40,43 +36,18 @@ namespace UptimeSharp /// public Monitor Retrieve(int monitorId) { - return Retrieve(new RetrieveParameters() - { - Monitors = new int[] { monitorId }, - ShowAlerts = true - })[0]; + return Retrieve(new int[] { monitorId })[0]; } - /// - /// Retrieves specified monitors from UptimeRobot - /// - /// monitor list - /// - public List Retrieve(int[] monitors) - { - return Retrieve(new RetrieveParameters() - { - Monitors = monitors, - ShowAlerts = true - }); - } - - - /// /// Deletes a monitor /// - /// The unique identifier for the monitor. + /// The unique identifier for the monitor. /// success state - public bool Delete(int ID) + public bool Delete(int monitorId) { - List parameters = new List() - { - new Parameter() { Name = "monitorID", Value = ID, Type = ParameterType.GetOrPost } - }; - - return Get("deleteMonitor", parameters).Status; + return Get("deleteMonitor", Parameter("monitorID", monitorId)).Status; } @@ -91,105 +62,40 @@ namespace UptimeSharp } - /// /// Creates a monitor. /// - /// The monitor parameters. - /// - /// success state - /// - public bool Add(MonitorParameters parameters) - { - return Get("newMonitor", parameters.Convert()).Status; - } - - - /// - /// Creates a HTTP/IP monitor. - /// - /// The name of the new monitor. - /// The URI or IP to watch. - /// A ID list of existing alerts to notify. - /// - /// success state - /// - public bool Add(string name, string uri, int[] alerts = null) - { - return Add(new MonitorParameters() - { - Name = name, - Uri = uri, - Type = Type.HTTP, - Alerts = alerts - }); - } - - - /// - /// Creates a Port monitor. - /// /// The name of the new monitor. /// The URI or IP to watch. + /// The type of the monitor. /// The subtype of the port. /// The port (only for Subtype.Custom). + /// The keyword value. + /// Type of the keyword. /// A ID list of existing alerts to notify. /// /// success state /// - public bool Add(string name, string uri, Subtype subtype, int? port = null, int[] alerts = null) + public bool Add(string name, string uri, Type type = Type.HTTP, Subtype subtype = Subtype.Unknown, + int? port = null, string keywordValue = null, KeywordType keywordType = KeywordType.Unknown, + int[] alerts = null, string HTTPPassword = null, string HTTPUsername = null) { - return Add(new MonitorParameters() + + MonitorParameters parameters = new MonitorParameters() { Name = name, Uri = uri, - Type = Type.Port, + Type = type, Subtype = subtype, Port = port, - Alerts = alerts - }); - } - - - /// - /// Creates a Keyword monitor. - /// - /// The name of the new monitor. - /// The URI or IP to watch. - /// Type of the keyword. - /// The keyword value. - /// A ID list of existing alerts to notify. - /// - /// success state - /// - public bool Add(string name, string uri, string keyword, KeywordType keywordType = KeywordType.Exists, int[] alerts = null) - { - return Add(new MonitorParameters() - { - Name = name, - Uri = uri, - Type = Type.Keyword, - KeywordValue = keyword, KeywordType = keywordType, - Alerts = alerts - }); - } + KeywordValue = keywordValue, + Alerts = alerts, + HTTPPassword = HTTPPassword, + HTTPUsername = HTTPUsername + }; - - /// - /// Edits a monitor. - /// - /// The monitor unique identifier. - /// The monitor parameters. - /// - /// success state - /// - public bool Modify(int monitorID, MonitorParameters parameters) - { - List paramList = parameters.Convert(); - paramList.Add(Parameter("monitorID", monitorID)); - - return Get("editorMonitor", paramList).Status; + return Get("newMonitor", parameters.Convert()).Status; } diff --git a/UptimeSharp/Models/Parameters/MonitorParameters.cs b/UptimeSharp/Models/Parameters/MonitorParameters.cs index 6a7e766..03ea96f 100644 --- a/UptimeSharp/Models/Parameters/MonitorParameters.cs +++ b/UptimeSharp/Models/Parameters/MonitorParameters.cs @@ -7,7 +7,7 @@ namespace UptimeSharp.Models /// /// All parameters which can be passed for monitor modifications /// - public class MonitorParameters + internal class MonitorParameters { /// /// Gets or sets the name. @@ -102,7 +102,7 @@ namespace UptimeSharp.Models parameters.Add(UptimeClient.Parameter("monitorFriendlyName", Name)); parameters.Add(UptimeClient.Parameter("monitorURL", Uri)); - if(Type != null && (int)Type != 0) + if ((int)Type != 0) { parameters.Add(UptimeClient.Parameter("monitorType", (int)Type)); } diff --git a/UptimeSharp/Models/Parameters/RetrieveParameters.cs b/UptimeSharp/Models/Parameters/RetrieveParameters.cs index e29c0a5..05201ab 100644 --- a/UptimeSharp/Models/Parameters/RetrieveParameters.cs +++ b/UptimeSharp/Models/Parameters/RetrieveParameters.cs @@ -7,7 +7,7 @@ namespace UptimeSharp.Models /// /// All parameters which can be passed for monitor retrieval /// - public class RetrieveParameters + internal class RetrieveParameters { /// /// List of monitor ids @@ -50,8 +50,15 @@ namespace UptimeSharp.Models { List parameters = new List(); - parameters.Add(UptimeClient.Parameter("monitors", String.Join("-", Monitors))); - parameters.Add(UptimeClient.Parameter("customUptimeRatio", String.Join("-", CustomUptimeRatio))); + if (Monitors != null && Monitors.Length > 0) + { + parameters.Add(UptimeClient.Parameter("monitors", String.Join("-", Monitors))); + } + if (CustomUptimeRatio != null && CustomUptimeRatio.Length > 0) + { + parameters.Add(UptimeClient.Parameter("customUptimeRatio", String.Join("-", CustomUptimeRatio))); + } + parameters.Add(UptimeClient.Parameter("showMonitorAlertContacts", (bool)ShowAlerts ? "1" : "0")); if (ShowLog.HasValue)