Created
June 22, 2017 00:17
-
-
Save ed-flanagan/bf510581225a00d0e1fbcb530f6d5a5a to your computer and use it in GitHub Desktop.
End all Coderpad pads through API (requires jq)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ -z "${API_KEY}" ]; then | |
>&2 echo "Must set API_KEY!" | |
exit 1 | |
fi | |
PAD_API="https://coderpad.io/api/pads" | |
PAD_PAGE="" | |
while :; do | |
PAD_RES=$(curl -s -H "Authorization: Token token=\"${API_KEY}\"" "${PAD_API}?${PAD_PAGE}") | |
for id in $(echo "${PAD_RES}" | jq '.pads[] | select(.ended_at == null).id' | tr -d '"'); do | |
curl -s -X PUT --data ended="true" \ | |
-H "Authorization: Token token=\"${API_KEY}\"" \ | |
"${PAD_API}/${id}?${PAD_PAGE}" | jq '.id' | |
done | |
[ "$(echo "${PAD_RES}" | jq 'has("next_page")')" = false ] && break | |
PAD_PAGE=$(echo "${PAD_RES}" | jq '.next_page' | tr -d '"' | cut -d '?' -f 2) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment