Esempio n. 1
0
        public void SendNotification(string title, string message, string userKey, PushoverPriority priority)
        {
            var client  = new RestClient(URL);
            var request = new RestRequest(Method.POST);

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

            client.ExecuteAndValidate(request);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority, string sound)
        {
            var client  = new RestClient(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);
        }
Esempio n. 4
0
        private static string ServiceUrlBuilder(string userKey, string token, IEnumerable <string> deviceIds, PushoverPriority priority, int?expire, int?retry, string sound)
        {
            var url = new StringBuilder();

            url.Append($"pover://{userKey}@{token}");

            if (deviceIds.IsAny())
            {
                foreach (var deviceId in deviceIds)
                {
                    url.Append($"/{deviceId}");
                }
            }

            if (priority is not PushoverPriority.Normal)
            {
                url.AppendParam(nameof(priority), priority.ToString());
            }

            if (expire.HasValue)
            {
                url.AppendParam(nameof(expire), expire.ToString());
            }

            if (retry.HasValue)
            {
                url.AppendParam(nameof(retry), retry.ToString());
            }

            if (sound is not null)
            {
                url.AppendParam(nameof(sound), sound);
            }

            return(url.ToString());
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of Pushover Notification Service
 /// </summary>
 /// <param name="appriseUrl">The URL of Apprise API.</param>
 /// <param name="userKey">The user key identifier associated with your Pushover account. This is NOT your email address. The key can be acquired from your Pushover dashboard.</param>
 /// <param name="token">The token associated with your Pushover account.</param>
 /// <param name="deviceIds">The device identifier to send your notification to. By default if one isn't specified then all of devices associated with your account are notified.</param>
 /// <param name="priority">Can be low, moderate, normal, high, or emergency; the default is normal if a priority isn't specified. To send an emergency-priority notification, the retry and expire parameters should be supplied.</param>
 /// <param name="expire">The expire parameter specifies how many seconds your notification will continue to be retried for (every retry seconds). If the notification has not been acknowledged in expire seconds, it will be marked as expired and will stop being sent to the user. Note that the notification is still shown to the user after it is expired, but it will not prompt the user for acknowledgement. This parameter has a maximum value of at most 10800 seconds (3 hours). The default is 3600 seconds (1 hr) if nothing is otherwise specified.</param>
 /// <param name="retry">The retry parameter specifies how often (in seconds) the Pushover servers will send the same notification to the user. In a situation where your user might be in a noisy environment or sleeping, retrying the notification (with sound and vibration) will help get his or her attention. This parameter must have a value of at least 30 seconds between retries. The default is 900 seconds (15 minutes) if nothing is otherwise specified.</param>
 /// <param name="sound">Can optionally identify one of the optional sound effects identified here. The default sound is pushover.</param>
 public Pushover(string appriseUrl, string userKey, string token, IEnumerable <string> deviceIds = null, PushoverPriority priority = PushoverPriority.Normal, int?expire = null, int?retry = null, string sound = null)
 {
     AppriseUrl = appriseUrl;
     ServiceUrl = ServiceUrlBuilder(userKey, token, deviceIds, priority, expire, retry, sound);
 }
Esempio n. 6
0
        public static void LogWithPushover(string pushoverUserKey, string pushoverAppToken, string logFilePath, BackupAction backupAction, PushoverPriority priority, string text, params object[] args)
        {
            Log(logFilePath, System.Enum.GetName(typeof(BackupAction), backupAction) + " " + text, args);

            if (!string.IsNullOrEmpty(pushoverAppToken))
            {
                Utils.SendPushoverMessage(pushoverUserKey, pushoverAppToken, System.Enum.GetName(typeof(BackupAction), backupAction), priority, string.Format(text, args));
            }
        }
Esempio n. 7
0
        public static void SendPushoverMessage(string userKey, string appToken, string title, PushoverPriority priority, string message)
        {
            string timeStamp = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds().ToString();

            try
            {
                NameValueCollection parameters = new NameValueCollection {
                    { "token", appToken },
                    { "user", userKey },
                    { "priority", Convert.ChangeType(priority, priority.GetTypeCode()).ToString() },
                    { "message", message },
                    { "title", title },
                    { "timestamp", timeStamp }
                };

                using (var client = new WebClient())
                {
                    client.UploadValues("https://api.pushover.net/1/messages.json", parameters);

                    System.Threading.Thread.Sleep(2000); // ensures there's at least a 1s gap between messages
                }
            }
            catch (Exception)
            {
                // we ignore any push problems
            }
        }