예제 #1
0
파일: JoinProxy.cs 프로젝트: novarr/Comarr
        private void SendNotification(string title, string message, RestRequest request, JoinSettings settings)
        {
            var client = RestClientFactory.BuildClient(URL);

            if (!string.IsNullOrEmpty(settings.DeviceIds))
            {
                request.AddParameter("deviceIds", settings.DeviceIds);
            }
            else
            {
                request.AddParameter("deviceId", "group.all");
            }

            request.AddParameter("apikey", settings.ApiKey);
            request.AddParameter("title", title);
            request.AddParameter("text", message);
            request.AddParameter("icon", "https://cdn.rawgit.com/Sonarr/Sonarr/develop/Logo/256.png"); // Use the Sonarr logo.

            var response = client.ExecuteAndValidate(request);
            var res      = Json.Deserialize <JoinResponseModel>(response.Content);

            if (res.success)
            {
                return;
            }

            if (res.userAuthError)
            {
                throw new JoinAuthException("Authentication failed.");
            }

            if (res.errorMessage != null)
            {
                // Unfortunately hard coding this string here is the only way to determine that there aren't any devices to send to.
                // There isn't an enum or flag contained in the response that can be used instead.
                if (res.errorMessage.Equals("No devices to send to"))
                {
                    throw new JoinInvalidDeviceException(res.errorMessage);
                }
                // Oddly enough, rather than give us an "Invalid API key", the Join API seems to assume the key is valid,
                // but fails when doing a device lookup associated with that key.
                // In our case we are using "deviceIds" rather than "deviceId" so when the singular form error shows up
                // we know the API key was the fault.
                else if (res.errorMessage.Equals("No device to send message to"))
                {
                    throw new JoinAuthException("Authentication failed.");
                }
                throw new JoinException(res.errorMessage);
            }

            throw new JoinException("Unknown error. Join message failed to send.");
        }
예제 #2
0
        public void SendNotification(string title, string message, TelegramSettings settings)
        {
            //Format text to add the title before and bold using markdown
            var text    = $"*{title}*\n{message}";
            var client  = RestClientFactory.BuildClient(URL);
            var request = new RestRequest("bot{token}/sendmessage", Method.POST);

            request.AddUrlSegment("token", settings.BotToken);
            request.AddParameter("chat_id", settings.ChatId);
            request.AddParameter("parse_mode", "Markdown");
            request.AddParameter("text", text);

            client.ExecuteAndValidate(request);
        }
예제 #3
0
 public void NotifyWebhook(WebhookPayload body, WebhookSettings settings)
 {
     try {
         var client  = RestClientFactory.BuildClient(settings.Url);
         var request = new RestRequest((Method)settings.Method);
         request.RequestFormat = DataFormat.Json;
         request.AddBody(body);
         client.ExecuteAndValidate(request);
     }
     catch (RestException ex)
     {
         throw new WebhookException("Unable to post to webhook: {0}", ex, ex.Message);
     }
 }
예제 #4
0
        public void SendNotification(string title, string message, string apiKey, NotifyMyAndroidPriority priority)
        {
            var client = RestClientFactory.BuildClient(URL);
            var request = new RestRequest("notify", Method.POST);
            request.RequestFormat = DataFormat.Xml;
            request.AddParameter("apikey", apiKey);
            request.AddParameter("application", "Radarr");
            request.AddParameter("event", title);
            request.AddParameter("description", message);
            request.AddParameter("priority", (int)priority);

            var response = client.ExecuteAndValidate(request);
            ValidateResponse(response);
        }
예제 #5
0
        private IRestClient BuildClient(XbmcSettings settings)
        {
            var url = string.Format(@"http://{0}/jsonrpc", settings.Address);

            _logger.Debug("Url: " + url);

            var client = RestClientFactory.BuildClient(url);

            if (!settings.Username.IsNullOrWhiteSpace())
            {
                client.Authenticator = new HttpBasicAuthenticator(settings.Username, settings.Password);
            }

            return(client);
        }
예제 #6
0
        public void SendNotification(string title, string message, TelegramSettings settings)
        {
            //Format text to add the title before and bold using markdown
            var text    = $"<b>{HttpUtility.HtmlEncode(title)}</b>\n{HttpUtility.HtmlEncode(message)}";
            var client  = RestClientFactory.BuildClient(URL);
            var request = new RestRequest("bot{token}/sendmessage", Method.POST);

            request.AddUrlSegment("token", settings.BotToken);
            request.AddParameter("chat_id", settings.ChatId);
            request.AddParameter("parse_mode", "HTML");
            request.AddParameter("text", text);
            request.AddParameter("disable_notification", settings.SendSilently);

            client.ExecuteAndValidate(request);
        }
예제 #7
0
        private IRestClient BuildClient(TransmissionSettings settings)
        {
            var protocol = settings.UseSsl ? "https" : "http";

            var url = String.Format(@"{0}://{1}:{2}/{3}/rpc", protocol, settings.Host, settings.Port, settings.UrlBase.Trim('/'));

            var restClient = RestClientFactory.BuildClient(url);

            restClient.FollowRedirects = false;

            if (!settings.Username.IsNullOrWhiteSpace())
            {
                restClient.Authenticator = new HttpBasicAuthenticator(settings.Username, settings.Password);
            }

            return(restClient);
        }
예제 #8
0
        private IRestClient BuildClient(NzbgetSettings settings)
        {
            var protocol = settings.UseSsl ? "https" : "http";

            var url = String.Format("{0}://{1}:{2}/jsonrpc",
                                    protocol,
                                    settings.Host,
                                    settings.Port);

            _logger.Debug("Url: " + url);

            var client = RestClientFactory.BuildClient(url);

            client.Authenticator = new HttpBasicAuthenticator(settings.Username, settings.Password);

            return(client);
        }
예제 #9
0
        public void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority, string sound)
        {
            var client  = RestClientFactory.BuildClient(URL);
            var request = new RestRequest(Method.POST);

            request.AddParameter("token", apiKey);
            request.AddParameter("user", userKey);
            request.AddParameter("title", title);
            request.AddParameter("message", message);
            request.AddParameter("priority", (int)priority);

            if (!sound.IsNullOrWhiteSpace())
            {
                request.AddParameter("sound", sound);
            }


            client.ExecuteAndValidate(request);
        }
예제 #10
0
        private IRestClient BuildClient(string action, SabnzbdSettings settings)
        {
            var protocol = settings.UseSsl ? "https" : "http";

            var authentication = settings.ApiKey.IsNullOrWhiteSpace() ?
                                 String.Format("ma_username={0}&ma_password={1}", settings.Username, Uri.EscapeDataString(settings.Password)) :
                                 String.Format("apikey={0}", settings.ApiKey);

            var url = String.Format(@"{0}://{1}:{2}/api?{3}&{4}&output=json",
                                    protocol,
                                    settings.Host,
                                    settings.Port,
                                    action,
                                    authentication);

            _logger.Debug("Url: " + url);

            return(RestClientFactory.BuildClient(url));
        }
예제 #11
0
파일: Slack.cs 프로젝트: novarr/Comarr
 private void NotifySlack(SlackPayload payload)
 {
     try
     {
         var client  = RestClientFactory.BuildClient(Settings.WebHookUrl);
         var request = new RestRequest(Method.POST)
         {
             RequestFormat  = DataFormat.Json,
             JsonSerializer = new JsonNetSerializer()
         };
         request.AddBody(payload);
         client.ExecuteAndValidate(request);
     }
     catch (RestException ex)
     {
         _logger.Error(ex, "Unable to post payload {0}", payload);
         throw new SlackExeption("Unable to post payload", ex);
     }
 }
예제 #12
0
        private IRestClient BuildClient(UTorrentSettings settings)
        {
            var url = string.Format(@"http://{0}:{1}",
                                    settings.Host,
                                    settings.Port);

            var restClient = RestClientFactory.BuildClient(url);

            restClient.Authenticator   = new HttpBasicAuthenticator(settings.Username, settings.Password);
            restClient.CookieContainer = _cookieContainer;

            if (_authToken.IsNullOrWhiteSpace())
            {
                // µTorrent requires a token and cookie for authentication. The cookie is set automatically when getting the token.
                _authToken = GetAuthToken(restClient);
            }

            return(restClient);
        }
예제 #13
0
        public List <PushBulletDevice> GetDevices(PushBulletSettings settings)
        {
            try
            {
                var client  = RestClientFactory.BuildClient(DEVICE_URL);
                var request = new RestRequest(Method.GET);

                client.Authenticator = new HttpBasicAuthenticator(settings.ApiKey, string.Empty);
                var response = client.ExecuteAndValidate(request);

                return(Json.Deserialize <PushBulletDevicesResponse>(response.Content).Devices);
            }
            catch (RestException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Error(ex, "Access token is invalid");
                    throw;
                }
            }

            return(new List <PushBulletDevice>());
        }
예제 #14
0
        private void SendNotification(string title, string message, RestRequest request, JoinSettings settings)
        {
            try
            {
                var client = RestClientFactory.BuildClient(URL);

                request.AddParameter("deviceId", "group.all");
                request.AddParameter("apikey", settings.APIKey);
                request.AddParameter("title", title);
                request.AddParameter("text", message);
                request.AddParameter("icon", "https://cdn.rawgit.com/Sonarr/Sonarr/develop/Logo/256.png"); // Use the Sonarr logo.

                var response = client.ExecuteAndValidate(request);
                var res      = Json.Deserialize <JoinResponseModel>(response.Content);

                if (res.success)
                {
                    return;
                }

                if (res.errorMessage != null)
                {
                    throw new JoinException(res.errorMessage);
                }

                if (res.userAuthError)
                {
                    throw new JoinAuthException("Authentication failed.");
                }

                throw new JoinException("Unknown error. Join message failed to send.");
            }
            catch (Exception e)
            {
                throw new JoinException(e.Message, e);
            }
        }
예제 #15
0
        private void SendNotification(string title, string message, RestRequest request, BoxcarSettings settings)
        {
            try
            {
                var client = RestClientFactory.BuildClient(URL);

                request.AddParameter("user_credentials", settings.Token);
                request.AddParameter("notification[title]", title);
                request.AddParameter("notification[long_message]", message);
                request.AddParameter("notification[source_name]", "Sonarr");

                client.ExecuteAndValidate(request);
            }
            catch (RestException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.ErrorException("Access Token is invalid: " + ex.Message, ex);
                    throw;
                }

                throw new BoxcarException("Unable to send text message: " + ex.Message, ex);
            }
        }
예제 #16
0
        private void SendNotification(string title, string message, RestRequest request, PushBulletSettings settings)
        {
            try
            {
                var client = RestClientFactory.BuildClient(URL);

                request.AddParameter("type", "note");
                request.AddParameter("title", title);
                request.AddParameter("body", message);

                client.Authenticator = new HttpBasicAuthenticator(settings.ApiKey, string.Empty);
                client.ExecuteAndValidate(request);
            }
            catch (RestException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.ErrorException("API Key is invalid: " + ex.Message, ex);
                    throw;
                }

                throw new PushBulletException("Unable to send text message: {0}", ex, ex.Message);
            }
        }
예제 #17
0
        public void SendNotification(String title, String message, PushalotSettings settings)
        {
            var client  = RestClientFactory.BuildClient(URL);
            var request = BuildRequest();

            request.AddParameter("Source", "NzbDrone");
            request.AddParameter("Image", "https://raw.githubusercontent.com/NzbDrone/NzbDrone/master/Logo/128.png");

            request.AddParameter("Title", title);
            request.AddParameter("Body", message);
            request.AddParameter("AuthorizationToken", settings.AuthToken);

            if ((PushalotPriority)settings.Priority == PushalotPriority.Important)
            {
                request.AddParameter("IsImportant", true);
            }

            if ((PushalotPriority)settings.Priority == PushalotPriority.Silent)
            {
                request.AddParameter("IsSilent", true);
            }

            client.ExecuteAndValidate(request);
        }
예제 #18
0
 private RestClient GetPlexServerClient(PlexServerSettings settings)
 {
     return(RestClientFactory.BuildClient(String.Format("http://{0}:{1}", settings.Host, settings.Port)));
 }
예제 #19
0
 private RestClient GetSubsonicServerClient(SubsonicSettings settings)
 {
     return(RestClientFactory.BuildClient(GetBaseUrl(settings, "rest")));
 }
예제 #20
0
        private RestClient GetPlexServerClient(PlexServerSettings settings)
        {
            var protocol = settings.UseSsl ? "https" : "http";

            return(RestClientFactory.BuildClient(string.Format("{0}://{1}:{2}", protocol, settings.Host, settings.Port)));
        }
예제 #21
0
        private IRestClient BuildClient(NzbVortexSettings settings)
        {
            var url = string.Format(@"https://{0}:{1}/api", settings.Host, settings.Port);

            return(RestClientFactory.BuildClient(url));
        }