Giter Site home page Giter Site logo

findcheapestprice's Introduction

Flyiin

Makefile

  • Lint and format targets are to keep track of styling in elixir
  • test target is to run mix via make
  • run is to run app
  • outdated is to check if libs are outdated

Phoenix

The usage of Phoenix is due to the elixir community standart. I prefer to work with webserver that implement interceptor concept, like Clojure's Pedestal and Java Spark, this is due to their ability to evolve by writing new interceptor or by changing the service configs. I have removed most of the files that are useless for an API, like views. There is a healthcheck for stabilizing purpose. Due to the usage of scope and routing pattern, the path is /findCheapestOffer/?origin=<IATA>&destination=<IATA>&departureDate=<DATE>

HTTP Client

Well, I had in mind to use HTTPoison, but by some typo during search of the mix deps info I started using HTTPotion, which was pretty good for this low demand service.

Mox

I used Mox to mock the request make to the apis, this helped develop as also focus on testing Factory class was used to return the soap responses from the API. I removed unused lines of XML to reduce garbage. Mox is available only for testing env.

Testing

Although I started the project from top-down, the core logic was made bottom-up, which can be easily viewed on commits. This extensive testing and change of approach made possible to remove redundant tests, but generated some extra functions, which also did not help on the pattern matching side. The bottom-up strategy made it harder to use less verbose Task functions, such as async_stream.

Amedeus responds 200 with erros

Due to the fact tha Amadeus and Sabre may return a status code 200 but with an invalid xml, I included the following lines:

# Flyiin.Cheapest.Http.Main
def get_best_value(response, path, status, errors) when status == 200 and errors < 1 do
...

def process_task(task, path) do
  ...
  errors = task_result |> Map.get(:body) |> xpath(~x"//Error"l) |> length
  get_best_value(task_result, path, Map.get(task_result, :status_code), errors)
end

This was not tested because I had no more time to work on the project, but I would just create a new factory that returns a status 200 with a body containing the tags <Error>.

Concurrency

As this had only two requests and the xpath lib is pretty fast, the only concurrency I used was Task.async. The function fetch_airlines_pricing would be prettier if I did not have to assign values inside the map to make a request, but the general complexity would have increased. Another way I think it would be a good solution for multiple "Backend APIs" is to use infosys.

Security

I forgot in the first commit to read the api_keys from the env_vars, as they will expire and have limited, I am not so worried about their public usage.

obs. AFKL API was having problems to respond.

TODO

  • Request date is incorrectly formated -> 400
  • Request iatas dont have 3 letters -> 400
  • Task return != 2xx for one request

findcheapestprice's People

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.