pushover.el 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ;;; pushover.el --- Pushover API Access
  2. ;; Copyright (C) 2016 Samuel Flint
  3. ;; Author: Samuel W. Flint <swflint@flintfam.org>
  4. ;; Version: 1.0
  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. (defconst *pushover-api-key* "agd6sapvp5xcdmbuo1qdpc7mddscri")
  14. (defvar *pushover-user-key* nil)
  15. (cl-defun pushover-send (title message &key url url-title sound (html t) (priority 0) retry expire)
  16. "TITLE MESSAGE &KEY URL URL-TITLE SOUND HTML PRIORITY RETRY EXPIRE
  17. TITLE is the message title.
  18. MESSAGE is the message itself.
  19. URL is a URL to be shown.
  20. URL-TITLE is the title of the given URL.
  21. SOUND is the sound to be used.
  22. HTML, default t, signals to Pushover that the message is in HTML.
  23. PRIORITY is an integer from -2 to 2, with 0 (mid-priority) being the default.
  24. RETRY is the number of seconds between retries for emergency (2) priority.
  25. EXPIRE is number of seconds before an emergency priority message expires."
  26. (let ((url-request-method "POST")
  27. (url-request-data (concat (format "token=%s&user=%s&title=%s&message=%s&priority=%s&timestamp=%s"
  28. *pushover-api-key*
  29. *pushover-user-key*
  30. (url-encode-url title)
  31. (url-encode-url message)
  32. priority
  33. (current-time))
  34. (if html
  35. "&html=1"
  36. "")
  37. (if url
  38. (format "&url=%s" (url-encode-url url))
  39. "")
  40. (if url-title
  41. (format "&url_title=%s" (url-encode-url url-title))
  42. "")
  43. (if sound
  44. (format "&sound=%s" sound)
  45. "")
  46. (if retry
  47. (format "&retry=%s" retry)
  48. "")
  49. (if expire
  50. (format "&expire=%s" expire)
  51. ""))))
  52. (url-retrieve "https://api.pushover.net/1/messages.json" (lambda (status) (kill-buffer (current-buffer)) t))))
  53. (provide 'pushover)
  54. ;;; pushover.el ends here