Coder Social home page Coder Social logo

postcode_checker's Introduction

Postcode Checker

Coding test: Postcode Service Checker

Details

Your customer would like a simple library, web-app or command line application to work out if a given postcode is within their service area. The input is a UK postcode and the output should be a boolean; true if that postcode can be served and false if not. We are using the Postcodes.io REST API as our source for data. The service area is described by the following rules:

  1. Postcodes are grouped into larger blocks called LSOAs. This is returned from the API when we query a postcode. We want to whitelist any postcode in an LSOA starting "Southwark" or "Lambeth". Example postcodes for these LSOAs are SE1 7QD and SE1 7QA respectively.
  2. Some postcodes are unknown by the API or may be served despite being outside of the whitelisted LSOAs. We need to be able to whitelist these anyway, even though the API does not recognise them. SH24 1AA and SH24 1AB are both examples of unknown postcodes that we want to serve.
  3. Any postcode not in the LSOA whitelist or the Postcode whitelist is not serviceable. Please note that no guarantees about the format of the input can be given, and the whitelists will need to be changed from time to time. Documentation for the Postcodes.io API can be found at http://postcodes.io/ For an example, you can either simulate the API on postcodes.io itself, or you could run:

Usage

In the root folder of the project simply execute bundle install to pull in the libraries needed to run the code. Please note that you will need Ruby version 2.2 or higher to be able to run this.

Once you have bundled the dependencies, simply run the programme passing it a web server log file. There's an exemplary file included in the project, so the following works: bin/postcode_checker "SE1 7QD"

Considerations

Whitelist config file

For the purpose of this exercise I have decided to use a config file for whitelisting, however I would normally consider either a UI to manage the configuration or environment variables (not discarding the config file itself).

Connect class

I have decided to wrap the HTTP client (Faraday in this case) in a separate class for convenience as I would imagine in the real world this class could do more validations (validate of uri for instance), however on the same token one could argue the wrapper could be removed for simplicity sake.

Postcode validation and formatting.

For the purpose of this project, postcode validation and formatting is a crucial step and it needs to be handled carefully. I have decided to use a gem UKPostcode.

To test the suitability of the gem I have used a list of valid postcodes and tested these postcodes against this gem and the gem has performed correctly, however, moving forward I would suggest to create an extensive suite of tests to continually test the gem to ensure it perform according to the business requirements and maybe participate in its development if it does not or create our own internal gem to handle this process.

This stack overflow thread provides insightful information on UK postcode validation: https://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive

Steps taken to validate the postcode gem against valid postcodes:

  • Downloaded postcode csv file from: https://www.doogal.co.uk/UKPostcodes.php
  • The zipped file is very large so I used the bash utility split to break the full list into smaller files: split -l 100 postcodes.csv new.csv and took a random file to use as test source.
  • Wrote the unit test to gem the gem against this set data.

Steps taken to validate the gem against invalid postcodes:

  • Found invalid postcodes online
  • Visited http://www.postoffice.co.uk/postcode-finder and check whether the postcode was valid. The Post Office tool tries to auto-complete the invalid postcodes with valid data, however it does not find addresses based on the exact match.

postcode_checker's People

Watchers

James Cloos 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.