Code Monkey home page Code Monkey logo

moip-test's Introduction

Moip Test

Introduction

Moip has an application that sends webhooks to the ecommerce of its clients. These webhooks have information about payments (if they were authorized, canceled, etc).

This application generates quite large logs. We need to find out through the log who are the clients who receive the most webhooks and verify all the response status returned by the clients' servers.

Task

The attached log file contains information about sending webhooks in format:

level=info response_body="" request_to"<url>" response_headers= response_status="<code>"

Where:

  • url: it is the url to which the webhook was sent
  • code: it is the status code returned by the client server
  • The other information is irrelevant to this task.

You must parse the file and at the end show the following information in the output:

The top 3 urls (most called) with their quantity A table showing the amount of webhooks by status

e.g.:

ps: the above result is not the real one.

Result

Create a repository on Github / Bitbucket with your solution and add documentation explaining how to run the program.

This task can be done using the programming language of your choice.

The evaluation will be based on:

  • Line of thought (document what you deem important)
  • Code design
  • Efficiency
  • Tests
  • Correct answer

My Solution

Programming Language and libraries

  • ruby 2.3.3 @ Windows 10 64-bits
  • rspec 3.5.0
  • terminal-table 1.7.3

My thoughts

  • I used Ruby because it's my favorite language. Simple like that.

  • I handled the URL and Status Code data as a pair, saving them in a hash ({"url" => "https: // ...", "code" => 201 "}). Then I added each pair in an array.

  • To manipulate the array of hashes, I create the following methods:

    • parse_line: to find in each log's line the URL and the status code, saving them in the array of hashes
    • top_three_url: to find the top 3 url in the array of hashes
    • count_status_code_table: to print a table with each status code and the amount of times they occurs
  • Finally, I used RSpec because of my knowledge with the library

Running the code

To run the code just type the following line in Terminal at project's root folder:

$ ruby main.rb

You can also run it with RSpec using the following line at project's root folder:

$ rspec spec/log_parser_spec.rb

moip-test's People

Contributors

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