pushover.el 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ;;; pushover.el --- Pushover API Access
  2. ;; Copyright (C) 2016 Samuel Flint
  3. ;; Author: Samuel W. Flint <swflint@flintfam.org>
  4. ;; Version: 1.2
  5. ;; Package-Requires: ((cl-lib "0.5"))
  6. ;; Keywords: notifications
  7. ;; URL: http://github.com/swflint/pushover.el
  8. ;; License: GNU General Public License version 3, or (at your option) any later version
  9. ;; This file is free software; you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 3, or (at your option)
  12. ;; any later version.
  13. ;; This file is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;;
  21. ;; This library provides a single function, pushover-send, which is
  22. ;; used to send notifications using the pushover service.
  23. ;;; Code:
  24. (require 'cl-lib)
  25. (defgroup pushover nil
  26. "Send notifications to the pushover service."
  27. :group 'communication)
  28. (defcustom pushover-api-key "agd6sapvp5xcdmbuo1qdpc7mddscri"
  29. "Pushover API key."
  30. :type 'string
  31. :group 'pushover)
  32. (defcustom pushover-user-key nil
  33. "Pushover user key."
  34. :type 'string
  35. :group 'pushover)
  36. ;;;### autoload
  37. (cl-defun pushover-send (title message &key url url-title sound (html t) (priority 0) retry expire)
  38. "Send notification to the pushover service.
  39. TITLE is the message title.
  40. MESSAGE is the message itself.
  41. URL is a URL to be shown.
  42. URL-TITLE is the title of the given URL.
  43. SOUND is the sound to be used.
  44. HTML, default t, signals to Pushover that the message is in HTML.
  45. PRIORITY is an integer from -2 to 2, with 0 (mid-priority) being the default.
  46. RETRY is the number of seconds between retries for emergency (2) priority.
  47. EXPIRE is number of seconds before an emergency priority message expires."
  48. (let ((url-request-method "POST")
  49. (url-request-data (concat (format "token=%s&user=%s&title=%s&message=%s&priority=%s&timestamp=%s"
  50. pushover-api-key
  51. pushover-user-key
  52. (url-encode-url title)
  53. (url-encode-url message)
  54. priority
  55. (current-time))
  56. (if html
  57. "&html=1"
  58. "")
  59. (if url
  60. (format "&url=%s" (url-encode-url url))
  61. "")
  62. (if url-title
  63. (format "&url_title=%s" (url-encode-url url-title))
  64. "")
  65. (if sound
  66. (format "&sound=%s" sound)
  67. "")
  68. (if retry
  69. (format "&retry=%s" retry)
  70. "")
  71. (if expire
  72. (format "&expire=%s" expire)
  73. ""))))
  74. (url-retrieve "https://api.pushover.net/1/messages.json" (lambda (status) (kill-buffer (current-buffer)) t))))
  75. (when (fboundp 'alert-define-style)
  76. (alert-define-style 'pushover :title "Pushover Alerter"
  77. :notifier (lambda (info)
  78. (let ((title (plist-get info :title))
  79. (message (plist-get info :message)))
  80. (pushover-send title message)))))
  81. (provide 'pushover)
  82. ;;; pushover.el ends here