Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

sasalatart/on-this-day-sinatra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

On This Day

License: MIT Docker Automated build Code Climate

About

Application built with Sinatra and React that returns events, births and deaths that occurred during a specific day of history. This information has been retrieved from Wikipedia using a scraper.

API Usage

Events

Returns an array of JSON historical events, filtered by day and month.

  • URL: /events?day=<day>&month=<month>

  • Method: GET

  • URL Params

    • day=[integer], any number between 1 and 31
    • month=[integer], any number between 1 and 12
  • Success Response:

    • Code: 200
    • Example content:
      {
        day_month: {
          id: 32,
          day: 1,
          month: 2,
          description: "February 1 is the 32nd day of the year in the Gregorian calendar. There are 333 days remaining until the end of the year (334 in leap years). This date is slightly more likely to fall on a Monday, Wednesday or Friday (58 in 400 years each) than on Saturday or Sunday (57), and slightly less likely to occur on a Tuesday or Thursday (56).",
          episodes: [
            {
              id: 10659,
              year: 2013,
              bce: false,
              episode_type: "event",
              text: "The Shard, the tallest building in the European Union, is opened to the public.",
              day_month_id: 32,
              keywords: [
                {
                  id: 21624,
                  episode_id: 10659,
                  title: "List of tallest buildings in the European Union",
                  href: "/wiki/List_of_tallest_buildings_in_the_European_Union"
                }, {
                  id: 21623,
                  episode_id: 10659,
                  title: "The Shard",
                  href: "/wiki/The_Shard"
                }, {
                  id: 21622,
                  episode_id: 10659,
                  title: "2013",
                  href: "/wiki/2013"
                }
              ]
            }, {
              ...
            }
          ]
        }
      }
  • Error Response:

    • Code: 400
    • Content:
      { error: "Not a valid request." }
  • Sample Call:

    $.ajax({
      url: "/events?day=25&month=12",
      dataType: "json",
      type : "GET",
      success : function(response) {
        console.log(response);
      }
    });

Births And Deaths

The API is the same for births and deaths, but instead of making a call to /events, it should be done to either /births or /deaths.

Setup

Development

  1. cd into client and:
  • run npm install
  • run npm start
  1. open a new shell instance, cd into server and:
  • run bundle install
  • run rake db:reset
  • run shotgun config.ru

Docker

# Pull and run the application and PostgreSQL
$ docker run -d --name=postgres_db postgres:9.6.1
$ docker run -d --name=onthisday -p 80:9292 --link=postgres_db:postgres_db sasalatart/on-this-day-sinatra

# Setup the database
$ docker exec onthisday rake db:reset

The server's machine should now be redirecting its port 80 to the container's port 9292.