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."); }
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); }
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); } }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
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); } }
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); }
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>()); }
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); } }
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); } }
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); } }
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); }
private RestClient GetPlexServerClient(PlexServerSettings settings) { return(RestClientFactory.BuildClient(String.Format("http://{0}:{1}", settings.Host, settings.Port))); }
private RestClient GetSubsonicServerClient(SubsonicSettings settings) { return(RestClientFactory.BuildClient(GetBaseUrl(settings, "rest"))); }
private RestClient GetPlexServerClient(PlexServerSettings settings) { var protocol = settings.UseSsl ? "https" : "http"; return(RestClientFactory.BuildClient(string.Format("{0}://{1}:{2}", protocol, settings.Host, settings.Port))); }
private IRestClient BuildClient(NzbVortexSettings settings) { var url = string.Format(@"https://{0}:{1}/api", settings.Host, settings.Port); return(RestClientFactory.BuildClient(url)); }