This API was written as a part of the Opendoor interview process. A full problem description can be found in PROBLEM.md
Data is loaded from https://s3.amazonaws.com/opendoor-problems/listings.csv on boot.
The available endpoints are:
| Endpoint | Supported Methods | Description |
|---|---|---|
/ |
GET |
Returns the contents PROBLEM.md. |
/listings |
GET |
Fetch a JSON list of house listings. |
The /listings endpoint supports the following query parameters:
| Parameter | Description |
|---|---|
min_price |
The minimum listing price in dollars (inclusive). |
max_price |
The maximum listing price in dollars (inclusive). |
min_bed |
The minimum number of bedrooms (inclusive). |
max_bed |
The maximum number of bedrooms (inclusive). |
min_bath |
The minimum number of bathrooms (inclusive). |
max_bath |
The maximum number of bathrooms (inclusive). |
- Python 2.7 (currently,
MySQL-pythonis not Python 3 compatible) - VirtualEnv
- Foreman
The easiest way to run the app is to simply deploy it to Heroku. View the Deploying section for an easy, one click button to do this.
To run the app locally, start by creating a .env file containing a CLEARDB_DATABASE_URL and your credentials:
CLEARDB_DATABASE_URL=mysql://username:password@hostname.com/database
Next, run the following commands to install the Python dependencies
virtualenv env
source env/bin/activate
pip install -r requirements
foreman startIf you are running the app on OSX, you may encounter an error while installing MySQL-python. This can generally be cleared up by installing the MySQL C dependencies with brew install mysql.
After running foreman start, the app should be running on port 5000.
Currently, there are no tests (see the Future Improvements section for more info).
To run the Python linter, run:
make lint
This project is designed to be run on Heroku with a ClearDB MySQL backend (the free Ignite tier provides enough storage for the Opendoor CSV file). Information on manually deploying to Heroku can be found here.
At a minimum:
- Your API endpoint URL is
/listings. - Your API responds with valid GeoJSON (you can check the output using http://geojson.io).
- The output of this app has been linted against GeoJSONlint.com.
- Your API should correctly filter any combination of API parameters.
- Use a datastore.
- This projected is backed my MySQL. The Heroku deploy button creates a ClearDB MySQL instance for storing and manipulating the data.
Bonus Points:
- Pagination via web linking (http://tools.ietf.org/html/rfc5988).
- The
Linkheader can be easily viewed withcurlby runningcurl -i "http://API-URL:5000/listings?page=30".firstandlastpaging is always available, andprevandnextare available when applicable.
- The
Given more time, I would like to make the following improvements:
- Tests (primarily unit and acceptance).
- Filtering based on the
statusof the listings. Currently, all listings are being returned with no indicator of what state they are in (active,pending, orsold). - Currently, every query against
/listingscreates a new MySQL connection. Ideally, one connection could be created when the app launches and be refreshed when a disconnect is detected. - Page sizes are currently static (locked to 15). There should be a
countparameter to make this configurable. - Better exception handling. There area a couple places where exception handling could be improved, such as around the database connection and around the handling of the CSV data.
- Sorting. The
/listingsendpoint currently always sorts byid.
