Thanks to visit codestin.com
Credit goes to github.com

Skip to content

eprislac/forecastro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Forecastro!

A simple Ruby on Rails application that provides weather forecasts using the Weather API.

build

Screenshots:

City Zip Cached

  • Ruby version: 3.4.5
  • Rails version: 8.0.3

Tech Used:

  • Ruby on Rails
  • RSpec for testing
  • Turbo for interactivity
  • Cucumber for BDD (though not fully implemented due to Capybara issues)
  • Net::HTTP for API requests
  • Simple caching with Rails.cache
  • Tailwind.css for styling
  • brakeman for security checks
  • rubocop for linting
  • simplecov for test coverage
  • Fasterer for performance improvements
  • Weather API (weatherapi.com) for weather data
  • dotenv-rails for environment variable management
  • Github Actions for CI/CD

Setup Instructions:

  • Need to set the following env vars:

Services

  • Weather API : Used to fetch weather data. the object it uses is too big to paste it its entirety, and we're only using a few fields from it. It takes either a city or zipcode as a param, so we accept either or both, and prefer zipcode when both are used. It returns current weather conditions, as well as a 5-day forecast.
    • In-memory caching is implemented using Rails.cache, with a TTL of 30 minutes, for calls made with zip-codes. This is to reduce the number of API calls and improve performance. Cached data is used if available, otherwise a new API call is made.

Testing:

  • Includes Routing, Request and Service unit tests
  • Testing instructions bundle exec rspec -f doc
  • NOTE: I had plans for cucumber tests, they looked promising, except Capybara's webdriver doesn't really play nice with JS, so does not register changes made by JS, including through turbo... so scrapped them for now. The feature scenarios and step definitions themselves are included for reference.
Feature: User gets weather forecast
  A user visits the site and looks up weather forecast data for their address

  Scenario: User provides valid city
    Given  I visit the weather forecast page
    When I enter 'Denver, CO' into the 'city' field
    And I click the 'Get Forecast' button
    Then I should see the current weather conditions
    And I should see a 5-day weather forecast
    And I should see appropriate weather icons for each day

  Scenario: User provides invalid city name
    Given  I visit the weather forecast page
    When I enter 'InvalidCity' into the 'city' field
    And I click the 'Get Forecast' button
    Then I should not see any weather data

  Scenario: User provides valid zip code
    Given  I visit the weather forecast page
    When I enter '80202' into the 'zip' field
    And I click the 'Get Forecast' button
    Then I should see the current weather conditions
    And I should see a 5-day weather forecast
    And I should see appropriate weather icons for each day

  Scenario: User provides zip code for cached value
    Given  I visit the weather forecast page
    And the value for zip code '80202' is cached
    When I enter '80202' into the 'zip' field
    And I click the 'Get Forecast' button
    Then I should see the current weather conditions
    And I should see a 5-day weather forecast
    And I should see appropriate weather icons for each day
    And I should see an indicator that the data was retrieved from cache

  Scenario: User provides invalid zip code
    Given  I visit the weather forecast page
    When I enter '99999' into the 'zip' field
    And I click the 'Get Forecast' button
    Then I should not see any weather data

Docs:

  • Uses YARD to generate documentation from code comments
  • To generate docs, run: yard doc
  • To view docs, open doc/index.html in a web browser
  • can also be viewed by running yard server and visiting http://localhost:8808 in a web browser

docs1 docs2

About

My submission for an interview coding exercise at Apple

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •