mea-libris

command module
v0.0.0-...-a512109 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2016 License: MIT Imports: 17 Imported by: 0

README

GoDoc GoReportCard

Shows your Google Books list as JSON or CSV.

FAQ

How do I run this?

This command needs OAuth credentials to access your book data, which can be created at Google API Console. The whole process for server-side web apps is explained here.

In particular, you'll need to register an authorized redirect URL, which will receive Google's auth responses. This program offers the /google/oauth2callback endpoint for that, so use the full URL: http://<my-running-server>/google/oauth2callback.

Your instance's Google OAuth credentials are read via two environment variables, GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET.

Optionally, this command also reads two more environment variables:

  • PORT: the port the server will be bound to. Defaults to 8080.
  • GOOGLE_REDIRECT_URL: forces a specific redirect URL. More on this below.
OK, it's running. Now what?

A running instance provides the following endpoints:

GET /google

Returns your books in either JSON or CSV, depending on the request's Accept header. Will return 401 if the user hasn't previously allowed this instance to access her data.

GET /google/connect

Starts the auth exchange. As per OAuth, the user will be redirected to a Google consent screen to authorize this instance to get the data, and then redirected back. Will error out if this instance wasn't previously authorized in the user's Google API Console.

GET /google/disconnect

Revokes the user's authorization. Any further accesses to /google will be 401'ed until the user /google/connects again.

GET /google/oauth2callback

This is called by Google's OAuth servers to answer /google/connect requests. As mentioned above, the /google/oauth2callback endpoint should be registered in the Google API Console as an authorized redirect URL.

Google doesn't accept the redirect URL!

Yeah... mea-libris can build the redirect URL itself, but:

  • Google demands the URL to be an exact match (scheme, host, port and path) with what's registered in the API Console; and
  • I don't know a sure-fire way to get all the information needed (e.g. the scheme isn't always there, so mea-libris defaults to http).

So, as an escape hatch, mea-libris will use the contents of the GOOGLE_REDIRECT_URL environment variable, if available.

How do I build this?

mea-libris uses Go (version 1.6+) and Glide.

After the setup, compile and run:

$ glide update -v
$ go install 
$ $GOPATH/bin/mea-libris

Alternatively, you could just deploy it in the cloud, without building it at all (if your cloud provider supports Go and Glide):

$ cf push mea-libris -b go_buildpack

I've used Cloud Foundry here, but pick your favorite :)

But I don't like Glide; I prefer <take your pick>!

I've found Glide to be nice, but I have no strong opinion or experience either way. The main requirement was something supported by Cloud Foundry (which I'm also checking out), so Glide worked well enough.

Why Google Books and not Amazon?

Seemed like the easiest to tackle. Amazon books should come, eventually :)

Upon further reading, Amazon apparently doesn't have a public API or any interest in making one. So... I'd need some (ahem) alternative means to get that information automatically 😜 Any suggestions?

The books I've previously rented aren't appearing!

Well, Google's Books API describes previously rented books as "User-rented books past their expiration time". So, if the books are expired, they're not "your" books any more ;)

Documentation

Overview

mea-libris starts a web server which shows your books. Right now, Google Books is the only service supported.

It needs 2 environment variables to function: GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET, which are this app's Google credentials. They are necessary to reach your Google books via OAuth.

mea-libris will use other 2 environment variables if available:

PORT: the port which this server will listen to. Defaults to 8080.

GOOGLE_REDIRECT_URL: the URL Google's OAuth server will respond to, as part of
  the OAuth authorization flow. Defaults to
  (request.URL.Scheme || http)://(request.Host)/google/oauth2callback.

More details at https://github.com/hanjos/mea-libris .

Directories

Path Synopsis
Package app defines the different pieces of the application, which are all put together in main.
Package app defines the different pieces of the application, which are all put together in main.
Package libris defines the Book type, which represents the user's books, and methods to encode books in JSON or CSV.
Package libris defines the Book type, which represents the user's books, and methods to encode books in JSON or CSV.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL