Skip to content

Commit 53fb4a7

Browse files
author
Balaji Jayaraman
committed
modified example workspace name to user defined name
1 parent dcf09a6 commit 53fb4a7

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed
295 KB
Binary file not shown.

examples/Workspaces/eg001CreateWorkspace.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
2626
'--header' "Content-Type: application/json")
2727
#ds-snippet-end:Workspaces1Step2
2828

29+
# Enter the name of the workspace to create
30+
echo ""
31+
echo "Enter the name for the new workspace:"
32+
echo ""
33+
34+
read workspace_name
35+
2936
# Create the workspace definition
3037
#apx-snippet-start:createWorkspace
3138
#ds-snippet-start:Workspaces1Step3
3239
printf \
3340
'{
34-
"name" : "Example workspace"
41+
"name" : "'"${workspace_name}"'"
3542
}' >> $request_data
3643
#ds-snippet-end:Workspaces1Step3
3744

examples/Workspaces/eg002AddDocumentToWorkspace.sh

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fi
99

1010
# Check that a workspace exists
1111
workspace_id=$(cat config/WORKSPACE_ID)
12+
workspace_name=$(cat config/WORKSPACE_NAME)
1213
if [ -z "$workspace_id" ]; then
1314
echo "Please create a workspace before running this example"
1415
exit 0
@@ -35,34 +36,65 @@ declare -a Headers=(
3536
)
3637
#ds-snippet-end:Workspaces2Step2
3738

39+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
40+
DEMO_DOCS_PATH_UNIX="$(cd "$SCRIPT_DIR/../../demo_documents" && pwd)"
41+
42+
if command -v cygpath >/dev/null 2>&1; then
43+
DEMO_DOCS_PATH="$(cygpath -w "$DEMO_DOCS_PATH_UNIX")"
44+
else
45+
DEMO_DOCS_PATH="$DEMO_DOCS_PATH_UNIX"
46+
fi
3847

3948
# Upload the file path to be added to the workspace
4049
#ds-snippet-start:Workspaces2Step3
41-
echo ""
42-
echo "Enter the path to the document you want to add to the workspace:"
43-
echo ""
44-
read file_path
50+
while true; do
51+
echo ""
52+
echo "Enter the PDF file name (e.g. World_Wide_Corp_Web_Form.pdf) from the ${DEMO_DOCS_PATH} folder:"
53+
echo ""
54+
read file_name
4555

46-
if [ ! -f "$file_path" ]; then
47-
echo "File does not exist: $file_path"
48-
exit 1
49-
fi
56+
file_path="$DEMO_DOCS_PATH/$file_name"
57+
58+
if [[ "$file_name" != *.pdf ]]; then
59+
echo ""
60+
echo "The file must be a PDF (must end with .pdf). Please try again."
61+
continue
62+
fi
63+
64+
if [ ! -f "$file_path" ]; then
65+
echo ""
66+
echo "File not found in demo_documents folder."
67+
continue
68+
fi
69+
break
70+
done
5071

5172
# Enter the document name for the workspace
5273
echo ""
53-
echo "Enter the name for the document in the workspace:"
74+
echo "Enter the name for the document in the workspace (must end with .pdf):"
5475
echo ""
5576

56-
read doc_name
77+
while true; do
78+
read doc_name
79+
80+
doc_name=$(echo "$doc_name" | xargs)
81+
82+
if [[ "$doc_name" =~ \.pdf$ ]]; then
83+
break
84+
else
85+
echo ""
86+
echo "Invalid name. The document name must end with '.pdf' (e.g., example.pdf)."
87+
echo "Please try again:"
88+
fi
89+
done
5790
#ds-snippet-end:Workspaces2Step3
5891

5992
#apx-snippet-start:addWorkspaceDocument
6093
#ds-snippet-start:Workspaces2Step4
6194
Status=$(curl -s -w "%{http_code}" -o "${response}" \
6295
--request POST "${base_path}/accounts/${account_id}/workspaces/${workspace_id}/documents" \
6396
"${Headers[@]}" \
64-
-F "file=@${file_path}" \
65-
-F "name=${doc_name}"
97+
-F "file=@${file_path};filename=${doc_name}" \
6698
)
6799
#ds-snippet-end:Workspaces2Step4
68100
#apx-snippet-end:addWorkspaceDocument
@@ -84,7 +116,8 @@ echo ""
84116

85117
# Pull out the document ID and save it
86118
document_id=$(cat $response | grep document_id | sed 's/.*"document_id":"//' | sed 's/".*//')
87-
echo "Document added! ID: ${document_id}"
119+
echo ""
120+
echo "Document added to the workspace '${workspace_name}'! ID: ${document_id}"
88121
echo ${document_id} > config/DOCUMENT_ID
89122

90123
rm "$response"

0 commit comments

Comments
 (0)