Giter Club home page Giter Club logo

air-price-exercise's Introduction

Air Price Excercise for Priceline

When running on dev it will provide a REST JSON interface at port 4000 with a single endpoint /findCheapestOffer.

Which will return a single offer with the lowest price if found, otherwise it will return null.

Getting started on dev

$ AIR_FRANCE_KEY=xxx BRITISH_AIRWAYS_KEY=xxx mix do deps.get, app.start

Endpoint /findCheapestOffer

Parameters

  • origin: IATA code for origin airport
  • destination: IATA code for destination airport
  • departureDate: Date of the departure in the format "YYYY-MM-DD"

Example request:

http://localhost:4000/findCheapestOffer?origin=BER&destination=LHR&departureDate=2021-12-12

Implementation

Application supervisor is defined at lib/air_price.ex

Cowboy and Plug are used to serve http.

The module AirPrice.Providers at lib/air_price/providers.ex exposes find_cheapest/1, fetch/1 and fetch/2, the first returns the cheapeast offer if any and the second all of the offers matching the criteria.

Fetching from all SOAP providers is performed concurrently using supervised Tasks. If a request fails it will be logged, but it will not prevent getting results from other providers.

Each of AirPrice.Poviders.AirFrance and AirPrice.Providers.British use a macro module AirPrice.Providers.Soap that will define the common functions for consuming the SOAP API. A SOAP provider must implement request_body/1 and parse/1.

No tests have been written, but I generally write enough unit tests to have confidence to refactor and as many integration tests to a have a good degree of confidence.

To mock requests I tend to define a Mock Plug server and dependency inject the url, here's an exaple for some other code exercise.

https://github.com/maca/air-quality-exercise/blob/master/test/mock_server.exs

taken from here:

https://medium.com/flatiron-labs/rolling-your-own-mock-server-for-testing-in-elixir-2cdb5ccdd1a0

air-price-exercise's People

Contributors

maca avatar

Watchers

 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.