AlecKap / whether-sweater

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

Whether Sweater

About this Project

Important to Note

This is a Back End Application that exposes 4 endpoints. 3 external API keys are required for this application to function properly.

Never be surprised by weather on your RoadTrip again. Sweater Weather is a weather application where a user can see the current weather and forecasted weather of a specific location. A registered user can plan a roadtrip and see how long the trip will take and the weather upon arrival to their destination.

Built With

  • Ruby
  • Postgresql
  • Rails
  • Visual Studio Code

Running On

  • Rails 7.0.4
  • Ruby 3.1.1

Getting Started

To get a local copy, follow these instructions

Installation

  1. Fork the Project
  2. Clone the repo
#terminal
git@github.com:AlecKap/whether-sweater.git 
  1. Navigate to the newly cloned repo and open it in your text editor of choice
  2. Install the gems
#terminal
bundle install
  1. Create the database
#terminal
rails db:{create,migrate}
  1. Create application.yml
#terminal
bundle exec figaro install
  1. Add environment variables to application.yml file
  • Navigate to the application.yml file in the config directory
  • Add the following to the file
#application.yml
MAPQUEST_API_KEY: <your key here>
WEATHER_API_KEY: <your key here>
  1. Run Tests in the terminal to verify everything was set up correctly
#terminal
bundle exec rspec
  • All tests should be passing
  1. Run Rails Server from the terminal to verify you can successfully hit the endpoints
#terminal
rails s
  1. Test the endpoints
  • You can utilize Postman or VScodes Thunderclient to test the endpoints are running properly
  • Append http://localhost:3000 to each of the endpoints listed below.

Endpoints

      get 'api/v0/forecast'
      post 'api/v0/users'
      post 'api/v0/sessions'
      post 'api/v0/road_trip'

Forecast

Get current and the next 5 days weather for a location

Example request

get http://localhost:3000/api/v0/forecast?location=denver,co

Example response

"data": {
        "id": null,
        "type": "forecast",
        "attributes": {
            "current_weather": {
                "last_updated": "2023-06-12 19:45",
                "temperature": 54.0,
                "feels_like": 54.8,
                "humidity": 80,
                "uvi": 4.0,
                "visibility": 9.0,
                "conditions": "Partly cloudy",
                "icon": "//cdn.weatherapi.com/weather/64x64/day/116.png"
            },
            "daily_weather": [
                {
                    "date": "2023-06-13",
                    "sunrise": "05:32 AM",
                    "sunset": "08:29 PM",
                    "max_temp": 61.0,
                    "min_temp": 52.5,
                    "conditions": "Heavy rain",
                    "icon": "//cdn.weatherapi.com/weather/64x64/day/308.png"
                },
                {
                    "date": "2023-06-14",
                    "sunrise": "05:32 AM",
                    "sunset": "08:29 PM",
                    "max_temp": 83.1,
                    "min_temp": 48.9,
                    "conditions": "Patchy rain possible",
                    "icon": "//cdn.weatherapi.com/weather/64x64/day/176.png"
                },
                etc... for the next 3 days
            ],
            "hourly_weather": [
                {
                    "time": "00:00",
                    "temperature": 54.1,
                    "conditions": "Moderate rain at times",
                    "icon": "//cdn.weatherapi.com/weather/64x64/night/299.png"
                },
                {
                    "time": "01:00",
                    "temperature": 53.8,
                    "conditions": "Partly cloudy",
                    "icon": "//cdn.weatherapi.com/weather/64x64/night/116.png"
                },
                {
                    "time": "02:00",
                    "temperature": 53.4,
                    "conditions": "Cloudy",
                    "icon": "//cdn.weatherapi.com/weather/64x64/night/119.png"
                },
                etc... for the remaining 24 hours
            ]
        }
    }
}

User registration

Register for a new account

Example request

post http://localhost:3000/api/v0/users
  # in the body of the request, send
  {
  "email": "whatever@example.com",
  "password": "password",
  "password_confirmation": "password"
}

Example response

{
    "data": {
        "id": "3",
        "type": "users",
        "attributes": {
            "email": "whatever@examples.com",
            "api_key": "61e82e95170d1a917904be3967"
        }
    }
}

User Login

Login as a registered user (Designed for a front end application to store session information)

Example request

post http://localhost/api/v0/sessions
 # in the body of the request, send
  {
  "email": "whatever@example.com",
  "password": "password"
}

Example response (if the user exists and the passwords match)

{
  "data": {
    "type": "users",
    "id": "1",
    "attributes": {
      "email": "whatever@example.com",
      "api_key": "t1h2i3s4_i5s6_l7e8g9i10t11"
    }
  }
}

Road Trip

Find the travel time (by car) between two points and see the eta weather of your destination

Example request

post http://localhost/api/v0/road_trip
  #in the body of the request send
  {
  "origin": "Cincinatti,OH",
  "destination": "Chicago,IL",
  "api_key": "<your_api_key>"
}

Example response

{
    "data": {
        "id": "null",
        "type": "road_trip",
        "attributes": {
            "start_city": "Cincinatti, OH",
            "end_city": "Chicago, IL",
            "travel_time": "04:40:45",
            "weather_at_eta": {
                "datetime": "2023-04-07 23:00",
                "temperature": 44.2,
                "condition": "Cloudy with a chance of meatballs"
            }
        }
    }
}

Schema

create_table "users", force: :cascade do |t|
    t.string "email"
    t.string "password_digest"
    t.string "api_key"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

API's Used

  • MapQuest API (for directions)
  • Weather API (for weather information)

Author

  • Alec Kapicak GitHub LinkedIn

About


Languages

Language:Ruby 99.7%Language:HTML 0.3%