gtasks

A command-line client (Ruby gem) for managing Google Tasks from the terminal. It can list, add, complete, and delete tasks, and clear all completed tasks at once; complete and delete accept a task number or, alternatively, a regular expression matched against task names for batch processing.

Google’s OAuth2 authentication is handled entirely within the command: on first run it starts a small local WEBrick server to receive the callback, then saves the obtained token to a file for reuse.

Internal design

The single file lib/gtasks.rb contains three layered classes: GoogleTaskAPI, which handles REST calls and authentication; GoogleTask, which wraps it in convenient methods; and GoogleTaskCLI, which formats output for the terminal.

Component diagram of gtasks

Authentication works like this: on first run it prints the authorization URL for the user to open in a browser, receives the authorization code on a local WEBrick server (by default /oauth_callback on port 9999), exchanges it for a token, and saves it as YAML to ~/.google_tasks.yml. Since it requests access_type=offline it also receives a refresh token, so subsequent runs just load the file and refresh — no browser needed.

Sequence diagram of the gtasks OAuth2 authentication flow

If the saved file has no refresh token it falls back to re-authentication, and if the initial authentication fails it deletes the token file so it can be recreated.