docs » Leanpub

Spoon to track and notify about Leanpub builds.

Download: https://github.com/Hammerspoon/Spoons/raw/master/Spoons/Leanpub.spoon.zip

API Overview

API Documentation

Variables

api_key
Signature Leanpub.api_key
Type Variable
Description

String containing the key to use for Leanpub API requests. Get it from your Leanpub account under the "Author / Your API Key" menu section. No default.

check_interval
Signature Leanpub.check_interval
Type Variable
Description

Integer containing the interval (in seconds) at which the book status is checked. Default 5.

fetch_leanpub_covers
Signature Leanpub.fetch_leanpub_covers
Type Variable
Description

Boolean indicating whether we should try to fetch book covers from Leanpub (default true)

logger
Signature Leanpub.logger
Type Variable
Description

Logger object used within the Spoon. Can be accessed to set the default log level for the messages coming from the Spoon.

persistent_notification
Signature Leanpub.persistent_notification
Type Variable
Description

Table specifying the Leanpub status for which notifications should not disappear automatically. The indices correspond to the values of the status field returned by the Leanpub API. Possible values are working and complete. Default { complete = true } to keep the "Book generation complete" messages.

watch_books
Signature Leanpub.watch_books
Type Variable
Description

List of books to watch (by default an empty list). Each element of the list must be a table containing the following keys:

  • slug - the web page "slug" of the book to watch. The slug of a book can be set under the "Book Web Page / Web Page URL" menu section in Leanpub.
  • icon - optional icon to show in the notifications for the book, as an hs.image object. If not specified, and if fetch_leanpub_covers is true, then the icon is generated automatically from the book cover.

Methods

displayAllBookStatus
Signature Leanpub:displayAllBookStatus()
Type Method
Description

Check and display (if needed) the status of all the books in watch_books

displayBookStatus
Signature Leanpub:displayBookStatus(book)
Type Method
Description

Display a notification with the current build status of a book. Only produce a notification if the current status is different than the last known one (from the last time displayBookStatus was run for the same book).

Parameters:

  • book - table containing the information of the book to check. The table must contain the following fields:
    • slug - URL "slug" of the book to check. The slug is the part of the book URL after https://leanpub.com/.
    • icon - optional icon to show in the notifications for the book, as an hs.image object. If this field is not specified but fetch_leanpub_covers is true (the default value), this method attempts to fetch the book cover from Leanpub. If the cover can be retrieved, it gets stored in the icon field so it doesn't get fetched every time. You can disable cover fetching for individual books by setting this field explicitly to false

Returns:

  • A Lua table containing the status (may be empty), nil if an error occurred
fetchBookCover
Signature Leanpub:fetchBookCover(slug)
Type Method
Description

Fetch the cover of a book.

Parameters:

  • book - slug for the book

Returns:

  • The image object if it can be fetched, nil otherwise
getBookStatus
Signature Leanpub:getBookStatus(slug)
Type Method
Description

Get the status of a book given its slug.

Parameters:

  • slug - URL "slug" of the book to check. The slug of a book is the part of the URL for your book after https://leanpub.com/.

Returns:

  • Table containing the fields returned by the Leanpub API. If the book is not being built at the moment, an empty table is returned. If an error occurs, returns nil. Samples of the return values can be found at https://leanpub.com/help/api#getting-the-job-status
start
Signature Leanpub:start()
Type Method
Description

Start periodic check for book status, checking every check_interval seconds.

stop
Signature Leanpub:stop()
Type Method
Description

Stops periodic check for book status, if enabled. check_interval seconds.