Contributors Forks Stargazers Issues


Sweater Weather

An API service that retrieves current weather, daily weather, and hourly weather by geographical location.
Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Available Endpoints
  4. Goals
  5. Database Schema

About The Project


This project utilizes the MapQuest API geocoding endpoint to retrieve the lattitude and longititute for a given location. These coordinates are then fed through to the WeatherAPI service to retrive the current weather, daily weather for the next 5 days, and the hourly weather. This data is then provided in the forecast endpoint.

(back to top)

Built With:

  • Ruby 3.1.1
  • Rails 7.0.4
  • Postgresql

(back to top)

Getting Started

This is a Ruby on Rails application which establishes API endpoints to be called in an application like Postman. To get started, please follow the directions below.


Installation

  1. Clone the repo:

    git clone git@github.com:DMTimmons1/sweater_weather.git
  2. Install gems:

    bundle install
  3. To establish the database, run:

    rails db:{drop,create,migrate}
  4. To start up the local rails server, run:

    rails server

Visit http://localhost:3000 in a web browser to confirm that the app is running, or use an application such as Postman to make your API calls and confirm the responses are accurate.

(back to top)


API Key Setup

In order to use this application you will API keys from both MapQuest and the WeatherAPI .

Once you have these keys, they will be stored in the application.yml file that you create.

  1. Run bundle exec figaro install, then open the application.yml file. Here you'll add your mapquest_key and weather_api_key.
    mapquest_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
    weather_api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxx

(back to top)


Testing with RSpec

Once sweater_weather is correctly installed, run tests locally to ensure the repository will work as intended.


To test the entire RSpec suite, run:

bundle exec rspec

All tests should be passing if the installation was successful.

If any tests are not passing, please report which tests are not passing Here. We will issue an update/fix as soon as possible!

(back to top)


Available Endpoints

  • This API can be called locally using a program like Postman.

  • Note: Necessary parameters marked with {}


Forecast Endpoint


1. Get forecast for a given location


Note: pass location as a paramater within this endpoint. the location should follow the format: 'City,State(Abbreviated)' ex: 'Denver,CO'

GET '/api/v1/forecast?location=<location>'

Response:

{
    "data": {
        "id": null,
        "type": "forecast",
        "attributes": {
            "current_weather": {
                "last_updated": "LAST_UPDATED",
                "temperature": "TEMPERATURE",
                "feels_like": "FEELS_LIKE",
                "humidity": "HUMIDITY",
                "uvi": "UVI",
                "visibility": "VISIBILITY",
                "conditions": "CONDITIONS",
                "icon": "ICON_IMG_LINK"
            },
            "daily_weather": [
                {
                    "date": "DATE",
                    "sunrise": "SUNRISE",
                    "sunset": "SUNSET",
                    "max_temp": "MAX_TEMP",
                    "min_temp": "MIN_TEMP",
                    "condition": "CONDITIONS",
                    "icon": "ICON_IMG_LINK"
                }
            ],
            "hourly_weather": [
                {
                    "time": "TIME",
                    "temperature": "TEMPERATURE",
                    "conditions": "CONDITIONS",
                    "icon": "ICON_IMG_LINK"
                }
            ]
        }
    }
}

Note: this response will return daily weather for 5 days and hourly weather for the next 24 hours. Only one is provided for each as an example of what the response looks like.


User Endpoint


1. Create a User


POST 'api/vi/users/'

Note: this endpoint will require the paramaters of the user passed into the body of the request as raw JSON. The formatting for this is shown below.

{
  "email": "whatever@example.com",
  "password": "password",
  "password_confirmation": "password"
}

Note: Since we are passing this data in the body of the request as raw JSON, you will need to add the following headers to your request as well.

    Content-Type: applicaton/json
    Accept: application/json

Response:

{
    "data": {
        "id": "ID",
        "type": "users",
        "attributes": {
            "email": "USER_EMAIL",
            "api_key": "GENERATED_API_KEY"
        }
    }
}

Session Endpoint


1. Create a Session


POST 'api/vi/sessions'

Note: this endpoint will require the paramaters of the user passed into the body of the request as raw JSON. This request only requires the email and password of an existing user. The formatting for this is shown below.

{
  "email": "whatever@example.com",
  "password": "password"
}

Note: Since we are passing this data in the body of the request as raw JSON, you will need to add the following headers to your request once again.

Content-Type: applicaton/json
Accept: application/json

Response:

{
    "data": {
        "id": "1",
        "type": "users",
        "attributes": {
            "email": "USER_EMAIL",
            "api_key": "USER_API_KEY"
        }
    }
}

(back to top)

Goals

Sweater weather was created to satisfy the Turing Mod 3 final project.

See the official project requirements here.


Learning Goals

  • Consume multiple external APIs, and create functionallity using the return from one API, to get a specific return from another.
  • Expose an API that creates an API key upon user creation.
  • Expose an API that creates sessions based on the user login information.
  • Demonstrate REST and CRUD fundamentals.

(back to top)


Database Schema


Project By:

Dawson Timmons
GitHub
LinkedIn