-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_v1_code_samples.sh
More file actions
executable file
·66 lines (54 loc) · 1.91 KB
/
test_v1_code_samples.sh
File metadata and controls
executable file
·66 lines (54 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
set -e
OUTPUT_FILE='../test_code_samples/_test.php'
ACCOUNT=$1
ENDPOINT=$2
rm -fr ../test_code_samples
mkdir ../test_code_samples
cd ../test_code_samples
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi
php composer-setup.php --quiet
rm composer-setup.php
composer init --no-interaction --name "mindee/test_code_samples" --description "testing package" --author "mindee" --type "project"
composer install
composer config repositories.mindee/mindee '{"type": "path", "url":"../mindee-api-php"}'
composer require mindee/mindee @dev
composer dump-autoload
chmod -R 777 ./
cd -
for f in $(find docs/code_samples -maxdepth 1 -name "*.txt" -not -name "workflow_*.txt" -not -name "v2_*.txt" | sort -h)
do
echo
echo "###############################################"
echo "${f}"
echo "###############################################"
echo
sed "s/my-api-key/$API_KEY/" "${f}" > $OUTPUT_FILE
sed -i "s/\/path\/to\/the\/file.ext/..\/mindee-api-php\/tests\/resources\/file_types\/pdf\/blank_1.pdf/" $OUTPUT_FILE
if echo "$f" | grep -q "custom_v1.txt"
then
continue
fi
if echo "${f}" | grep -q "default.txt"
then
sed -i "s/my-account/$ACCOUNT/" $OUTPUT_FILE
sed -i "s/my-endpoint/$ENDPOINT/" $OUTPUT_FILE
sed -i "s/my-version/1/" $OUTPUT_FILE
fi
if echo "${f}" | grep -q "default_async.txt"
then
sed -i "s/my-account/mindee/" $OUTPUT_FILE
sed -i "s/my-endpoint/invoice_splitter/" $OUTPUT_FILE
sed -i "s/my-version/1/" $OUTPUT_FILE
fi
sleep 0.6 # avoid too many request errors
php -d auto_prepend_file=vendor/autoload.php $OUTPUT_FILE
done