forked from tensorfork/tlarc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase.arc
24 lines (21 loc) · 891 Bytes
/
firebase.arc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(= firebase-url* "https://laarrc.firebaseio.com/"
hn-firebase-url* "https://hacker-news.firebaseio.com/"
firebase-write* (no (readenv "DEV")))
(defcache firebase-token 600
(when (file-exists "../firetoken.py")
(let x (trim:fromstring "" (shell 'python "../firetoken.py"))
(unless (blank x) x))))
(def firebase-set (path value (o auth firebase-write*) (o url firebase-url*))
(when (and auth (firebase-token))
(thread
(fromstring (tostring:write-json value)
(shell 'curl '-fsSL '-X 'PUT '-d (string #\@ "-")
(string url path ".json?access_token=" (firebase-token))))))
value)
(def firebase-get (path (o auth) (o url firebase-url*))
(fromstring
(fromstring ""
(shell 'curl '-fsSL
(string url path ".json"
(if auth (string "?access_token=" (firebase-token)) ""))))
(read-json (stdin))))