#!/usr/bin/env sh
set -eu

if [ -z "${LOCASTICA_API_KEY:-}" ]; then
  echo "Set LOCASTICA_API_KEY before running this example." >&2
  exit 1
fi

LOCASTICA_BASE_URL="${LOCASTICA_BASE_URL:-https://locastica.com}"
POSTCODE="${1:-SE17 1PU}"
ENCODED_POSTCODE=$(printf '%s' "$POSTCODE" | sed 's/ /+/g')

curl --silent --show-error --request GET \
  "${LOCASTICA_BASE_URL}/api/v1/licensing/lookup?postcode=${ENCODED_POSTCODE}" \
  -H "Authorization: Bearer ${LOCASTICA_API_KEY}" \
  -H "Content-Type: application/json"

# Alternative header when Authorization is unavailable:
# curl --silent --show-error --request GET \
#   "${LOCASTICA_BASE_URL}/api/v1/licensing/lookup?postcode=${ENCODED_POSTCODE}" \
#   -H "x-api-key: ${LOCASTICA_API_KEY}"
