diff options
| author | typebrook <typebrook@gmail.com> | 2020-04-07 00:05:17 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-04-07 00:07:59 +0800 |
| commit | aea6308dc148858f77723e934440604819ba4581 (patch) | |
| tree | 65fc9928ba471ca234fa20b8d5f7f3db87877f70 | |
| parent | 7870b029ccf86ef2fed932ac7e2a0295c2b799de (diff) | |
Chech internet when using Github API
| -rwxr-xr-x | gist | 5 |
1 files changed, 5 insertions, 0 deletions
| @@ -388,6 +388,7 @@ _parse_response() { | |||
| 388 | # TODO pagnation for more than 100 gists | 388 | # TODO pagnation for more than 100 gists |
| 389 | # TODO add files of a gist | 389 | # TODO add files of a gist |
| 390 | _fetch_gists() { | 390 | _fetch_gists() { |
| 391 | checkInternet || exit 1 | ||
| 391 | echo "fetching $user's gists from $GITHUB_API..." | 392 | echo "fetching $user's gists from $GITHUB_API..." |
| 392 | echo | 393 | echo |
| 393 | local route="users/$user/gists" | 394 | local route="users/$user/gists" |
| @@ -410,6 +411,7 @@ _fetch_gists() { | |||
| 410 | # Fetch gists for a given user | 411 | # Fetch gists for a given user |
| 411 | # TODO pagnation for more than 100 gists | 412 | # TODO pagnation for more than 100 gists |
| 412 | _query_user() { | 413 | _query_user() { |
| 414 | checkInternet || exit 1 | ||
| 413 | local route="users/$1/gists" | 415 | local route="users/$1/gists" |
| 414 | result="$(http_method GET $GITHUB_API/$route?per_page=100 | _parse_response)" | 416 | result="$(http_method GET $GITHUB_API/$route?per_page=100 | _parse_response)" |
| 415 | [[ -z $result ]] && echo "Failed to query $1's gists" && return 1 | 417 | [[ -z $result ]] && echo "Failed to query $1's gists" && return 1 |
| @@ -516,6 +518,7 @@ _delete_gist() { | |||
| 516 | [[ ! $response =~ ^(yes|y)$ ]] && return 0 | 518 | [[ ! $response =~ ^(yes|y)$ ]] && return 0 |
| 517 | fi | 519 | fi |
| 518 | 520 | ||
| 521 | checkInternet || exit 1 | ||
| 519 | for i in "$@"; do | 522 | for i in "$@"; do |
| 520 | _gist_id "$i" &> /dev/null || continue | 523 | _gist_id "$i" &> /dev/null || continue |
| 521 | http_method DELETE "$GITHUB_API/gists/$GIST_ID" \ | 524 | http_method DELETE "$GITHUB_API/gists/$GIST_ID" \ |
| @@ -643,6 +646,7 @@ print(json.dumps({'public': $public, 'files': files_json, 'description': descrip | |||
| 643 | # Create a new gist with files. If success, also update index file and clone the repo | 646 | # Create a new gist with files. If success, also update index file and clone the repo |
| 644 | _create_gist() { | 647 | _create_gist() { |
| 645 | _set_gist "$@" || return 1 | 648 | _set_gist "$@" || return 1 |
| 649 | checkInternet || exit 1 | ||
| 646 | [[ -z ${files[*]} ]] && files+=($(_new_file "$filename")) | 650 | [[ -z ${files[*]} ]] && files+=($(_new_file "$filename")) |
| 647 | [[ -z $description ]] && read -r -p 'Type description: ' description < /dev/tty | 651 | [[ -z $description ]] && read -r -p 'Type description: ' description < /dev/tty |
| 648 | 652 | ||
| @@ -674,6 +678,7 @@ _get_desc() { | |||
| 674 | # Update description of a gist | 678 | # Update description of a gist |
| 675 | _edit_gist() { | 679 | _edit_gist() { |
| 676 | _gist_id "$1" || return 1 | 680 | _gist_id "$1" || return 1 |
| 681 | checkInternet || exit 1 | ||
| 677 | 682 | ||
| 678 | local prefill="$(_get_desc $1)" | 683 | local prefill="$(_get_desc $1)" |
| 679 | if [[ -z $2 ]]; then | 684 | if [[ -z $2 ]]; then |