Skip to content

diegocharles/weather-test

Repository files navigation

Weather Forecast Application

A Ruby on Rails application that accepts an address as input and retrieves weather forecast data for the given location. Built with Rails best practices - thin controllers, fat models, and minimal dependencies.

Features

  • Accept address input from users
  • Convert addresses to zip codes using geocoding
  • Retrieve current weather data (temperature, humidity, pressure, etc.)
  • Display 5-day extended forecast with high/low temperatures
  • Cache weather data for 30 minutes
  • Display cache indicator when data is retrieved from cache
  • Modern, responsive UI design
  • Error handling for invalid addresses and API failures

Requirements

  • Ruby 3.4.6+
  • Rails 8.0.3+
  • OpenWeatherMap API key (free tier available)

Setup

  1. Clone the repository

    git clone <your-repo-url>
    cd weather_forecast_app
  2. Install dependencies

    bundle install
  3. Set up environment variables

    Create a .env file in the root directory:

    OPENWEATHER_API_KEY=your_api_key_here

    To get a free API key:

    • Go to OpenWeatherMap
    • Sign up for a free account
    • Generate an API key
    • Add it to your .env file
  4. Set up the database

    rails db:create
    rails db:migrate
  5. Start the server

    rails server
  6. Visit the application Open your browser and go to http://localhost:3000

Usage

  1. Enter a zip code in the input field (e.g., "10001", "90210")
    • Also accepts full addresses (e.g., "San Francisco, CA")
  2. Click "Get Weather" to retrieve current weather and 5-day forecast
  3. The application will:
    • Convert the address to a zip code (if needed)
    • Fetch weather data from OpenWeatherMap API
    • Display current temperature, conditions, and extended forecast
    • Cache the results for 30 minutes
    • Show a cache indicator if data is retrieved from cache

Architecture

Built following Rails conventions:

  • Thin Controllers: Controllers only handle HTTP concerns
  • Fat Models: All business logic lives in the Forecast model
  • No Comments: Code is self-documenting (except where complexity requires explanation)
  • Standard Library: Uses Net::HTTP instead of external HTTP gems
app/
├── controllers/
│   └── forecasts_controller.rb    # Thin controller - orchestration only
├── models/
│   └── forecast.rb                # Fat model - all business logic
├── views/
│   └── forecasts/
│       └── index.html.erb         # Main view
└── assets/
    └── stylesheets/
        └── application.css        # Custom CSS

API Integration

  • OpenWeatherMap API for weather data
  • Geocoder gem for address-to-zip-code conversion
  • Net::HTTP for API requests (built-in Ruby library)

Caching

  • Weather data cached for 30 minutes using Rails.cache
  • Cache keys based on zip code
  • Cache status displayed to users
  • Subsequent requests for the same location within 30 minutes use cached data

Technical Details

  • Framework: Ruby on Rails 8.0.3
  • Database: SQLite3 (development)
  • Caching: Solid Cache (Rails 8 default)
  • Styling: Custom CSS with responsive design
  • API: OpenWeatherMap (free tier)

Error Handling

The application handles:

  • Invalid or non-existent addresses
  • API failures or rate limits
  • Network connectivity issues
  • Missing API keys

Bonus Features

  • Extended 5-day forecast with high/low temperatures
  • Modern, responsive UI design
  • Detailed weather information (humidity, pressure, feels-like temperature)
  • Location information display
  • Comprehensive error handling
  • Mobile-responsive design

This project is created for assessment purposes.

weather-test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors