pushover.el 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. ;;; Commentary:
  9. ;;
  10. ;; This library provides a single function, pushover-send, which is
  11. ;; used to send notifications using the pushover service.
  12. ;;; Code:
  13. (require 'cl-lib)
  14. (defconst pushover-api-key "agd6sapvp5xcdmbuo1qdpc7mddscri")
  15. (defvar pushover-user-key nil)
  16. ;;;### autoload
  17. (cl-defun pushover-send (title message &key url url-title sound (html t) (priority 0) retry expire)
  18. "TITLE MESSAGE &KEY URL URL-TITLE SOUND HTML PRIORITY RETRY EXPIRE
  19. TITLE is the message title.
  20. MESSAGE is the message itself.
  21. URL is a URL to be shown.
  22. URL-TITLE is the title of the given URL.
  23. SOUND is the sound to be used.
  24. HTML, default t, signals to Pushover that the message is in HTML.
  25. PRIORITY is an integer from -2 to 2, with 0 (mid-priority) being the default.
  26. RETRY is the number of seconds between retries for emergency (2) priority.
  27. EXPIRE is number of seconds before an emergency priority message expires."
  28. (let ((url-request-method "POST")
  29. (url-request-data (concat (format "token=%s&user=%s&title=%s&message=%s&priority=%s&timestamp=%s"
  30. pushover-api-key
  31. pushover-user-key
  32. (url-encode-url title)
  33. (url-encode-url message)
  34. priority
  35. (current-time))
  36. (if html
  37. "&html=1"
  38. "")
  39. (if url
  40. (format "&url=%s" (url-encode-url url))
  41. "")
  42. (if url-title
  43. (format "&url_title=%s" (url-encode-url url-title))
  44. "")
  45. (if sound
  46. (format "&sound=%s" sound)
  47. "")
  48. (if retry
  49. (format "&retry=%s" retry)
  50. "")
  51. (if expire
  52. (format "&expire=%s" expire)
  53. ""))))
  54. (url-retrieve "https://api.pushover.net/1/messages.json" (lambda (status) (kill-buffer (current-buffer)) t))))
  55. (provide 'pushover)
  56. ;;; pushover.el ends here