Git Product home page Git Product logo

caffefndr's Introduction

README

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’.

Probem

As a user 1

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 |

As a user 2

I would like to see the results sorted by popularity So that I know what’s the best coffee shop to go to

As a user 3

I would like to know when there are no results So that I can search for a different postcode

Solution

Requirements

  • ruby 2.2.3

  • rails 4.2.5

Main workflow:

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.

Design decisions:

Code organization:

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.

Database:

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.

Frontend

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.

Testing and error handling

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.

Deployment

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.

caffefndr's People

Contributors

pgcosta avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.