From d9bef59ec21c4309d36d274d63e6785d6ee1c7fe Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 28 Oct 2011 01:14:13 -0700 Subject: [PATCH] Twitter notifications working from end-to-end. --- NzbDrone.Core/CentralDispatch.cs | 1 + NzbDrone.Core/NzbDrone.Core.csproj | 1 + .../Providers/Core/ConfigProvider.cs | 14 ++++++ .../Providers/ExternalNotification/Twitter.cs | 44 +++++++++++++++++++ .../Controllers/SettingsController.cs | 15 ++++++- .../Views/Settings/Notifications.cshtml | 8 ++-- 6 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 NzbDrone.Core/Providers/ExternalNotification/Twitter.cs diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 47c90a29d..276551bf1 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -106,6 +106,7 @@ namespace NzbDrone.Core { _kernel.Bind().To(); _kernel.Bind().To(); + _kernel.Bind().To(); var notifiers = _kernel.GetAll(); _kernel.Get().InitializeNotifiers(notifiers.ToList()); diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index c8358226f..d91b26a96 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -222,6 +222,7 @@ + diff --git a/NzbDrone.Core/Providers/Core/ConfigProvider.cs b/NzbDrone.Core/Providers/Core/ConfigProvider.cs index e2cb6cb3c..a10bccc6d 100644 --- a/NzbDrone.Core/Providers/Core/ConfigProvider.cs +++ b/NzbDrone.Core/Providers/Core/ConfigProvider.cs @@ -312,6 +312,20 @@ namespace NzbDrone.Core.Providers.Core set { SetValue("SmtpToAddresses", value); } } + public virtual Boolean TwitterNotifyOnGrab + { + get { return GetValueBoolean("TwitterNotifyOnGrab"); } + + set { SetValue("TwitterNotifyOnGrab", value); } + } + + public virtual Boolean TwitterNotifyOnDownload + { + get { return GetValueBoolean("TwitterNotifyOnDownload"); } + + set { SetValue("TwitterNotifyOnDownload", value); } + } + public virtual string TwitterAccessToken { get { return GetValue("TwitterAccessToken", String.Empty); } diff --git a/NzbDrone.Core/Providers/ExternalNotification/Twitter.cs b/NzbDrone.Core/Providers/ExternalNotification/Twitter.cs new file mode 100644 index 000000000..79fae1a9a --- /dev/null +++ b/NzbDrone.Core/Providers/ExternalNotification/Twitter.cs @@ -0,0 +1,44 @@ +using System; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Repository; + +namespace NzbDrone.Core.Providers.ExternalNotification +{ + public class Twitter : ExternalNotificationBase + { + private readonly TwitterProvider _twitterProvider; + + public Twitter(ConfigProvider configProvider, TwitterProvider twitterProvider) + : base(configProvider) + { + _twitterProvider = twitterProvider; + } + + public override string Name + { + get { return "Twitter"; } + } + + public override void OnGrab(string message) + { + if (_configProvider.TwitterNotifyOnGrab) + { + _logger.Trace("Sending Notification to Twitter (On Grab)"); + _twitterProvider.SendTweet("Download Started: " + message); + } + } + + public override void OnDownload(string message, Series series) + { + if (_configProvider.TwitterNotifyOnDownload) + { + _logger.Trace("Sending Notification to Twitter (On Grab)"); + _twitterProvider.SendTweet("Downloaded Complete: " + message); + } + } + + public override void OnRename(string message, Series series) + { + } + } +} diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index eb6f0e707..89ef7aedf 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -170,7 +170,10 @@ namespace NzbDrone.Web.Controllers SmtpUsername = _configProvider.SmtpUsername, SmtpPassword = _configProvider.SmtpPassword, SmtpFromAddress = _configProvider.SmtpFromAddress, - SmtpToAddresses = _configProvider.SmtpToAddresses + SmtpToAddresses = _configProvider.SmtpToAddresses, + TwitterEnabled = _externalNotificationProvider.GetSettings(typeof(Twitter)).Enable, + TwitterNotifyOnGrab = _configProvider.TwitterNotifyOnGrab, + TwitterNotifyOnDownload = _configProvider.TwitterNotifyOnDownload }; return View(model); @@ -449,7 +452,7 @@ namespace NzbDrone.Web.Controllers _externalNotificationProvider.SaveSettings(smtpSettings); _configProvider.SmtpNotifyOnGrab = data.SmtpNotifyOnGrab; - _configProvider.SmtpNotifyOnGrab = data.SmtpNotifyOnDownload; + _configProvider.SmtpNotifyOnDownload = data.SmtpNotifyOnDownload; _configProvider.SmtpServer = data.SmtpServer; _configProvider.SmtpPort = data.SmtpPort; _configProvider.SmtpUseSsl = data.SmtpUseSsl; @@ -458,6 +461,14 @@ namespace NzbDrone.Web.Controllers _configProvider.SmtpFromAddress = data.SmtpFromAddress; _configProvider.SmtpToAddresses = data.SmtpToAddresses; + //Twitter + var twitterSettings = _externalNotificationProvider.GetSettings(typeof(Twitter)); + twitterSettings.Enable = data.TwitterEnabled; + _externalNotificationProvider.SaveSettings(twitterSettings); + + _configProvider.TwitterNotifyOnGrab = data.TwitterNotifyOnGrab; + _configProvider.TwitterNotifyOnDownload = data.TwitterNotifyOnDownload; + return GetSuccessResult(); } diff --git a/NzbDrone.Web/Views/Settings/Notifications.cshtml b/NzbDrone.Web/Views/Settings/Notifications.cshtml index 0d306a377..6f2de624d 100644 --- a/NzbDrone.Web/Views/Settings/Notifications.cshtml +++ b/NzbDrone.Web/Views/Settings/Notifications.cshtml @@ -54,19 +54,19 @@
-
- @{Html.RenderPartial("Twitter", Model);} -
@{Html.RenderPartial("Xbmc", Model);}
@{Html.RenderPartial("Smtp", Model);}
+
+ @{Html.RenderPartial("Twitter", Model);} +