czapkomaty API sometimes returns blank pages - workaround

master
Dominika Liberda 2020-11-12 13:06:17 +01:00
parent 913295ebd7
commit 1df1bbf2c8
5 changed files with 32 additions and 8 deletions

View File

@ -62,7 +62,14 @@ function add_account_authtoken() {
function update_account_authtoken() {
a=$(cat secret/refreshTokens.dat | grep -P "^$1\:")
token=$(awk -F: '{print $2}' <<< $a);
auth=$(curl -s -X POST -H "Content-type: application/json" --data '{"phoneOS": "Android", "refreshToken": "'"$token"'"}' https://api-inmobile-pl.easypack24.net/v1/authenticate | jq -r .authToken | sed -s 's/Bearer //g')
while true; do
if [[ "$auth" == '' ]]; then
auth=$(curl -s -X POST -H "Content-type: application/json" --data '{"phoneOS": "Android", "refreshToken": "'"$token"'"}' https://api-inmobile-pl.easypack24.net/v1/authenticate | jq -r .authToken | sed -s 's/Bearer //g')
sleep 1
else
break
fi
done
sed -E -i 's/^'"$1"':.*/'"$1:$auth"'/g' secret/authTokens.dat
}

View File

@ -5,16 +5,22 @@ fi
source "${cfg[namespace]}/code/common.sh"
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]}"'"}}')
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
if [[ $(echo $data | jq .status) == "403" ]]; then
echo $data | jq "{status: .status, msg: .error}"
else
uuid=$(echo $data | jq -r ".sessionUuid")
data=$(curl -X POST -H "$(get_auth_string)" "https://api-inmobile-pl.easypack24.net/v1/collect/compartment/open/$uuid")
data=''
while [[ "$data" == '' ]]; do
data=$(curl -X POST -H "$(get_auth_string)" "https://api-inmobile-pl.easypack24.net/v1/collect/compartment/open/$uuid")
done
if [[ $(echo $data | jq ".compartment") != "" ]]; then
echo $data
else
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "emptyPage"
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "OCW received an invalid response from the API."
fi
fi

View File

@ -11,7 +11,10 @@ if [[ "${post_data[code]}" != '' && "${post_data[phone]}" != '' ]]; then
mail="$(get_account_mail $username)"
if [[ "$(cat secret/mail.dat | grep "$username:" | grep ":${post_data[code]}:")" != '' ]]; then
sed -i "s/$username:$mail:${post_data[code]}:no/$username:$mail:${post_data[code]}:yes/" secret/mail.dat
curl -s "https://api-inmobile-pl.easypack24.net/v1/sendSMSCode/${post_data[phone]}" > /dev/null
x=''
while [[ "$x" == '' ]]; do
x=$(curl -s "https://api-inmobile-pl.easypack24.net/v1/sendSMSCode/${post_data[phone]}")
done
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 "success"
elif [[ $status == 1 ]]; then
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "$reason"

View File

@ -3,6 +3,10 @@ if ! silent=yes source "${cfg[namespace]}/webroot/api/session.shs"; then
return
fi
data=$(curl -s -H "$(get_auth_string)" "https://api-inmobile-pl.easypack24.net/v1/parcel?updatedAfter=1970-01-01T00:00:00.000Z")
data=''
echo $data | jq -c "[.[] | {shipmentNumber: .shipmentNumber, status: .status, openCode: .openCode, senderName: .senderName, pickupPoint: {name: .pickupPoint.name, status: .pickupPoint.status, location: .pickupPoint.location, description: .pickupPoint.locationDescription, address: .pickupPoint.addressDetails}}]"
while [[ "$data" == '' ]]; do
data=$(curl -s -H "$(get_auth_string)" "https://api-inmobile-pl.easypack24.net/v1/parcel?updatedAfter=1970-01-01T00:00:00.000Z")
done
echo "$data" | jq -c "[.[] | {shipmentNumber: .shipmentNumber, status: .status, openCode: .openCode, senderName: .senderName, pickupPoint: {name: .pickupPoint.name, status: .pickupPoint.status, location: .pickupPoint.location, description: .pickupPoint.locationDescription, address: .pickupPoint.addressDetails}}]"

View File

@ -7,7 +7,11 @@ fi
source "${cfg[namespace]}/code/common.sh"
if [[ "${post_data[phone]}" != "" && "${post_data[code]}" != "" ]]; then
tokens=$(curl -s -X POST -H "Content-type: application/json" --data '{"phoneOS":"Android"}' "https://api-inmobile-pl.easypack24.net/v1/confirmSMSCode/${post_data[phone]}/${post_data[code]}")
tokens=''
while [[ "$tokens" == '' ]]; do
tokens=$(curl -s -X POST -H "Content-type: application/json" --data '{"phoneOS":"Android"}' "https://api-inmobile-pl.easypack24.net/v1/confirmSMSCode/${post_data[phone]}/${post_data[code]}")
sleep 0.5
done
if [[ $(echo $tokens | jq .status) == "404" ]]; then
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "wrongData"