ocw/webroot/api/collect.shs

30 lines
1.1 KiB
Plaintext
Raw Normal View History

2020-09-19 18:32:46 +02:00
#!/bin/bash
2020-11-06 00:27:48 +01:00
if ! silent=yes source "${cfg[namespace]}/webroot/api/session.shs"; then
return
fi
2020-10-05 00:46:42 +02:00
source "${cfg[namespace]}/code/common.sh"
2020-09-19 18:32:46 +02:00
data=''
while [[ "$data" == '' ]]; do
data=$(curl -s -X POST -H "$(get_auth_string)" -H "Content-type: application/json" "https://api-inmobile-pl.easypack24.net/v1/collect/validate" --data '{"geoPoint":{"accuracy":"1","latitude":"'"${post_data[lat]}"'","longitude":"'"${post_data[lon]}"'"},"parcel":{"openCode":"'"${post_data[openCode]}"'","shipmentNumber":"'"${post_data[id]}"'"}}')
done
2020-09-19 18:32:46 +02:00
2021-04-27 23:06:33 +02:00
echo $data > tmpdata
2020-09-19 18:32:46 +02:00
if [[ $(echo $data | jq .status) == "403" ]]; then
echo $data | jq "{status: .status, msg: .error}"
2020-09-19 18:32:46 +02:00
else
uuid=$(echo $data | jq -r ".sessionUuid")
data=''
while [[ "$data" == '' ]]; do
data=$(curl -X POST -H "$(get_auth_string)" "https://api-inmobile-pl.easypack24.net/v1/collect/compartment/open/$uuid")
done
2020-09-19 18:32:46 +02:00
if [[ $(echo $data | jq ".compartment") != "" ]]; then
2021-04-27 23:06:33 +02:00
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 ":o $data"
2020-09-19 18:32:46 +02:00
else
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "OCW received an invalid response from the API."
2020-09-19 18:32:46 +02:00
fi
2021-04-27 23:06:33 +02:00
echo $data > tmp_data2
2020-10-05 00:46:42 +02:00
fi