diff options
author | typebrook <typebrook@gmail.com> | 2020-02-01 15:23:32 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-02-01 15:23:32 +0800 |
commit | 70a71dfaa07b4d80816617b15d2e684b8fd04201 (patch) | |
tree | 5c78d9af2d26a86bfc1440fdbd556236a703b14a | |
parent | 90029eb46526841c7a1b9a8d43030211bb70d8ea (diff) |
update
-rwxr-xr-x | scripts/gist | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/scripts/gist b/scripts/gist index ee400fb..c1b8a8c 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -134,7 +134,7 @@ _validate_config(){ | |||
134 | 134 | ||
135 | # load configuration | 135 | # load configuration |
136 | _apply_config() { | 136 | _apply_config() { |
137 | source $CONFIG && _validate_config | 137 | _validate_config |
138 | 138 | ||
139 | AUTH_HEADER="Authorization: token $token" | 139 | AUTH_HEADER="Authorization: token $token" |
140 | [[ -z "$action" ]] && action="${EDITOR:-vi} *" | 140 | [[ -z "$action" ]] && action="${EDITOR:-vi} *" |
@@ -161,12 +161,13 @@ getConfiguredClient() { | |||
161 | } | 161 | } |
162 | 162 | ||
163 | ## Allows to call the users configured client without if statements everywhere | 163 | ## Allows to call the users configured client without if statements everywhere |
164 | httpGet() { | 164 | http_method() { |
165 | local header="" | 165 | local header="" |
166 | local METHOD=$1; shift | ||
166 | case "$configuredClient" in | 167 | case "$configuredClient" in |
167 | curl) [[ -n $token ]] && header="--header Authorization: token $token"; curl -A curl -s $header "$@" ;; | 168 | curl) [[ -n $token ]] && header="--header Authorization: token $token"; curl $METHOD -A curl -s $header $@ ;; |
168 | wget) [[ -n $token ]] && header="--header Authorization: token $token"; wget -qO- $header "$@" ;; | 169 | wget) [[ -n $token ]] && header="--header Authorization: token $token"; wget --method=$METHOD -qO- $header $@ ;; |
169 | httpie) [[ -n $token ]] && header="Authorization:token $token"; http -b GET "$@" "$header";; | 170 | httpie) [[ -n $token ]] && header="Authorization:token $token"; http -b $METHOD $@ $header;; |
170 | fetch) fetch -q "$@" ;; | 171 | fetch) fetch -q "$@" ;; |
171 | esac | 172 | esac |
172 | } | 173 | } |
@@ -249,7 +250,7 @@ _update() { | |||
249 | filter='/^[s]/ d' | 250 | filter='/^[s]/ d' |
250 | fi | 251 | fi |
251 | 252 | ||
252 | local response=$(httpGet $GITHUB_API/$route) | 253 | local response=$(http_method GET $GITHUB_API/$route) |
253 | false && echo Failed to update gists && return 1 | 254 | false && echo Failed to update gists && return 1 |
254 | sed -i "$filter" $INDEX | 255 | sed -i "$filter" $INDEX |
255 | echo $response | _parse_response >> $INDEX | 256 | echo $response | _parse_response >> $INDEX |
@@ -357,10 +358,10 @@ for comment in raw: | |||
357 | # TODO format with simple text | 358 | # TODO format with simple text |
358 | _show_detail() { | 359 | _show_detail() { |
359 | _gist_id $1 | 360 | _gist_id $1 |
360 | httpGet $GITHUB_API/gists/$GIST_ID \ | 361 | http_method GET $GITHUB_API/gists/$GIST_ID \ |
361 | | AccessJsonElement "$(_handle_gist)" | 362 | | AccessJsonElement "$(_handle_gist)" |
362 | 363 | ||
363 | httpGet $GITHUB_API/gists/$GIST_ID/comments \ | 364 | http_method GET $GITHUB_API/gists/$GIST_ID/comments \ |
364 | | AccessJsonElement "$(_handle_comment)" | 365 | | AccessJsonElement "$(_handle_comment)" |
365 | } | 366 | } |
366 | 367 | ||