-
Notifications
You must be signed in to change notification settings - Fork 1
/
clockifunlib.el
44 lines (34 loc) · 1.55 KB
/
clockifunlib.el
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
;;; clockifunlib.el -- Clockifun library
;; Copyright (C) 2020-2023 Jovany Leandro G.C <[email protected]>
;; Maintainer: Jovany Leandro G.C <[email protected]>
;; Version: 0.1.0
;;; CODE:
(defun clockifun--host->auth-token (host)
"Token from .authinfo for HOST."
(let ((found (nth 0 (auth-source-search :host host))))
(unless found (error (format "not found auth token for host %s" host)))
(funcall (plist-get found :secret))))
(defun clockifun--host->user (host)
(let ((found (nth 0 (auth-source-search :host host))))
(unless found (error (format "not found auth token for host %s" host)))
(plist-get found :user)))
(defun clockifun--http-call (host authorization-header-fun method resource &optional body)
"Do http call json to HOST using http METHOD to RESOURCE with BODY."
(let* ((url-request-method method)
(url-request-extra-headers
(list '("Content-Type" . "application/json")
(funcall authorization-header-fun host)
))
(service (if (listp resource) (string-join resource "/") resource))
(url-request-data (if (listp body)
(replace-regexp-in-string "[^[:ascii:]]" "?"
(json-encode-list body)) nil))
)
(with-current-buffer
(url-retrieve-synchronously (concat "https://" host service))
(goto-char (point-min))
(search-forward-regexp "\n\n")
(buffer-substring (point) (point-max))
)))
(provide 'clockifunlib)
;;; clockifunlib.el ends here