Add some pivotal functions
This commit is contained in:
parent
35b9c059eb
commit
c487024e26
1 changed files with 60 additions and 17 deletions
|
@ -43,28 +43,71 @@ and story data via the API, and needs to be kept private."
|
|||
|
||||
Does not need a final `/'.")
|
||||
|
||||
(defun pivotel-get-story (project story)
|
||||
"Get data from PROJECT for STORY."
|
||||
(let ((url-request-extra-headers
|
||||
`(("X-TrackerToken" . ,pivotel-api-token))))
|
||||
(defvar pivotel-user-id nil
|
||||
"The user id of the current user.")
|
||||
(defvar pivotel-projects nil
|
||||
"The projects from the current user.")
|
||||
|
||||
(defmacro with-pivotel-headers (headers &rest body)
|
||||
"Add `X-TrackerTocken' to HEADERS and bind them around BODY."
|
||||
(declare (indent 1))
|
||||
`(let ((url-request-extra-headers
|
||||
(append (list (cons "X-TrackerToken" pivotel-api-token))
|
||||
,headers)))
|
||||
,@body))
|
||||
|
||||
(defun pivotel--retrieve-from (url)
|
||||
"Retrieve data from URL."
|
||||
(with-current-buffer
|
||||
(url-retrieve-synchronously
|
||||
(format "%s/projects/%d/stories/%d"
|
||||
pivotel-api-url project story))
|
||||
(url-retrieve-synchronously (concat pivotel-api-url url))
|
||||
(goto-char (point-min))
|
||||
(search-forward "\n\n")
|
||||
(json-read))))
|
||||
(let ((results (json-read)))
|
||||
(kill-buffer)
|
||||
results)))
|
||||
|
||||
(defun pivotel-get-story (project story)
|
||||
"Get data from PROJECT for STORY."
|
||||
(with-pivotel-headers nil
|
||||
(pivotel--retrieve-from
|
||||
(format "/projects/%d/stories/%d" project story))))
|
||||
|
||||
(defun pivotel-get-projects ()
|
||||
"Get a list of all projects."
|
||||
(let ((url-request-extra-headers
|
||||
`(("X-TrackerTocken" . ,pivotel-api-token))))
|
||||
(with-current-buffer
|
||||
(url-retrieve-synchronously
|
||||
(format "%s/projects" pivotel-api-url))
|
||||
(goto-char (point-min))
|
||||
(search-forward "\n\n")
|
||||
(json-read))))
|
||||
(or pivotel-projects
|
||||
(setq pivotel-projects
|
||||
(with-pivotel-headers nil
|
||||
(pivotel--retrieve-from "/projects")))))
|
||||
|
||||
(defun pivotel-get-stories (project)
|
||||
"Get a list of all stories in PROJECT."
|
||||
(with-pivotel-headers nil
|
||||
(pivotel--retrieve-from (format "/projects/%d/stories" project))))
|
||||
|
||||
(defun pivotel-get-me ()
|
||||
"Get information about currently logged-in user."
|
||||
(with-pivotel-headers nil (pivotel--retrieve-from "/me")))
|
||||
|
||||
(defun pivotel-get-me-id ()
|
||||
"Get and cache the current user's id."
|
||||
(or pivotel-user-id
|
||||
(setq pivotel-user-id
|
||||
(cdr (assoc 'id (pivotel-get-me))))))
|
||||
|
||||
(defun pivotel-get-all-stories ()
|
||||
"Get all stories for the current user."
|
||||
(let ((project-ids (mapcar (lambda (itm) (cdr (assoc 'id itm)))
|
||||
(pivotel-get-projects))))
|
||||
(mapcar #'pivotel-get-stories project-ids)))
|
||||
|
||||
(defun pivotel-get-my-owned-stories ()
|
||||
"Get the stories for which the user is an owner."
|
||||
(let ((stories (pivotel-get-all-stories))
|
||||
(id (pivotel-get-me-id)))
|
||||
(delq nil
|
||||
(mapcar (lambda (itm)
|
||||
(when (= (cdr (assoc 'owned_by_id itm)) id) itm))
|
||||
stories))))
|
||||
|
||||
(provide 'pivot)
|
||||
;;; pivot.el ends here
|
||||
|
|
Loading…
Reference in a new issue