mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Fixed: New device_iden from PushBullet can be used
This commit is contained in:
parent
9b0114714d
commit
5ada7efefc
@ -7,18 +7,18 @@ namespace NzbDrone.Core.Notifications.PushBullet
|
|||||||
{
|
{
|
||||||
public interface IPushBulletProxy
|
public interface IPushBulletProxy
|
||||||
{
|
{
|
||||||
void SendNotification(string title, string message, string apiKey, long deviceId);
|
void SendNotification(string title, string message, string apiKey, string deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PushBulletProxy : IPushBulletProxy, IExecute<TestPushBulletCommand>
|
public class PushBulletProxy : IPushBulletProxy, IExecute<TestPushBulletCommand>
|
||||||
{
|
{
|
||||||
private const string URL = "https://api.pushbullet.com/api/pushes";
|
private const string URL = "https://api.pushbullet.com/api/pushes";
|
||||||
|
|
||||||
public void SendNotification(string title, string message, string apiKey, long deviceId)
|
public void SendNotification(string title, string message, string apiKey, string deviceId)
|
||||||
{
|
{
|
||||||
var client = new RestClient(URL);
|
var client = new RestClient(URL);
|
||||||
var request = new RestRequest(Method.POST);
|
var request = BuildRequest(deviceId);
|
||||||
request.AddParameter("device_id", deviceId);
|
|
||||||
request.AddParameter("type", "note");
|
request.AddParameter("type", "note");
|
||||||
request.AddParameter("title", title);
|
request.AddParameter("title", title);
|
||||||
request.AddParameter("body", message);
|
request.AddParameter("body", message);
|
||||||
@ -27,6 +27,24 @@ public void SendNotification(string title, string message, string apiKey, long d
|
|||||||
client.ExecuteAndValidate(request);
|
client.ExecuteAndValidate(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RestRequest BuildRequest(string deviceId)
|
||||||
|
{
|
||||||
|
var request = new RestRequest(Method.POST);
|
||||||
|
long integerId;
|
||||||
|
|
||||||
|
if (Int64.TryParse(deviceId, out integerId))
|
||||||
|
{
|
||||||
|
request.AddParameter("device_id", integerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
request.AddParameter("device_iden", deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
public void Execute(TestPushBulletCommand message)
|
public void Execute(TestPushBulletCommand message)
|
||||||
{
|
{
|
||||||
const string title = "Test Notification";
|
const string title = "Test Notification";
|
||||||
|
@ -11,7 +11,7 @@ public class PushBulletSettingsValidator : AbstractValidator<PushBulletSettings>
|
|||||||
public PushBulletSettingsValidator()
|
public PushBulletSettingsValidator()
|
||||||
{
|
{
|
||||||
RuleFor(c => c.ApiKey).NotEmpty();
|
RuleFor(c => c.ApiKey).NotEmpty();
|
||||||
RuleFor(c => c.DeviceId).GreaterThan(0);
|
RuleFor(c => c.DeviceId).NotEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,13 +23,13 @@ public class PushBulletSettings : IProviderConfig
|
|||||||
public String ApiKey { get; set; }
|
public String ApiKey { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(1, Label = "Device ID")]
|
[FieldDefinition(1, Label = "Device ID")]
|
||||||
public Int64 DeviceId { get; set; }
|
public String DeviceId { get; set; }
|
||||||
|
|
||||||
public bool IsValid
|
public bool IsValid
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return !String.IsNullOrWhiteSpace(ApiKey) && DeviceId > 0;
|
return !String.IsNullOrWhiteSpace(ApiKey) && !String.IsNullOrWhiteSpace(DeviceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,6 @@ public override bool SendUpdatesToClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public string ApiKey { get; set; }
|
public string ApiKey { get; set; }
|
||||||
public long DeviceId { get; set; }
|
public string DeviceId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user