From a45360d806b4e4db863f99fea916d6ab3c7974f4 Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Thu, 28 May 2020 12:35:51 -0700 Subject: [PATCH] Added support for ADSBX API whitelist codes. If an ADSBX API whitelist code is specified, pass it in the headers of the API request. --- src/main/lemondronor/advisorycircular.cljs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/lemondronor/advisorycircular.cljs b/src/main/lemondronor/advisorycircular.cljs index 56762ef..7238908 100644 --- a/src/main/lemondronor/advisorycircular.cljs +++ b/src/main/lemondronor/advisorycircular.cljs @@ -63,14 +63,16 @@ "ac"))}) -(defn get-adsbexchange-live-data [{:keys [url lat lon radius-nm api-key]}] +(defn get-adsbexchange-live-data [{:keys [url lat lon radius-nm api-key api-whitelist]}] (let [url (->> [url "lat" lat "lon" lon "dist" (.toFixed radius-nm 1)] (map str) - (string/join "/"))] - (p/let [http-result (util/http-get url {:headers {:api-auth api-key}})] + (string/join "/")) + headers (cond-> {:api-auth api-key} + api-whitelist (assoc :ADSBX-WL api-whitelist))] + (p/let [http-result (util/http-get url {:headers headers})] (let [result (parse-adsbexchange-live-data http-result)] (log-verbose "Got %s aircraft from API" (count (:aircraft result))) result)))) @@ -653,11 +655,10 @@ (write-history-db {} history-db-path)) db (read-history-db history-db-path) data (get-adsbexchange-live-data - {:url (get-in config [:adsbx :url]) - :api-key (get-in config [:adsbx :api-key]) - :lat (:lat config) - :lon (:lon config) - :radius-nm (* (:radius-km config) 0.539957)}) + (merge (:adsbx config) + {:lat (:lat config) + :lon (:lon config) + :radius-nm (* (:radius-km config) 0.539957)})) now (current-time) [new-db potential-circles] (-> db (update-history-db (:aircraft data) now config)