Added support for ADSBX API whitelist codes.

If an ADSBX API whitelist code is specified, pass it in the headers of
the API request.
This commit is contained in:
John Wiseman 2020-05-28 12:35:51 -07:00
parent cafbca970e
commit a45360d806

View File

@ -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)
(merge (:adsbx config)
{:lat (:lat config)
:lon (:lon config)
:radius-nm (* (:radius-km config) 0.539957)})
:radius-nm (* (:radius-km config) 0.539957)}))
now (current-time)
[new-db potential-circles] (-> db
(update-history-db (:aircraft data) now config)