retrieve/add/delete alert contacts;
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using RestSharp;
|
||||
using System.Collections.Generic;
|
||||
using UptimeSharp.Models;
|
||||
|
||||
namespace UptimeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// UptimeClient
|
||||
/// </summary>
|
||||
public partial class UptimeClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves alerts from UptimeRobot
|
||||
/// </summary>
|
||||
/// <param name="IDs">Retrieve specified alert contacts by supplying IDs for them.</param>
|
||||
/// <returns></returns>
|
||||
public List<Alert> RetrieveAlerts(int[] alertIDs = null)
|
||||
{
|
||||
return Get<AlertResponse>("getAlertContacts").Items;
|
||||
}
|
||||
|
||||
|
||||
/// <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)
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>()
|
||||
{
|
||||
Utilities.CreateParam("alertContactType", (int)type),
|
||||
Utilities.CreateParam("alertContactValue", value)
|
||||
};
|
||||
|
||||
return Get<DefaultResponse>("newAlertContact", parameters).Status;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Removes an alert.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns></returns>
|
||||
public bool DeleteAlert(int alertID)
|
||||
{
|
||||
List<Parameter> parameters = new List<Parameter>()
|
||||
{
|
||||
Utilities.CreateParam("alertContactID", alertID)
|
||||
};
|
||||
|
||||
return Get<DefaultResponse>("deleteAlertContact", parameters).Status;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,15 @@ namespace UptimeSharp.Models
|
||||
[DataMember(Name = "type")]
|
||||
public AlertType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the alert status.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The status.
|
||||
/// </value>
|
||||
[DataMember(Name = "status")]
|
||||
public AlertStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the alert value.
|
||||
/// </summary>
|
||||
@@ -60,4 +69,28 @@ namespace UptimeSharp.Models
|
||||
/// </summary>
|
||||
Boxcar = 4
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The status of the alert contact.
|
||||
/// </summary>
|
||||
public enum AlertStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Unknown
|
||||
/// </summary>
|
||||
Unknown,
|
||||
/// <summary>
|
||||
/// Not activated
|
||||
/// </summary>
|
||||
NotActicated = 0,
|
||||
/// <summary>
|
||||
/// Paused
|
||||
/// </summary>
|
||||
Paused = 1,
|
||||
/// <summary>
|
||||
/// Active
|
||||
/// </summary>
|
||||
Active = 2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace UptimeSharp.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Alert Response
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
internal class AlertResponse : ResponseBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the item dictionary.
|
||||
/// The list is 2 layers deep, so this one is necessary :-/
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The item dictionary.
|
||||
/// </value>
|
||||
[DataMember(Name = "alertcontacts")]
|
||||
public Dictionary<string, List<Alert>> ItemDictionary { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the items.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The items.
|
||||
/// </value>
|
||||
[IgnoreDataMember]
|
||||
public List<Alert> Items
|
||||
{
|
||||
get
|
||||
{
|
||||
return ItemDictionary["alertcontact"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,9 @@ namespace UptimeSharp
|
||||
/// <returns></returns>
|
||||
protected T Request<T>(RestRequest request) where T : new()
|
||||
{
|
||||
// fix content type if wrong determined by RestSharp
|
||||
request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
|
||||
|
||||
IRestResponse<T> response = _restClient.Execute<T>(request);
|
||||
|
||||
LastRequestData = response;
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="APIException.cs" />
|
||||
<Compile Include="Components\Alert.cs" />
|
||||
<Compile Include="Components\Monitor.cs" />
|
||||
<Compile Include="JsonDeserializer.cs" />
|
||||
<Compile Include="Models\Alert.cs" />
|
||||
@@ -59,6 +60,7 @@
|
||||
<Compile Include="Models\Monitor.cs" />
|
||||
<Compile Include="Models\Parameters\MonitorParameters.cs" />
|
||||
<Compile Include="Models\Parameters\RetrieveParameters.cs" />
|
||||
<Compile Include="Models\Response\AlertResponse.cs" />
|
||||
<Compile Include="Models\Response\DefaultResponse.cs" />
|
||||
<Compile Include="Models\Response\ResponseBase.cs" />
|
||||
<Compile Include="Models\Response\RetrieveResponse.cs" />
|
||||
|
||||
Reference in New Issue
Block a user