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.

96 lines
3.7KB

  1. ;;; libbcel-nav.el --- Code to navigate 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") (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 file contains code to go from an entity to another one. For
  19. ;; example, the file contains `libbcel-nav-children' to list the
  20. ;; direct children of an entity (e.g., the messages of a message
  21. ;; board).
  22. ;;; Code:
  23. (require 'libbcel-structs)
  24. (require 'libbcel-client)
  25. (require 'libbcel-util)
  26. (require 'subr-x)
  27. (cl-defgeneric libbcel-nav-children (entity callback)
  28. "Execute CALLBACK with the children of ENTITY as parameter.")
  29. (cl-defmethod libbcel-nav-children ((_entity (eql projects)) callback)
  30. "Execute CALLBACK with the list of all projects as parameter."
  31. (libbcel-client-get-path
  32. "projects.json"
  33. (lambda (projects-data)
  34. (funcall callback
  35. (libbcel-structs-create-instances-from-data projects-data 'projects)))))
  36. (cl-defmethod libbcel-nav-children ((project libbcel-project) callback)
  37. "Execute CALLBACK with the list of all PROJECT's tools as parameter."
  38. (let* ((enabled-tool-alists (seq-filter
  39. (lambda (tool-alist)
  40. (not (eq (map-elt tool-alist 'enabled) :json-false)))
  41. (libbcel-project-tools project)))
  42. (tool-urls (seq-map
  43. (lambda (tool-alist) (map-elt tool-alist 'url))
  44. enabled-tool-alists)))
  45. (libbcel-util-async-mapcar
  46. #'libbcel-client-get-url
  47. tool-urls
  48. (lambda (tools-data) (funcall callback (libbcel-structs-create-instances-from-data tools-data project))))))
  49. (cl-defmethod libbcel-nav-children ((tool libbcel-tool) callback)
  50. "Execute CALLBACK with the list of TOOL entities as parameter."
  51. (libbcel-client-get-url
  52. (libbcel-tool-children-url tool)
  53. (lambda (children-data)
  54. (funcall callback
  55. (libbcel-structs-create-instances-from-data children-data tool)))))
  56. (cl-defmethod libbcel-nav-children ((todolist libbcel-todolist) callback)
  57. "Execute CALLBACK with TODOLIST's todos as parameter."
  58. (libbcel-util-async-mapcar
  59. (lambda (params partial-callback)
  60. (libbcel-client-get-url
  61. (libbcel-todolist-todos-url todolist)
  62. (lambda (todos-data)
  63. (funcall partial-callback (libbcel-structs-create-instances-from-data todos-data todolist)))
  64. params))
  65. (list nil '((completed . "true")))
  66. (lambda (todos)
  67. (funcall callback (apply #'seq-concatenate 'list todos)))))
  68. (cl-defgeneric libbcel-nav-comments ((entity libbcel-entity) callback)
  69. "Execute CALLBACK with a list of ENTITY's comments."
  70. (if (and (> (libbcel-entity-comments-count entity) 0)
  71. (not (string-empty-p (libbcel-entity-comments-url entity))))
  72. (libbcel-client-get-url
  73. (libbcel-entity-comments-url entity)
  74. (lambda (comments-data)
  75. (funcall callback (libbcel-structs-create-instances-from-data comments-data entity))))
  76. (funcall callback nil)))
  77. (provide 'libbcel-nav)
  78. ;;; libbcel-nav.el ends here