isitchristmas/web — pull request #94 by konklone (2014-12-23 22:10:31+00:00)
Title: Adds an isitchristmas.com API and IFTTT channel

This is the code that powers [isitchristmas.com/api](https://isitchristmas.com/api), and the [Is It Christmas? IFTTT Channel](https://ifttt.com/isitchristmas).

[![ifttt](https://cloud.githubusercontent.com/assets/4592/5543650/3c35f31e-8ac5-11e4-8063-3c2cb34422b8.png)](http://blog.ifttt.com/post/105911049918/is-it-christmas-introducing-a-channel-to-answer)

(There are a few other small things in this branch, like arrow key support, as I worked on this branch in a separate private mirror until now.)

Nearly all of the relevant code is in [`api.js`](https://github.com/isitchristmas/web/blob/38a2021452a1176ffe0016b06679edb6ae795dd0/api.js).

It provides a couple of normal endpoints:

* The `/api` endpoint, which lists Christmases which have occurred since 2007, according to UTC (or the timezone you pass in a `timezone` parameter).
* And `/test`, which is just a heartbeat debugging endpoint to make sure the API is up and fine.

A number of IFTTT endpoints:

* The trigger for Christmas, which presents a similar list, but in accordance with IFTTT's spec.
* The trigger _field_ endpoint, which populates the timezone dropdown users see on IFTTT when they configure a personal or shared recipe using the channel.
* The trigger validation endpoint, which just verifies that a given option is a valid timezone entry. In theory, this should never be needed in practice, but it is a required endpoint.
* The status endpoint, which is used to indicate the server status. All this has to do for us is say :+1:, since if the IFTTT API is up, the whole website is up and Christmas is happening on schedule. For other channels, this endpoint might need to check the status of other backend services.
* The test sample endpoint, which provides IFTTT some example data it can use during automated channel testing.

I also made two timezone files:

* [`zones.js`](https://github.com/isitchristmas/web/blob/38a2021452a1176ffe0016b06679edb6ae795dd0/public/js/zones.js), which maps IFTTT timezone names (also used commonly in Ruby-land) to a different set of timezone names (used in Node-land).
* [`labels.js`](https://github.com/isitchristmas/web/blob/38a2021452a1176ffe0016b06679edb6ae795dd0/public/js/labels.js), which maps IFTTT timezone names to labels that include the offset, and are appropriate to show to the users in a dropdown dialog. I made this by literally copying the HTML from the timezone dropdown on IFTTT's user account page and manipulating it with regular expressions until I had myself a JSON object.

Altogether, it's a pretty small and simple API, but involved a surprising amount of rigor. Thanks to IFTTT for working with me on this on a short time line, and for including a link to the channel in their end-of-year newsletter!

![christmas lights](https://cloud.githubusercontent.com/assets/4592/5543728/8d23e00a-8ac6-11e4-941f-e170c4f76bf5.png)