update shitiverse
1 files changed, 12 insertions(+), 10 deletions(-)

M bin/shitiverse
M bin/shitiverse +12 -10
@@ 24,7 24,7 @@ is_token_expired() {
 }
 
 if [ ! -r "$APP_CLIENT_FILE" ]; then
-	curl -s -X POST "$SHITIVERSE_POD_URL/api/v1/apps" \
+	curl -sf -X POST "$SHITIVERSE_POD_URL/api/v1/apps" \
 		-d client_name="Shitiverse" \
 		-d redirect_uris="urn:ietf:wg:oauth:2.0:oob" \
 		-d scopes="read+write+follow" \

          
@@ 43,7 43,7 @@ if [ ! -r "$APP_TOKEN_FILE" ]; then
 	xdg-open "$request_url"
 	read -r AUTHORIZATION_CODE
 
-	if curl -sf -X POST \
+	if ! curl -sf -X POST \
 		-d client_id="$CLIENT_ID" \
 		-d client_secret="$CLIENT_SECRET" \
 		-d redirect_uris="urn:ietf:wg:oauth:2.0:oob" \

          
@@ 52,32 52,34 @@ if [ ! -r "$APP_TOKEN_FILE" ]; then
 		-d grant_type="authorization_code" \
 		"$SHITIVERSE_POD_URL/oauth/token" \
 		> "$APP_TOKEN_FILE"; then
-		notice "Registration done"
-	else
 		notice "An error occured when fetching token"
 		exit 1
 	fi
+
+	notice "Registration done"
 fi
 
 if is_token_expired; then
 	REFRESH_TOKEN="$(jq -r .refresh_token "$APP_TOKEN_FILE")"
-	if curl -X POST \
+	if ! curl -sf -X POST \
 		-d client_id="$CLIENT_ID" \
 		-d client_secret="$CLIENT_SECRET" \
 		-d grant_type="refresh_token" \
 		-d refresh_token="$REFRESH_TOKEN" \
 		"$SHITIVERSE_POD_URL/oauth/token" \
 		> "$APP_TOKEN_FILE"; then
-		notice "Token refreshed"
-	else
 		notice "An error occured when refreshing token"
 		exit 1
 	fi
+
+	notice "Token refreshed"
 fi
 
 APP_TOKEN="$(jq -r .access_token "$APP_TOKEN_FILE")"
 
-target="$1"
-shift
+if [ -n "$1" ]; then
+	target="$1"
+	shift
 
-curl -sH "Authorization: Bearer $APP_TOKEN" "$SHITIVERSE_POD_URL/$target" "$@"
+	curl -sH "Authorization: Bearer $APP_TOKEN" "$SHITIVERSE_POD_URL/$target" "$@"
+fi