pushover.el 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. (defgroup pushover nil
  15. "Send notifications to the pushover service."
  16. :group 'communication)
  17. (defcustom pushover-api-key "agd6sapvp5xcdmbuo1qdpc7mddscri"
  18. "Pushover API key."
  19. :type 'string
  20. :group 'pushover)
  21. (defcustom pushover-user-key nil
  22. "Pushover user key."
  23. :type 'string
  24. :group 'pushover)
  25. ;;;### autoload
  26. (cl-defun pushover-send (title message &key url url-title sound (html t) (priority 0) retry expire)
  27. "Send notification to the pushover service.
  28. TITLE is the message title.
  29. MESSAGE is the message itself.
  30. URL is a URL to be shown.
  31. URL-TITLE is the title of the given URL.
  32. SOUND is the sound to be used.
  33. HTML, default t, signals to Pushover that the message is in HTML.
  34. PRIORITY is an integer from -2 to 2, with 0 (mid-priority) being the default.
  35. RETRY is the number of seconds between retries for emergency (2) priority.
  36. EXPIRE is number of seconds before an emergency priority message expires."
  37. (let ((url-request-method "POST")
  38. (url-request-data (concat (format "token=%s&user=%s&title=%s&message=%s&priority=%s&timestamp=%s"
  39. pushover-api-key
  40. pushover-user-key
  41. (url-encode-url title)
  42. (url-encode-url message)
  43. priority
  44. (current-time))
  45. (if html
  46. "&html=1"
  47. "")
  48. (if url
  49. (format "&url=%s" (url-encode-url url))
  50. "")
  51. (if url-title
  52. (format "&url_title=%s" (url-encode-url url-title))
  53. "")
  54. (if sound
  55. (format "&sound=%s" sound)
  56. "")
  57. (if retry
  58. (format "&retry=%s" retry)
  59. "")
  60. (if expire
  61. (format "&expire=%s" expire)
  62. ""))))
  63. (url-retrieve "https://api.pushover.net/1/messages.json" (lambda (status) (kill-buffer (current-buffer)) t))))
  64. (provide 'pushover)
  65. ;;; pushover.el ends here