From b1436832fcceca9ec734e318cf63dcf58f2a7b3d Mon Sep 17 00:00:00 2001 From: Adriean Khisbe Date: Mon, 2 Mar 2015 16:44:15 +0100 Subject: [PATCH 001/173] Fix #37 documentation typo --- README.md | 13 ++++++------- resty | 8 +++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index efbbd96..4c1e340 100644 --- a/README.md +++ b/README.md @@ -298,13 +298,13 @@ Per-Host/Per-Method Curl Configuration Files Resty supports a per-host/per-method configuration file to help you with frequently used curl options. Each host (including the port) can have its -own configuration file in the _~/.resty_ directory. The file format is +own configuration file in the `~/.resty_ directory`. The file format is - $ GET [arg] [arg] ... - $ PUT [arg] [arg] ... - $ PATCH [arg] [arg] ... - $ POST [arg] [arg] ... - $ DELETE [arg] [arg] ... + GET [arg] [arg] ... + PUT [arg] [arg] ... + PATCH [arg] [arg] ... + POST [arg] [arg] ... + DELETE [arg] [arg] ... Where the `arg`s are curl command line arguments. Each line can specify arguments for that HTTP verb only, and all lines are optional. @@ -403,4 +403,3 @@ scripts that make dealing with JSON data easier. value - diff --git a/resty b/resty index be64ab1..12c1d57 100644 --- a/resty +++ b/resty @@ -31,14 +31,14 @@ function resty() { method="$1"; [[ $# -gt 0 ]] && shift h2t=$( (exec 2>&-; (which lynx >/dev/null && echo lynx -stdin -dump) \ || which html2text || which cat) |tail -n 1) - editor=$( (exec 2>&-; which "$EDITOR" || which vim || echo "vi") |tail -n 1) + editor=$((exec 2>&-; which "$EDITOR" || which vim || echo "vi") |tail -n 1) [ "${method#P}" != "$method" ] || [ "$method" = "TRACE" ] && wantdata="yes" [ -d "$cookies" ] || (mkdir -p "$cookies"; echo "http://localhost*" > "$host") [ -n "$1" ] && [ "${1#/}" != "$1" ] \ - && _path="$1" && [[ $# -gt 0 ]] && shift - [ "$1" = "${1#-}" ] && dat="$1" && [[ $# -gt 0 ]] && shift + && _path="$1" && [[ $# > 0 ]] && shift + [ "$1" = "${1#-}" ] && dat="$1" && [[ $# > 0 ]] && shift j=1 for i in "$@"; do @@ -80,6 +80,8 @@ function resty() { [ -n "$dat" ] && opt="--data-binary" [ "$method" = "HEAD" ] && opt="-I" && raw="yes" + ## Retrieve stored option in confidir. + ## §maybe: cache this when resty) [ -f "$confdir/$domain" ] && eval "args2=( $(cat "$confdir/$domain" 2>/dev/null |sed 's/^ *//' |grep "^$method" |cut -b $((${#method}+2))-) )" [ "$dry" = "yes" ] && echo "curl -sLv $opt \"$dat\" -X $method -b "$cookies/$domain" -c "$cookies/$domain" \"${args2[@]}\" \"${curlopt2[@]}\" \"${curlopt[@]}\" \"$_path$query\"" && return 0 # TODO: refactor function From 2d03da6e5827981ee69973fca5218687a3d60fdf Mon Sep 17 00:00:00 2001 From: Adriean Khisbe Date: Mon, 2 Mar 2015 17:06:37 +0100 Subject: [PATCH 002/173] refactor: rename data -> body --- resty | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/resty b/resty index 12c1d57..0766e6d 100644 --- a/resty +++ b/resty @@ -14,7 +14,7 @@ export _resty_path="" export _resty_nohistory="" function resty() { - local confdir datadir host cookies method h2t editor domain _path opt dat res ret out err verbose raw i j d tmpf args2 wantdata vimedit quote query maybe_query dry + local confdir datadir host cookies method h2t editor domain _path opt body res ret out err verbose raw i j d tmpf args2 hasbody vimedit quote query maybe_query dry local -a curlopt local -a curlopt2 @@ -31,14 +31,14 @@ function resty() { method="$1"; [[ $# -gt 0 ]] && shift h2t=$( (exec 2>&-; (which lynx >/dev/null && echo lynx -stdin -dump) \ || which html2text || which cat) |tail -n 1) - editor=$((exec 2>&-; which "$EDITOR" || which vim || echo "vi") |tail -n 1) + editor=$((exec 2>&-; which "$EDITOR" || which vim || echo "vi") |tail -n 1) # editor default - [ "${method#P}" != "$method" ] || [ "$method" = "TRACE" ] && wantdata="yes" + [ "${method#P}" != "$method" ] || [ "$method" = "TRACE" ] && hasbody="yes" + # hack: want data only for Put and Post - [ -d "$cookies" ] || (mkdir -p "$cookies"; echo "http://localhost*" > "$host") - [ -n "$1" ] && [ "${1#/}" != "$1" ] \ - && _path="$1" && [[ $# > 0 ]] && shift - [ "$1" = "${1#-}" ] && dat="$1" && [[ $# > 0 ]] && shift + [ -d "$cookies" ] || (mkdir -p "$cookies"; echo "http://localhost*" > "$host") # retrieve cookie + [ -n "$1" ] && [ "${1#/}" != "$1" ] && _path="$1" && [[ $# > 0 ]] && shift # retrieve path + [ "$1" = "${1#-}" ] && body="$1" && [[ $# > 0 ]] && shift # retrieve data j=1 for i in "$@"; do @@ -65,27 +65,28 @@ function resty() { case "$method" in HEAD|OPTIONS|GET|DELETE|POST|PUT|PATCH|TRACE) eval "curlopt2=(${_resty_opts[*]})" - dat=$( ( [ "$wantdata" = "yes" ] \ - && ( ( [ -n "$dat" ] && echo "$dat") \ + body=$( ( [ "$hasbody" = "yes" ] \ + && ( ( [ -n "$body" ] && echo "$body") \ || ([ ! -t 0 ] && echo "@-") ) ) || echo) - if [ "$wantdata" = "yes" ] && [ "$vimedit" = "yes" ]; then + if [ "$hasbody" = "yes" ] && [ "$vimedit" = "yes" ]; then tmpf=$(mktemp /tmp/resty.XXXXXX) [ -t 0 ] || cat > $tmpf (exec < /dev/tty; "$editor" $tmpf) - dat=$(cat $tmpf) + body=$(cat $tmpf) rm -f $tmpf fi - [ -n "$dat" ] && [ "$dat" != "@-" ] && [[ $# -gt 0 ]] && shift - [ "$1" = "-Z" ] && raw="yes" && [[ $# -gt 0 ]] && shift - [ -n "$dat" ] && opt="--data-binary" + [ -n "$body" ] && [ "$body" != "@-" ] && [[ $# > 0 ]] && shift + [ "$1" = "-Z" ] && raw="yes" && [[ $# > 0 ]] && shift + [ -n "$body" ] && opt="--data-binary" [ "$method" = "HEAD" ] && opt="-I" && raw="yes" - ## Retrieve stored option in confidir. + ## Retrieve stored option in config dir. ## §maybe: cache this when resty) - [ -f "$confdir/$domain" ] && eval "args2=( $(cat "$confdir/$domain" 2>/dev/null |sed 's/^ *//' |grep "^$method" |cut -b $((${#method}+2))-) )" - [ "$dry" = "yes" ] && echo "curl -sLv $opt \"$dat\" -X $method -b "$cookies/$domain" -c "$cookies/$domain" \"${args2[@]}\" \"${curlopt2[@]}\" \"${curlopt[@]}\" \"$_path$query\"" && return 0 + [ -f "$confdir/$domain" ] && eval "args2=( $(cat "$confdir/$domain" 2>/dev/null |sed 's/^ *//' |grep ^$method |cut -b $((${#method}+2))-) )" + [ "$dry" = "yes" ] && echo "curl -sLv $opt \"body\" -X $method -b "$cookies/$domain" -c "$cookies/$domain" \"${args2[@]}\" \"${curlopt2[@]}\" \"${curlopt[@]}\" \"$_path$query\"" && return 0 # TODO: refactor function - res=$( ( ( (curl -sLv $opt "$dat" -X $method \ + + res=$((((curl -sLv $opt "$body" -X $method \ -b "$cookies/$domain" -c "$cookies/$domain" \ "${args2[@]}" "${curlopt2[@]}" "${curlopt[@]}" "$_path$query" \ |sed 's/^/OUT /' && echo) 3>&2 2>&1 1>&3) \ From ad37bb0fca9ef65bdccbdf760e92a8761fef0006 Mon Sep 17 00:00:00 2001 From: Adriean Khisbe Date: Wed, 4 Mar 2015 10:07:21 +0100 Subject: [PATCH 003/173] refactor: convert Changes to changelog convention --- CHANGELOG.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ CHANGES.md | 29 ----------------------------- 2 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 CHANGELOG.md delete mode 100644 CHANGES.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8e06277 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,49 @@ +# Change Log +All notable changes to *Resty* will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +## [Unreleased][unreleased] +### Changed + +- major refactor +### Fixed +- Documentation glitch + +## History Black Hole to retrieve + + + +## [1.5] - 2011-03-20 +### Added +- Curl options can now be specified when calling the resty command to set + the URI base. These options will be passed to curl for all subsequent + requests, until the next time the resty command is called. + +## [1.4] - 2011-03-08 +### Fixed +- several bugs fix for zsh users. + +## [1.3] - 2011-03-04 + +* Attempted bug fix for zsh users that prevented options from being passed + correctly to curl. + +## [1.2] - 2011-02-06 - + +* Data is now optional in PUT and POST requests. If the input is not a + terminal and no data is specified on the command line, resty won't wait + for data on stdin anymore. If you liked the old behavior you can always do + something like `cat | POST /Somewhere` for the same effect. + +## [1.1] - 2011-01-07 +### Fixed +- bug where `-V` option required input on stdin, and would block waiting for it. + +