<commit_before># ToDo [![Build Status](https://travis-ci.org/mssola/todo.svg?branch=master)](https://travis-ci.org/mssola/todo)

## About this application

This application has a simple job: handle my "To Do list". This might seem
trivial but I got to a point where my To Do list was a scrambled mess that was
scattered throughout my system. To fix this situation I've built a service that
has the following specifications:

* There only exists one user in the database.
* The "To Do" list is organized in topics. Topics can be created, deleted,
  renamed, updated, etc.
* A topic has contents, that are written in Markdown.

This application implements two things: a web application and an API layer.

### The Web Application

The web application has a quite minimalistic design and it only consists of two
different pages:

1. The `login` page.
2. The `topics` page. This is the main page and in it the user can create new
   topics, read their contents, update them, etc.

The style for this web application has been taken from Reddit's one (the list
of topics in this application has the same style as the list of multireddits).
The markdown being shown has a similar style as the one from Github. A
snapshot:

![The main page](public/images/snapshot.png)

### The JSON API

This application also implements a JSON API. This API can be accessed by
setting `application/json` in the `Content-Type` or the `Accept` header of the
request. First of all, you have to login with the application. In order to do
so, you have to perform a POST HTTP request with the following body:

```json
{
  "name":     "name-of-the-user",
  "password": "<PASSWORD>"
}
```

If everything was ok, the response should only be a JSON object with the
`token` key. The value for this key has to be used on every request afterwards
by adding it to the URL query part. With this in mind, we can now call any
method of this simple REST API:

|    Method   |        Path       | Keys in the JSON body |     Response    |
|:-----------:|:-----------------:|:---------------------:|:---------------:|
|GET          | /topics           |            -          | Array of Topics |
|POST         | /topics           |          name         |      Topic      |
|GET          | /topics/{topicId} |            -          |      Topic      |
|PUT or PATCH | /topics/{topicId} |    name or contents   |      Topic      |
|DELETE       | /topics/{topicId} |            -          |     Message     |


The fourth method is the update method. It accepts either the name or the
contents, but not both parameters at the same time. We might want to pass the
`name` key when renaming a topic. We will pass the `contents` key if we
want to update the contents of a topic. Moreover, the last method is the delete
method. This method responds with a `Message` object. A `Message` object
contains the key `msg` on success, and the `error` key on error.

Let's see a quick example (cURL with the `--trace-ascii` option):

    0000: POST /topics?token=6b6c<PASSWORD>-<PASSWORD>-4<PASSWORD>-5dd8-92<PASSWORD>43dbcaf HTTP/1.
    0040: 1
    0043: User-Agent: curl/7.38.0
    005c: Host: localhost:3000
    0072: Accept: */*
    007f: Content-Type: application/json
    009f: Content-Length: 17
    00b3:
    => Send data, 17 bytes (0x11)
    0000: {"name": "topic"}

The create method will respond with the newly created Topic on success:

```json
{
  "id":         "ec654b88-e227-47bb-6254-60b77329732e",
  "name":       "topic",
  "contents":   "",
  "created_at": "2014-10-07T08:37:05.424276522+02:00",
  "markdown":   ""
}
```

So, let's explain the `Topic` object. The `id`, `name` and `created_at` columns
are quite self-explanatory. The `contents` column exposes the raw data of this
object. The `markdown` object contains the HTML code that has been produced
after rendering the markdown of the `contents` column.

## Getting this application up and running

This application uses the Go programming language and some awesome packages
like negroni, gorilla/mux, blackfriday, etc. Moreover, it uses PostgreSQL
for the database. You can install the dependencies manually and setup
the db/database.json file by yourself, or you can just perform the
following command:

    ./script/kickstart

It will ask for a few DB-related things: the user, the dbname and the password.
After this, you can install this like any other Go program and run it:

    go install
    todo

Last but not least, this application can be deployed to Heroku. Here are some
notes about it:

* This application uses PostgreSQL, so you have to setup PostgreSQL in
  Heroku as well.
* Even though this application uses Sass, it has the resulting compiled CSS
  files in it. This is done this way so we don't have to mess with Sass on
  deployment.
* We'll have to use a third-party buildpack in order to deploy this
  application.

So, pick up your terminal and perform the following command:

    $ heroku create -b https://github.com/kr/heroku-buildpack-go.git

This will create the application with a Go buildpack setup. You should now go
to this application's config page on Heroku and add it the PostgreSQL add-on.
After this, no more configuration is needed, so you can just perform the
following command:

    $ git push heroku master
<commit_msg>Fixed a couple of typos in the README file.<commit_after># ToDo [![Build Status](https://travis-ci.org/mssola/todo.svg?branch=master)](https://travis-ci.org/mssola/todo)

## About this application

This application has a simple job: handle my "To Do list". This might seem
trivial but I got to a point where my To Do list was a scrambled mess that was
scattered throughout my system. To fix this situation I've built a service that
has the following specifications:

* There only exists one user in the database.
* The "To Do" list is organized in topics. Topics can be created, deleted,
  renamed, updated, etc.
* A topic has contents, that are written in Markdown.

This application implements two things: a web application and an API layer.

### The Web Application

The web application has a quite minimalistic design and it only consists of two
different pages:

1. The `login` page.
2. The `topics` page. This is the main page and in it the user can create new
   topics, read their contents, update them, etc.

The style for this web application has been taken from Reddit's one (the list
of topics in this application has the same style as the list of multireddits).
The markdown being shown has a similar style as the one from Github. A
snapshot:

![The main page](public/images/snapshot.png)

### The JSON API

This application also implements a JSON API. This API can be accessed by
setting `application/json` in the `Content-Type` or the `Accept` header of the
request. First of all, you have to login with the application. In order to do
so, you have to perform a POST HTTP request with the following body:

```json
{
  "name":     "name-of-the-user",
  "password": "<PASSWORD>"
}
```

If everything was ok, the response should only be a JSON object with the
`token` key. The value for this key has to be used on every request afterwards
by adding it to the URL query part. With this in mind, we can now call any
method of this simple REST API:

|    Method   |        Path       | Keys in the JSON body |     Response    |
|:-----------:|:-----------------:|:---------------------:|:---------------:|
|GET          | /topics           |            -          | Array of Topics |
|POST         | /topics           |          name         |      Topic      |
|GET          | /topics/{topicId} |            -          |      Topic      |
|PUT or PATCH | /topics/{topicId} |    name or contents   |      Topic      |
|DELETE       | /topics/{topicId} |            -          |     Message     |


The fourth method is the update method. It accepts either the name or the
contents, but not both parameters at the same time. We might want to pass the
`name` key when renaming a topic. We will pass the `contents` key if we
want to update the contents of a topic. Moreover, the last method is the delete
method. This method responds with a `Message` object. A `Message` object
contains the key `msg` on success, and the `error` key on error.

Let's see a quick example (cURL with the `--trace-ascii` option):

    0000: POST /topics?token=<PASSWORD> HTTP/1.
    0040: 1
    0043: User-Agent: curl/7.38.0
    005c: Host: localhost:3000
    0072: Accept: */*
    007f: Content-Type: application/json
    009f: Content-Length: 17
    00b3:
    => Send data, 17 bytes (0x11)
    0000: {"name": "topic"}

The create method will respond with the newly created Topic on success:

```json
{
  "id":         "ec654b88-e227-47bb-6254-60b77329732e",
  "name":       "topic",
  "contents":   "",
  "created_at": "2014-10-07T08:37:05.424276522+02:00",
  "markdown":   ""
}
```

So, let's explain the `Topic` object. The `id`, `name` and `created_at` columns
are quite self-explanatory. The `contents` column exposes the raw data of this
object. The `markdown` object contains the HTML code that has been produced
after rendering the markdown of the `contents` column.

## Getting this application up and running

This application uses the Go programming language and some awesome packages
like negroni, gorilla/mux, blackfriday, etc. Moreover, it uses PostgreSQL
for the database. You can install the dependencies manually and setup
the db/database.json file by yourself, or you can just perform the
following command:

    $ ./script/kickstart

It will ask for a few DB-related things: the user, the dbname and the password.
After this, you can install this like any other Go program and run it:

    $ go install
    $ todo

Last but not least, this application can be deployed to Heroku. Here are some
notes about it:

* This application uses PostgreSQL, so you have to setup PostgreSQL in
  Heroku as well.
* Even though this application uses Sass, it has the resulting compiled CSS
  files in it. This is done this way so we don't have to mess with Sass on
  deployment.
* We'll have to use a third-party buildpack in order to deploy this
  application.

So, pick up your terminal and perform the following command:

    $ heroku create -b https://github.com/kr/heroku-buildpack-go.git

This will create the application with a Go buildpack setup. You should now go
to this application's config page on Heroku and add it the PostgreSQL add-on.
After this, no more configuration is needed, so you can just perform the
following command:

    $ git push heroku master

{'fraction_non_alphanumeric': 0.08877086494688922, 'fraction_numerical': 0.020201062215477995, 'mean_word_length': 3.0171428571428573, 'pattern_counts': {'":': 16, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '32459', 'n_tokens_mistral': 3116, 'n_tokens_neox': 2929, 'n_words': 1486}