Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 150 lines (112 sloc) 4.016 kb

Setup

Installation

First make sure you've installed

- Git[http://git-scm.com/]
- Ruby
- Bundler[http://gembundler.com/]

And then

$ git clone https://github.com/infochimps/chiat_day_innovation_matcher.git
$ cd chiat_day_innovation_matcher
$ bundle install

Configuration

There are two configuration files this app depends upon.

The settings.yml file points at the MySQL database so provide an appropriate host and credentials. Copy it from the given example:

$ cp settings.example.yml settings.yml

The unicorn-conf.rb file is required if you want to run the app behind the Unicorn webserver.

$ cp unicorn-conf.example.rb unicorn-conf.example.rb

Here you can define where the app will log, leave its pids, and how it listens. You can also define the number of worker processes you want to run.

Running

You can run the app locally on port 4567 by just running it with Ruby:

$ ruby innovation_matcher.rb
== Sinatra/1.3.3 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4567, CTRL+C to stop

You can also run it with Unicorn

$ unicorn -c unicorn-conf.rb

which is what you should do in production, after you've tweaked the unicorn-conf.rb file.

Make sure that the user you're running this unicorn with can write to the directories you point at in the unicorn-conf.rb file. If you're using the example unicorn-conf.rb file then you might want to run a command like

$ chmod -R www-data:www-data log tmp

Usage

Create a match

Returns an array of innovations matching given parameters dob and hometown. Also returns a match_id that can be used to retrieve this match later.

If the name parameter is given, that name will be returned when asking for the match later.

Example:

$ curl -s -X POST http://localhost:4567/matches -d '{"dob": "1983-05-23", "hometown": "New York, NY", "name": "Dhruv Bansal"}'
{
  "match_id": "6b73f010-d469-012f-ad21-002219342852",
  "innovations": [
    {
      "id": "280",
      "type": "Automotive",
      "name": "internal combustion engine",
      "photo": "http://www.flickr.com/photos/ell-r-brown/6050366599/",
      "innovator_name": "NICOLAUS OTTO",
      "innovation_date": "8/14/1877"
      ...
    },
    { ... },
    ...
  ],
  "user_data": {
    "dob": "1983-05-23",
    "hometown": "New York, NY",
    "name": "Dhruv Bansal"
  }
}

Retrieve a match

Returns an array of innovations from a previously returned match_id.

If a name was passed in with the original match, it will be available as the fb_user value in the returned innovation object.

Example:

$ curl -s -X GET http://localhost:4567/matches/6b73f010-d469-012f-ad21-002219342852
{
  "match_id": "6b73f010-d469-012f-ad21-002219342852",
  "innovations": [
    {
      "id": "280",
      "type": "Automotive",
      "name": "internal combustion engine",
      "photo": "http://www.flickr.com/photos/ell-r-brown/6050366599/",
      "innovator_name": "NICOLAUS OTTO",
      "innovation_date": "8/14/1877",
      ...
      "fb_user": "Dhruv Bansal"
    },
    { ... },
    ...
  ]
}

JSONP & Callbacks

All URLs will accept the callback parameter to wrap the JSON response in a JavaScript callback suitable for JSON-P.

Example:

$ curl -s -X GET http://localhost:4567/matches/6b73f010-d469-012f-ad21-002219342852?callback=hello
hello({
  "match_id": "6b73f010-d469-012f-ad21-002219342852",
  "innovations": [
    {
      "id": "280",
      "type": "Automotive",
      "name": "internal combustion engine",
      "photo": "http://www.flickr.com/photos/ell-r-brown/6050366599/",
      "innovator_name": "NICOLAUS OTTO",
      "innovation_date": "8/14/1877",
      ...
      "fb_user": "Dhruv Bansal"
    },
    { ... },
    ...
  ]
})
Something went wrong with that request. Please try again.