#!/usr/bin/env bash
# Batch (up to 500 locations per call). PAID, needs a key. Weather $0.0002 per location, risk $0.05 per location. Shows what a 402 looks like without a key.
set -euo pipefail
# Free previews need no key. Paid pulls need:  export GETFIXN_KEY=tfx_live_...
B=https://data.truefixr.com
echo "--- no key: expect HTTP 402 with the price (nothing is charged) ---"
curl -s -i -A getfixn-starter -X POST "$B/v1/weather/batch" -H "Content-Type: application/json" \
  -d "{\"locations\":[{\"lat\":30.27,\"lon\":-97.74,\"label\":\"Austin office\"}]}" | sed -n "1p;/^{/p"
echo
echo "--- with a key (paid) ---"
if [ -n "${GETFIXN_KEY:-}" ]; then
  curl -s -A getfixn-starter -X POST "$B/v1/weather/batch" -H "Authorization: Bearer $GETFIXN_KEY" -H "Content-Type: application/json" \
    -d "{\"locations\":[{\"lat\":30.27,\"lon\":-97.74,\"label\":\"Austin office\"},{\"lat\":32.78,\"lon\":-96.80,\"label\":\"Dallas yard\"}]}"
else echo "set GETFIXN_KEY to run this"; fi
