#!/bin/sh USER="you" PASS="seekrit" needs_escape=true while test -n "$1" ; do word="$1" shift case "$word" in --escaped) needs_escape= ;; *) URL=$word ;; esac done if test -z "$URL" ; then echo >&2 "$0 [--escaped] " exit 1 fi # http://en.wikipedia.org/wiki/Percent-encoding if test -n "$needs_escape" ; then URL=$(echo "$URL" | sed -e 's/\%/%25/g' \ -e 's/!/%21/g' \ -e 's/*/%2A/g' \ -e "s/'/%27/g" \ -e 's/(/%28/g' \ -e 's/)/%29/g' \ -e 's/;/%3B/g' \ -e 's/:/%3A/g' \ -e 's/@/%40/g' \ -e 's/&/%26/g' \ -e 's/=/%3D/g' \ -e 's/+/%2B/g' \ -e 's/\$/%24/g' \ -e 's/,/%2C/g' \ -e 's,/,%2F,g' \ -e 's/?/%3F/g' \ -e 's/#/%23/g' \ -e 's/\[/%5B/g' \ -e 's/]/%5D/g') fi # http://blog.instapaper.com/post/73123968/read-later-api SUBMIT="https://www.instapaper.com/api/add?username=$USER&password=$PASS&url=$URL&auto-title=1" RES=$(wget -q -O - "$SUBMIT") case "$RES" in 201) echo >&2 "This URL has been successfully added to this Instapaper account." exit 0 ;; 400) echo >&2 "Bad request. Probably missing a required parameter, such as url." exit 1 ;; 403) echo >&2 "Invalid username or password." exit 1 ;; 500) echo >&2 "The service encountered an error. Please try again later." exit 1 ;; *) echo "unhandled error: $RES" exit 1 ;; esac