This is a solution for a coding challenge for appearhere.com!
Sadly it was never reviewed, even after a reminder email. Their CTO at the time simply went ‘radio silent’.
I would like to search for coffee shops near <Postcode> So that I can satisfy my caffeine needs
Examples: | Postcodes | | N1 6AA | | E2 8RS | | LA9 7RL |
I would like to see the results sorted by popularity So that I know what’s the best coffee shop to go to
I would like to know when there are no results So that I can search for a different postcode
-
ruby 2.2.3
-
rails 4.2.5
The application receives a postal code.
The application uses this API (postcodes.io/) to check the validity and geographic location of the postal code.
Then the app queries the foursquare API for a list of caffes, using the latitude and longitude got from the postal codes API.
The result information is then listed for the user.
Why use the postcodes public API? The Foursquare API to search for venues, only works with one of the two:
-
an address (using the parameter near)
-
a geographic location (latitude and longitude)
So I used the former. To get the latitude and longitude, given a postal code, I used the postcodes API.
I try to modularize and separate the code as most as I can. To avoid long controllers I use services. It is just a folder containing all the logic needed for each controller.
There are two models: Caffe and PostalCode.
# A PostalCode can have many caffes, and a caffe can have many PostalCodes as well. The reason for this is the following: in foursquare, we list the caffes that happen to be in x miles radius from a postal code. Now a Caffe could be in the intersection between two postal code’s, thus belonging to both.
# Caffe: store in database, timeout
The caffes are saved to the database, once retrieved from foursquare.
After getting a postal code the public postal codes API, one of three things can happen:
-
A new postal code is created, and the foursquare API is queried for the caffes list
-
The postal code is already in the database, and I load it, as well as the related caffes
-
The postal code is already on the database, but it’s an old record (more than 1 day old), so
I update it with what I get from foursquare
Note: A good optimization to the application would be to cache the results to be served, using redis.
I used a little frontend framework for creating responsive pages called skeleton. Also used the gmaps open javascript api. I’m not a frontend expert, so the UX could be improved a lot.
For testing I used Rspec, along with FactoryGirl and Faker.
For error awareness I implemented exception notifier, to send me an email each time an exception is raised.
The solution is on an EC2 machine. The machine uses nginx as the web server, and unicorn as the application server. I haven’t implemented automated deployment for the app. I just clone it from a private Bitbucket repository.