public void SendNotification(string title, string message, string apiKey, ProwlPriority priority = ProwlPriority.Normal, string url = null) { try { var requestBuilder = new HttpRequestBuilder(PUSH_URL); var request = requestBuilder.Post() .AddFormParameter("apikey", apiKey) .AddFormParameter("application", BuildInfo.AppName) .AddFormParameter("event", title) .AddFormParameter("description", message) .AddFormParameter("priority", priority) .AddFormParameter("url", url) .Build(); _httpClient.Post(request); } catch (HttpException ex) { if (ex.Response.StatusCode == HttpStatusCode.Unauthorized) { _logger.Error(ex, "Apikey is invalid: {0}", apiKey); throw new ProwlException("Apikey is invalid", ex); } throw new ProwlException("Unable to send text message: " + ex.Message, ex); } catch (WebException ex) { throw new ProwlException("Failed to connect to prowl, please check your settings.", ex); } }
private static string ServiceUrlBuilder(string apiKey, string providerKey, ProwlPriority priority) { var url = new StringBuilder(); url.Append($"prowl://{apiKey}"); if (!string.IsNullOrWhiteSpace(providerKey)) { url.Append($"/{providerKey}"); } if (priority is not ProwlPriority.Normal) { url.AppendParam(nameof(priority), priority.ToString()); } return(url.ToString()); }
public static void Notify(string source, string description, ProwlPriority priority) { Uri URI = new Uri("https://api.prowlapp.com/publicapi/add"); foreach (string key in Global.prowl_key) { List<string> parameters = new List<string>(); parameters.Add("apikey=" + key); parameters.Add("priority= " + (int)priority); parameters.Add("application=" + Global.event_source); parameters.Add("event=" + source); parameters.Add("description=" + description); WebClient client = new WebClient(); client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; client.UploadStringAsync(URI, string.Join("&", parameters.ToArray())); client.UploadStringCompleted += client_UploadStringCompleted; } }
/// <summary> /// Initializes a new instance of Prowl Notification Service /// </summary> /// <param name="appriseUrl">The URL of Apprise API.</param> /// <param name="apiKey">The API Key provided to you after you create yourself a Prowl account.</param> /// <param name="providerKey">The Provider Key is only required if you have been whitelisted.</param> /// <param name="priority">Can be low, moderate, normal, high, or emergency; the default is normal if a priority isn't specified.</param> public Prowl(string appriseUrl, string apiKey, string providerKey = null, ProwlPriority priority = ProwlPriority.Normal) { AppriseUrl = appriseUrl; ServiceUrl = ServiceUrlBuilder(apiKey, providerKey, priority); }