|
- #!/bin/bash
- # Tracks API query examples.
- #
- # Two endpoints are available:
- #
- # GET /reslevis/getTracks/{uuid}
- # Returns historical track records for a single tracker.
- # Query params:
- # limit - max records to return (default: 10)
- # from - start of time window, RFC3339 (default: 24 h ago)
- # to - end of time window, RFC3339 (default: now)
- #
- # GET /reslevis/getTracks
- # Returns the single latest track record for every known tracker.
- # Useful for a "current positions" overview.
- # Query params:
- # limit - max trackers to return (default: 100)
- # offset - number of trackers to skip, for paging (default: 0)
- #
- # Usage:
- # ./api/tracks.sh [TRACKER_UUID]
- # BASE_URL=http://host:port ./api/tracks.sh [TRACKER_UUID]
- #
- # Get tracker UUIDs from: GET /reslevis/getTrackers
- set -e
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
- . "${SCRIPT_DIR}/../_common.sh"
-
- TRACKER_UUID="${1:-1a6c6f1e-9a3d-4a66-9f0b-6d5f0e1c1a01}"
-
- echo "==================================="
- echo "Single-tracker history: GET /reslevis/getTracks/{uuid}"
- echo "==================================="
- echo ""
-
- # Default call — returns last 10 records from the past 24 hours.
- echo "1. Basic query (default: last 10 tracks from the last 24 hours):"
- curl -s -X GET "${BASE_URL}/reslevis/getTracks/${TRACKER_UUID}" | jq '.'
- echo -e "\n"
-
- # Raise the limit to retrieve more records in a single call.
- echo "2. Get last 50 tracks (raise limit):"
- curl -s -X GET "${BASE_URL}/reslevis/getTracks/${TRACKER_UUID}?limit=50" | jq '.'
- echo -e "\n"
-
- # Explicit time window — both from and to accept RFC3339 timestamps.
- # The date command falls back gracefully between GNU/Linux (-d) and macOS (-v).
- TO_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
- FROM_DATE=$(date -u -d '7 days ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null \
- || date -u -v-7d +%Y-%m-%dT%H:%M:%SZ 2>/dev/null \
- || echo "2020-01-01T00:00:00Z")
-
- echo "3. Get up to 20 tracks from the last 7 days (explicit time window):"
- echo " from=${FROM_DATE} to=${TO_DATE}"
- curl -s -X GET "${BASE_URL}/reslevis/getTracks/${TRACKER_UUID}?from=${FROM_DATE}&to=${TO_DATE}&limit=20" | jq '.'
- echo -e "\n"
-
- echo "==================================="
- echo "All-trackers latest positions: GET /reslevis/getTracks"
- echo "==================================="
- echo ""
-
- # No parameters — returns the most recent record for each tracker, up to 100.
- echo "4. All latest positions (default limit=100, offset=0):"
- curl -s -X GET "${BASE_URL}/reslevis/getTracks" | jq '.'
- echo -e "\n"
-
- # Reduce the page size to 5 — useful when there are many trackers.
- echo "5. First page — limit to 5 trackers:"
- curl -s -X GET "${BASE_URL}/reslevis/getTracks?limit=5&offset=0" | jq '.'
- echo -e "\n"
-
- # Move to the second page by setting offset=5.
- echo "6. Second page — next 5 trackers (offset=5):"
- curl -s -X GET "${BASE_URL}/reslevis/getTracks?limit=5&offset=5" | jq '.'
- echo -e "\n"
-
- echo "==================================="
- echo "Done."
- echo "==================================="
|