Dry running intuit

This commit is contained in:
2021-12-14 11:18:24 -08:00
parent 1178e723d1
commit b7324af538
3 changed files with 80 additions and 28 deletions

View File

@@ -15,7 +15,8 @@
[mount.core :as mount]
[unilog.context :as lc]
[yang.scheduler :as scheduler]
[clojure.core.async :as async])
[clojure.core.async :as async]
[clojure.core.memoize :as m])
(:import [org.apache.commons.codec.binary Base64]))
@@ -119,27 +120,29 @@
(defn get-transactions []
(client/get (str prod-base-url "/company/" prod-company-id "/reports/TransactionList" "?minorversion=63&start_date=2021-11-30&end_date=2021-11-30")
{:headers prod-base-headers
:as :json}))
(defn get-transactions [start end external-id]
(defn get-all-transactions [start end]
(let [token (get-fresh-access-token)]
(let [body (:body (client/get (str prod-base-url "/company/" prod-company-id "/reports/TransactionList" "?minorversion=63&start_date=" start "&end_date=" end)
{:headers (with-auth prod-base-headers token)
:as :json}))
headers (map :ColTitle (:Column (:Columns body)))
rows (map :ColData (:Row (:Rows body)))]
(->> rows
(map
(fn [row]
(into {}
(map
(fn [h r]
[(keyword h) (:value r)])
headers
row))))
(filter #(str/includes? (:Account %) external-id))))))
:as :json}))]
body)))
(def memoize-get-all-transactions (m/ttl get-all-transactions :ttl/threshold 60000))
(defn get-transactions [start end external-id]
(let [body (memoize-get-all-transactions start end)
headers (map :ColTitle (:Column (:Columns body)))
rows (map :ColData (:Row (:Rows body)))]
(->> rows
(map
(fn [row]
(into {}
(map
(fn [h r]
[(keyword h) (:value r)])
headers
row))))
(filter #(str/includes? (:Account %) external-id)))))