-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_storage.clj
43 lines (38 loc) · 1.71 KB
/
json_storage.clj
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
(ns firma-analysis.ports.http-out.json-storage
(:require [clj-data-adapter.core :as data-adapter]
[clojure.data.json :as cjson]
[firma-analysis.adapters.events :as a.events]
[firma-analysis.adapters.members :as a.members]
[org.httpkit.client :as hk-client]
[outpace.config :refer [defconfig]]))
(defconfig bin-account-id)
(defconfig events-bin-id)
(defconfig part-bin-id)
(defconfig api-key)
(def raw-config
{:bin-account-id bin-account-id
:events-bin-id events-bin-id
:part-bin-id part-bin-id
:api-key api-key})
(def events-url
(str "https://api.jsonstorage.net/v1/json/" (:bin-account-id raw-config) "/" (:events-bin-id raw-config) "?apiKey=" (:api-key raw-config)))
(def participation-url
(str "https://api.jsonstorage.net/v1/json/" (:bin-account-id raw-config) "/" (:part-bin-id raw-config) "?apiKey=" (:api-key raw-config)))
(defn fetch-events!
[]
(let [resp (hk-client/request {:url events-url
:method :get})
{:keys [events availabilities]} (-> @resp
:body
(cjson/read-str :key-fn data-adapter/snake-str->kebab-key))]
{:events/events (a.events/storage-> events)
:events/availabilitites availabilities}))
(defn fetch-participation!
[]
(let [resp (hk-client/request {:url participation-url
:method :get})
{:keys [votes members]} (-> @resp
:body
(cjson/read-str :key-fn data-adapter/snake-str->kebab-key))]
{:participation/votes votes
:participation/members (map a.members/storage-> members)}))