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.

82 lines
2.7KB

  1. ;;; libbcel.el --- Library to connect to basecamp 3 API -*- 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") (request "0.3.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. ;; This library provides a bunch of functions and structures to
  19. ;; connect to Basecamp 3 API. The connection is handled by
  20. ;; libbcel-proxy.el and the JS files in the proxy/ directory.
  21. ;;; Code:
  22. (require 'libbcel-util)
  23. (require 'libbcel-oauth)
  24. (require 'libbcel-client)
  25. (require 'libbcel-structs)
  26. (require 'libbcel-nav)
  27. (require 'libbcel-actions)
  28. ;; Configuration
  29. (defgroup libbcel nil
  30. "Configure libbcel to integrate Basecamp."
  31. :group 'external)
  32. ;;; Public functions
  33. (defun libbcel-completing-read (prompt entities &optional transformer)
  34. "PROMPT user to select one entity among ENTITIES.
  35. Transform each entity to a string with TRANSFORMER,
  36. `libbcel-entity-name' if nil."
  37. (let* ((transformer (or transformer #'libbcel-entity-name))
  38. (map (make-hash-table :test 'equal :size (length entities)))
  39. (entity-strings (mapcar (lambda (entity) (funcall transformer entity)) entities)))
  40. (cl-mapcar (lambda (entity entity-string)
  41. (puthash entity-string entity map))
  42. entities entity-strings)
  43. (let ((entity-string (completing-read prompt entity-strings nil t)))
  44. (gethash entity-string map))))
  45. (defun libbcel-completing-read-entity (function prompt entity &optional transformer)
  46. "Call FUNCTION after prompting for a child of ENTITY.
  47. Pass PROMPT, the elements of ENTITY and TRANSFORMER to
  48. `libbcel-completing-read'."
  49. (libbcel-nav-children
  50. entity
  51. (lambda (entities)
  52. (funcall function
  53. (libbcel-completing-read prompt entities transformer)))))
  54. (cl-defmethod libbcel-nav-children ((entities list) callback)
  55. "Execute CALLBACK with the children of all ENTITIES as parameter."
  56. (libbcel-util-async-mapcar
  57. #'libbcel-nav-children
  58. entities
  59. callback))
  60. (provide 'libbcel)
  61. ;;; libbcel.el ends here