Google Mirror API's Quickstart in Scala
CSS JavaScript Scala Java
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 114 commits ahead, 48 commits behind googleglass:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Mirror API Quickstart for Scala and Scalaz

This is a Scala port of Google's Quickstart for Java code (

My suggestion is to start reading the code in src/main/scala/com/seattleglassware/ServersAndFilters.scala. That has the servers for /main, /oauth2callback, /notify and /attachmentproxy.

You'll notice that the code makes heavy use of Scalaz, including EitherT and the State monad. Most of the functions are for-comprehensions that look like this:

  def insertSubscription = for {
    userId <- getUserId
    credential <- getCredential
    collection <- getParameter("collection")
    callbackUrl <- getGenericUrlWithNewPath("/notify")
    subscription <- m.insertSubscription(credential, callbackUrl.toString, userId, collection)
    _ <- addGlasswareEffect(AddMessage("Application is now subscribed to updates."))
  } yield subscription

The left side of the arrows (<-) are all successful results. The right side of the arrows are all functions that can do a few things:

  • Return a successful result, in which case the computation just keeps going
  • Return a failure result, in which case the computation ends and returns that failure

Threaded through those successes and failures are additions to state (that''s the state monad), so you can do things like have a function return a success and at the same time push an operation (like set a session variable) onto the state object.

Not a 100% complete port

Not everything is ported to Scala. The jsp pages are untouched, and there are a couple java classess (ListableAppEngineCredentialStore) that remain. Moving these over to Scala would be nice for completeness, but the existing Scala has enough samples that I don''t think finishing the remaining Java classes really adds much.