aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-04-16 15:57:30 +0800
committertypebrook <typebrook@gmail.com>2020-04-16 15:57:31 +0800
commitf10d3396e504166f95c9d015affe5ac884ed63fe (patch)
treee145c6a19a8b3087a71e14fce92897041974e1c5
parentff048ac89c17d5efcbdae18a426f4a20c90c2518 (diff)
Remove method checkInternet
All API calls github.com, do not need this.
-rwxr-xr-xgist13
1 files 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() {
103 httpie) [[ -n $token ]] && header="Authorization:token $token" 103 httpie) [[ -n $token ]] && header="Authorization:token $token"
104 [[ $METHOD =~ (POST|PATCH) ]] && data_opt="@$http_data" 104 [[ $METHOD =~ (POST|PATCH) ]] && data_opt="@$http_data"
105 http -b "$METHOD" "$@" "$header" "$data_opt" ;; 105 http -b "$METHOD" "$@" "$header" "$data_opt" ;;
106 esac 106 esac 2>&1 \
107 || { echo "Error: no active internet connection" >&2; return 1; }
107} 108}
108 109
109httpGet(){ 110httpGet(){
@@ -117,10 +118,6 @@ _process_json() {
117 return "$?" 118 return "$?"
118} 119}
119 120
120checkInternet() {
121 httpGet github.com 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query github with a get request
122}
123
124update() { 121update() {
125 # Author: Alexander Epstein https://github.com/alexanderepstein 122 # Author: Alexander Epstein https://github.com/alexanderepstein
126 # Update utility version 2.2.0 123 # Update utility version 2.2.0
@@ -405,7 +402,6 @@ _parse_response() {
405# Get latest list of gists from Github API 402# Get latest list of gists from Github API
406# TODO pagnation for more than 100 gists 403# TODO pagnation for more than 100 gists
407_fetch_gists() { 404_fetch_gists() {
408 checkInternet || exit 1
409 echo "fetching $user's gists from $GITHUB_API..." 405 echo "fetching $user's gists from $GITHUB_API..."
410 echo 406 echo
411 local route="users/$user/gists" 407 local route="users/$user/gists"
@@ -428,7 +424,6 @@ _fetch_gists() {
428# Fetch gists for a given user 424# Fetch gists for a given user
429# TODO pagnation for more than 100 gists 425# TODO pagnation for more than 100 gists
430_query_user() { 426_query_user() {
431 checkInternet || exit 1
432 local route="users/$1/gists" 427 local route="users/$1/gists"
433 result="$(http_method GET $GITHUB_API/$route?per_page=100 | _parse_response)" 428 result="$(http_method GET $GITHUB_API/$route?per_page=100 | _parse_response)"
434 [[ -z $result ]] && echo "Failed to query $1's gists" && return 1 429 [[ -z $result ]] && echo "Failed to query $1's gists" && return 1
@@ -534,7 +529,6 @@ _delete_gist() {
534 [[ ! $response =~ ^(yes|y)$ ]] && return 0 529 [[ ! $response =~ ^(yes|y)$ ]] && return 0
535 fi 530 fi
536 531
537 checkInternet || exit 1
538 for i in "$@"; do 532 for i in "$@"; do
539 _gist_id "$i" &> /dev/null || continue 533 _gist_id "$i" &> /dev/null || continue
540 http_method DELETE "$GITHUB_API/gists/$GIST_ID" \ 534 http_method DELETE "$GITHUB_API/gists/$GIST_ID" \
@@ -661,7 +655,6 @@ print(json.dumps({'public': $public, 'files': files_json, 'description': descrip
661# Create a new gist with files. If success, also update index file and clone the repo 655# Create a new gist with files. If success, also update index file and clone the repo
662_create_gist() { 656_create_gist() {
663 _set_gist "$@" || return 1 657 _set_gist "$@" || return 1
664 checkInternet || exit 1
665 [[ -z ${files[*]} ]] && files+=($(_new_file "$filename")) 658 [[ -z ${files[*]} ]] && files+=($(_new_file "$filename"))
666 [[ -z $description ]] && read -e -r -p 'Type description: ' description < /dev/tty 659 [[ -z $description ]] && read -e -r -p 'Type description: ' description < /dev/tty
667 660
@@ -688,7 +681,6 @@ _create_gist() {
688# Update description of a gist 681# Update description of a gist
689_edit_gist() { 682_edit_gist() {
690 _gist_id "$1" || return 1 683 _gist_id "$1" || return 1
691 checkInternet || exit 1
692 684
693 if [[ -z $2 ]]; then 685 if [[ -z $2 ]]; then
694 read -r "${INDEX_FORMAT[@]}" <<<"$(sed -ne "/^$1 / p" $INDEX)" 686 read -r "${INDEX_FORMAT[@]}" <<<"$(sed -ne "/^$1 / p" $INDEX)"
@@ -872,7 +864,6 @@ case "$1" in
872 version) 864 version)
873 echo "Version $currentVersion" ;; 865 echo "Version $currentVersion" ;;
874 update) 866 update)
875 checkInternet || exit 1
876 update ;; 867 update ;;
877 help | h) 868 help | h)
878 usage ;; 869 usage ;;