Emacs library to control Basecamp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.3KB

  1. ;;; libbcel-actions.el --- Functions to act on Basecamp entities -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2019 Damien Cassou
  3. ;; Author: Damien Cassou <damien@cassou.me>
  4. ;; Url: https://gitlab.petton.fr/bcel/libbcel
  5. ;; Package-requires: ((emacs "26.1"))
  6. ;; Version: 0.4.0
  7. ;; This program is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; This program is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; A set of methods to modify Basecamp entities.
  19. ;;; Code:
  20. (require 'libbcel-client)
  21. (require 'libbcel-structs)
  22. (require 'libbcel-util)
  23. (cl-defgeneric libbcel-actions-todo-toggle (entity &optional callback)
  24. "Toggle the completed state of ENTITY.
  25. When finished, execute CALLBACK if non-nil.")
  26. (cl-defmethod libbcel-actions-todo-toggle ((todo libbcel-todo) &optional callback)
  27. "Toggle the completed state of TODO. When done, execute CALLBACK if non-nil."
  28. (if (libbcel-todo-completed todo)
  29. (libbcel-actions-todo-uncomplete todo callback)
  30. (libbcel-actions-todo-complete todo callback)))
  31. (cl-defmethod libbcel-actions-todo-toggle ((todos list) &optional callback)
  32. "Toggle the completed state of all TODOS. When done, execute CALLBACK if non-nil."
  33. (libbcel-util-async-mapc
  34. #'libbcel-actions-todo-toggle
  35. todos
  36. callback))
  37. (defun libbcel-actions-todo-uncomplete (todo &optional callback)
  38. "Set TODO as uncompleted. When finished, execute CALLBACK."
  39. (libbcel-client-delete-url
  40. (libbcel-todo-completion-url todo)
  41. (when callback (lambda (_data) (funcall callback)))))
  42. (defun libbcel-actions-todo-complete (todo &optional callback)
  43. "Set TODO as completed. When finished, execute CALLBACK."
  44. (libbcel-client-post-url
  45. (libbcel-todo-completion-url todo)
  46. (when callback (lambda (_data) (funcall callback)))))
  47. (provide 'libbcel-actions)
  48. ;;; libbcel-actions.el ends here