From 61f30677e84a3168d711a527e2b75fa77e0a23ac Mon Sep 17 00:00:00 2001 From: Steve White Date: Thu, 10 Oct 2024 20:38:57 -0500 Subject: [PATCH] put scripts in ./scripts --- .../addItemToBox.bash | 0 .../deleteItemsInBox.bash | 0 scripts/getboxes.bash | 37 +++++++++++++++++++ getitems.bash => scripts/getitems.bash | 0 .../getitemsinbox.bash | 0 test2.bash => scripts/test2.bash | 0 tests.bash => scripts/tests.bash | 0 7 files changed, 37 insertions(+) rename addItemToBox.bash => scripts/addItemToBox.bash (100%) rename deleteItemsInBox.bash => scripts/deleteItemsInBox.bash (100%) create mode 100644 scripts/getboxes.bash rename getitems.bash => scripts/getitems.bash (100%) rename getitemsinbox.bash => scripts/getitemsinbox.bash (100%) rename test2.bash => scripts/test2.bash (100%) rename tests.bash => scripts/tests.bash (100%) diff --git a/addItemToBox.bash b/scripts/addItemToBox.bash similarity index 100% rename from addItemToBox.bash rename to scripts/addItemToBox.bash diff --git a/deleteItemsInBox.bash b/scripts/deleteItemsInBox.bash similarity index 100% rename from deleteItemsInBox.bash rename to scripts/deleteItemsInBox.bash diff --git a/scripts/getboxes.bash b/scripts/getboxes.bash new file mode 100644 index 0000000..c466333 --- /dev/null +++ b/scripts/getboxes.bash @@ -0,0 +1,37 @@ +#!/bin/bash + +# API base URL +API_BASE_URL="http://10.0.0.66:8080" + +# Login credentials +USERNAME="boxuser" +PASSWORD="boxuser" + +# Function to make an authenticated request +function authenticated_request() { + local method=$1 + local endpoint=$2 + local data=$3 + + # Get a new JWT token + TOKEN=$(curl -s -X POST -H "Content-Type: application/json" \ + -d "{\"username\":\"$USERNAME\", \"password\":\"$PASSWORD\"}" \ + "$API_BASE_URL/login" | jq -r '.token') + + # Make the authenticated request + curl -s -X $method -H "Authorization: Bearer $TOKEN" \ + -H "Content-Type: application/json" \ + -d "$data" \ + "$API_BASE_URL$endpoint" +} + +# Get all boxes +response=$(authenticated_request "GET" "/boxes" "") + +# Check if the request was successful +if [[ $? -eq 0 ]]; then + # Pretty print the boxes using jq + echo "$response" | jq . +else + echo "Error: Failed to get boxes." +fi diff --git a/getitems.bash b/scripts/getitems.bash similarity index 100% rename from getitems.bash rename to scripts/getitems.bash diff --git a/getitemsinbox.bash b/scripts/getitemsinbox.bash similarity index 100% rename from getitemsinbox.bash rename to scripts/getitemsinbox.bash diff --git a/test2.bash b/scripts/test2.bash similarity index 100% rename from test2.bash rename to scripts/test2.bash diff --git a/tests.bash b/scripts/tests.bash similarity index 100% rename from tests.bash rename to scripts/tests.bash