-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclockifylib.el
More file actions
70 lines (56 loc) · 2.03 KB
/
clockifylib.el
File metadata and controls
70 lines (56 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(require 'clockifunlib)
(defvar clockify-base-endpoint
"https://api.clockify.me/api")
(defvar clockify-time-format "%Y-%m-%dT%H:%M:%SZ")
(defun clockify-current-time ()
""
(format-time-string clockify-time-format nil "UTC"))
(defun clockify-call (method resource &optional body)
"return me"
(clockifun--http-call
"api.clockify.me"
(lambda (host)
(let ((secret (clockifun--host->auth-token host)))
(cons "X-Api-Key" secret)))
method
(append (list "/api") resource) body))
(defun clockify-call/sexp (method resource &optional body)
"return SEXP"
(json-read-from-string
(decode-coding-string
(clockify-call method resource body)
'utf-8)))
(defun clockify-workspaces ()
"get workspaces"
(clockify-call/sexp "GET" "/v1/workspaces"))
(defun clockify-workspace--find-by-name (name)
"return SEXP or NIL"
(let ((workspaces (clockify-workspaces)))
(seq-find (lambda (item)
(equal (alist-get 'name item) name))
workspaces)))
(defun clockify-projects-by-workspace (workspace)
"return SEQUENCE(SEXP) or NIL"
(let* ((id (if (listp workspace)
(alist-get 'id workspace)
workspace)
))
(clockify-call/sexp "GET" (list "/v1/workspaces" id "projects"))))
(defun clockify-in (workspace-id project-id description &optional start-at)
""
;;TODO enviar en UTC
(let ((at (or start-at (clockify-current-time))))
(clockify-call/sexp "POST"
(list "/v1/workspaces" workspace-id "time-entries")
(list (cons "start" at)
(cons "projectId" project-id)
(cons "description" description)))
))
(defun clockify-out (workspace-id &optional end-at)
""
;;TODO enivar en UTC
(let ((at (or end-at (clockify-current-time))))
(clockify-call "PUT"
(list "/workspaces" workspace-id "timeEntries" "endStarted")
(list (cons "end" at)))))
(provide 'clockifylib)