Created
April 23, 2014 00:49
-
-
Save tophyr/11199362 to your computer and use it in GitHub Desktop.
dsc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
dsc $1 $2 $($(dirname $0)/dsc_local) $3 put json "$4" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$1" = "usage" ]; then | |
echo "dsc <username> <password> <host (incl protocol)> <endpoint> [<method> [<content type> [<data>]]]" | |
echo | |
echo "host must include either the http:// or https:// and a full domain name." | |
echo "endpoint is everything else in the url, except restapi/v2/ (ex: /accounts/2/connect/mobile_notifiers)" | |
echo "method is {get|put|post|delete} (case insensitive)" | |
echo "content type is {raw|xml|json}. if valid content type is not specified, data will not be sent." | |
echo "data is any data you'd like to send. currently does not support streaming from stdin; this is a TODO" | |
exit | |
fi | |
USERNAME=$1 | |
PASSWORD=$2 | |
AUTH="-H \"X-Authentication:<censored>\"" | |
HOST=$3 | |
ENDPOINT=$4 | |
METHOD=$(echo $5 | tr '[:lower:]' '[:upper:]') | |
CURL="" | |
if [ ! -z "$7" ]; then | |
DATA="--data-binary \"$7\"" | |
else | |
DATA= | |
fi | |
if [ "$6" == "raw" ]; then | |
TYPE="-H \"Content-Type: application/octet-stream\"" | |
POSTPROCESS= | |
elif [ "$6" == "xml" ]; then | |
TYPE="-H \"Content-Type: application/xml\"" | |
POSTPROCESS= | |
elif [ "$6" == "json" ]; then | |
TYPE="-H \"Content-Type: application/json\"" | |
POSTPROCESS=" | python -mjson.tool" | |
else | |
echo Unrecognized or no content type specified. | |
TYPE= | |
POSTPROCESS= | |
if [ ! -z "${DATA}" ]; then | |
echo Disallowing data send. | |
DATA= | |
fi | |
fi | |
CURL="curl -v ${AUTH} -X ${METHOD:-GET} ${HOST}/restapi/v2/${ENDPOINT} ${TYPE} ${DATA} 2> >(grep -e '^[<>]' 1>&2) ${POSTPROCESS}" | |
eval ${CURL} | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment