Last active
January 3, 2016 17:51
-
-
Save bennylope/82ea9b5c6490bb2d617f to your computer and use it in GitHub Desktop.
A Leanpub API client script
This file contains 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
#!/usr/bin/env bash | |
# Copyright 2016, Ben Lopatin | |
# Licensed freely to use, modify, and redistribute under GNUGPLv3 | |
APIKEY=$LEANPUB_API_KEY | |
SLUG=$LEANPUB_SLUG | |
case "$1" in | |
preview) | |
case "$2" in | |
subset) | |
curl --silent -d "api_key=$APIKEY" https://leanpub.com/$SLUG/preview/subset.json | |
exit | |
;; | |
""|all) | |
curl --silent -d "api_key=$APIKEY" https://leanpub.com/$SLUG/preview.json | |
exit | |
;; | |
status) | |
curl --silent "https://leanpub.com/$SLUG/book_status?api_key=$APIKEY" | python -mjson.tool | |
exit | |
;; | |
*) | |
curl --silent -X POST -d "$(cat $2)" \ | |
-H "Content-Type: text/plain" \ | |
https://leanpub.com/$SLUG/preview/single.json\?api_key\=$APIKEY | |
exit | |
;; | |
esac | |
;; | |
publish) | |
case "$2" in | |
status) | |
curl --silent \ | |
"https://leanpub.com/$SLUG/book_status?api_key=$APIKEY" | python -mjson.tool | |
exit | |
;; | |
"") | |
echo "Are you ready to publish?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes) | |
curl --silent \ | |
-d "api_key=APIKEY" \ | |
https://leanpub.com/$SLUG/publish.json | |
exit | |
;; | |
No) | |
echo "Aborting" | |
exit | |
;; | |
esac | |
done | |
exit | |
;; | |
*) | |
echo "Are you ready to publish and send your release notes?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes) | |
curl --silent \ | |
-d "api_key=$APIKEY" \ | |
-d "publish[email_readers]=true" \ | |
-d "publish[release_notes]=${@:2}" \ | |
https://leanpub.com/$SLUG/publish.json | |
exit | |
;; | |
No) | |
echo "Aborting" | |
exit | |
;; | |
esac | |
done | |
exit | |
;; | |
esac | |
exit | |
;; | |
info) | |
curl --silent https://leanpub.com/$SLUG.json?api_key=$APIKEY | python -mjson.tool | |
exit | |
;; | |
sales) | |
case "$2" in | |
""|summary) | |
curl --silent https://leanpub.com/$SLUG/sales.json?api_key=$APIKEY | python -mjson.tool | |
exit | |
;; | |
all) | |
curl --silent https://leanpub.com/$SLUG/individual_purchases.json?api_key=$APIKEY | python -mjson.tool | |
exit | |
;; | |
esac | |
exit | |
;; | |
coupons) | |
echo "No coupons just yet" | |
exit | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment