From f10d3396e504166f95c9d015affe5ac884ed63fe Mon Sep 17 00:00:00 2001 From: typebrook Date: Thu, 16 Apr 2020 15:57:30 +0800 Subject: Remove method checkInternet All API calls github.com, do not need this. --- gist | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/gist b/gist index f803030..c773d4f 100755 --- a/gist +++ b/gist @@ -103,7 +103,8 @@ http_method() { httpie) [[ -n $token ]] && header="Authorization:token $token" [[ $METHOD =~ (POST|PATCH) ]] && data_opt="@$http_data" http -b "$METHOD" "$@" "$header" "$data_opt" ;; - esac + esac 2>&1 \ + || { echo "Error: no active internet connection" >&2; return 1; } } httpGet(){ @@ -117,10 +118,6 @@ _process_json() { return "$?" } -checkInternet() { - httpGet github.com 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query github with a get request -} - update() { # Author: Alexander Epstein https://github.com/alexanderepstein # Update utility version 2.2.0 @@ -405,7 +402,6 @@ _parse_response() { # Get latest list of gists from Github API # TODO pagnation for more than 100 gists _fetch_gists() { - checkInternet || exit 1 echo "fetching $user's gists from $GITHUB_API..." echo local route="users/$user/gists" @@ -428,7 +424,6 @@ _fetch_gists() { # Fetch gists for a given user # TODO pagnation for more than 100 gists _query_user() { - checkInternet || exit 1 local route="users/$1/gists" result="$(http_method GET $GITHUB_API/$route?per_page=100 | _parse_response)" [[ -z $result ]] && echo "Failed to query $1's gists" && return 1 @@ -534,7 +529,6 @@ _delete_gist() { [[ ! $response =~ ^(yes|y)$ ]] && return 0 fi - checkInternet || exit 1 for i in "$@"; do _gist_id "$i" &> /dev/null || continue http_method DELETE "$GITHUB_API/gists/$GIST_ID" \ @@ -661,7 +655,6 @@ print(json.dumps({'public': $public, 'files': files_json, 'description': descrip # Create a new gist with files. If success, also update index file and clone the repo _create_gist() { _set_gist "$@" || return 1 - checkInternet || exit 1 [[ -z ${files[*]} ]] && files+=($(_new_file "$filename")) [[ -z $description ]] && read -e -r -p 'Type description: ' description < /dev/tty @@ -688,7 +681,6 @@ _create_gist() { # Update description of a gist _edit_gist() { _gist_id "$1" || return 1 - checkInternet || exit 1 if [[ -z $2 ]]; then read -r "${INDEX_FORMAT[@]}" <<<"$(sed -ne "/^$1 / p" $INDEX)" @@ -872,7 +864,6 @@ case "$1" in version) echo "Version $currentVersion" ;; update) - checkInternet || exit 1 update ;; help | h) usage ;; -- cgit v1.2.3-70-g09d2