foxhole/app/hyap.hy

26 lines
725 B
Hy
Raw Normal View History

2024-02-26 16:55:18 +01:00
#!/usr/bin/env hy
(import httpx)
(import loguru [logger])
(import app [config])
2024-02-28 06:45:13 +01:00
(import app.httpsig [auth])
2024-02-26 16:55:18 +01:00
(defn/a fetch
[url]
(.info logger url)
(return (.json
(with/a [client (.AsyncClient httpx)]
2024-02-26 17:27:01 +01:00
(let [headers {"User-Agent" config.USER_AGENT
"Accept" config.AP_CONTENT_TYPE}]
2024-03-09 18:02:21 +01:00
(await (.get client url :headers headers :timeout 15)))))))
2024-02-28 06:45:13 +01:00
(defn/a post
[url payload]
(with/a [client (.AsyncClient httpx)]
(let [headers {"User-Agent" config.USER_AGENT
"Content-Type" config.AP_CONTENT_TYPE}]
2024-02-28 06:45:13 +01:00
(setv resp
2024-03-09 18:02:21 +01:00
(await (.post client url :headers headers :json payload :auth auth :timeout 15)))
2024-02-28 06:45:13 +01:00
(.raise_for_status resp)
(return resp))))