Instructions - democracyworks/dw-code-exercise-lein-template GitHub Wiki

Getting started

Thank you for applying to work at Democracy Works! This coding exercise is designed to show off your ability to program web applications in Clojure. You should spend no more than 2 hours on it and then turn it in to us by running the command lein submit and following the instructions it prints out. While we will be evaluating how much of the project you complete, we know that 2 hours isn't enough time to do a thorough and complete job on all of it, and we're not expecting you to. We just want to see what you get working in that amount of time.

It is a server-side web application written in Clojure and using the Ring, Compojure, and Hiccup libraries.You should feel free to use other libraries as you see fit.

Right now the form below submits to a missing route in the app. To complete the exercise, do the following:

  • Create the missing /search route
  • Ingest the incoming form parameters
  • Derive a basic set of OCD-IDs from the address (see below for further explanation)
  • Retrieve upcoming elections from the Democracy Works election API using those OCD-IDs
  • Display any matching elections to the user

You will get bonus points for:

  • Documenting your code
  • Adding tests for your code
  • Noting additional features or other improvements you would make if you had more time

About OCD-IDs

OCD-IDs are Open Civic Data division identifiers and they look like this (for the state of Massachusetts): ocd-division/country:us/state:ma

A given address can be broken down into several OCD-IDs. For example, an address in Wayland, Massachusetts would be associated with the following OCD-IDs:

  • ocd-division/country:us
  • ocd-division/country:us/state:ma
  • ocd-division/country:us/state:ma/cd:5
  • ocd-division/country:us/state:ma/county:middlesex
  • ocd-division/country:us/state:ma/place:wayland
  • ocd-division/country:us/state:ma/sldl:13th_middlesex
  • ocd-division/country:us/state:ma/sldu:norfolk_bristol_and_middlesex

Not all of those are derivable from just an address (without running it through a standardization and augmentation service). For example, having a random address in Wayland doesn't tell us what county it is in. But we can derive a basic set of state and place (i.e. city) OCD-IDs that will be a good starting point for this project. This entails...

  • lower-casing the state abbreviation and appending it to ocd-division/country:us/state:
  • creating a copy of the state OCD-ID
  • appending /place: to it
  • lower-casing the city value, replacing all spaces with underscores, and appending it to that.

Then you should supply both OCD-IDs to your election API request, separated by a comma as shown in the example URL below.

https://api.turbovote.org/elections/upcoming?district-divisions=ocd-division/country:us/state:ma,ocd-division/country:us/state:ma/place:wayland

The response will be in the EDN format (commonly used in Clojure) by default, but you can request JSON by setting your request's Accept header to 'application/json' if you prefer.

Current elections

Depending on the time of year and whether it's an odd or even-numbered year, the number of elections in the system can vary wildly. We maintain an up-to-date list of OCD-IDs that will return an election until the dates they are listed under. Please refer to that for example OCD-IDs that will return an election to your app.