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
|
|
|
|
2024-09-29 18:42:10 +02:00
|
|
|
(defn :async fetch
|
2024-02-26 16:55:18 +01:00
|
|
|
[url]
|
|
|
|
(.info logger url)
|
|
|
|
(return (.json
|
2024-09-29 18:42:10 +02:00
|
|
|
(with [:async 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
|
|
|
|
2024-09-29 18:42:10 +02:00
|
|
|
(defn :async post
|
2024-02-28 06:45:13 +01:00
|
|
|
[url payload]
|
2024-09-29 18:42:10 +02:00
|
|
|
(with [:async client (.AsyncClient httpx)]
|
2024-02-28 06:45:13 +01:00
|
|
|
(let [headers {"User-Agent" config.USER_AGENT
|
2024-03-09 19:11:07 +01:00
|
|
|
"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))))
|